| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/sync/notifier/server_notifier_thread.h" | 5 #include "chrome/browser/sync/notifier/server_notifier_thread.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "chrome/browser/sync/notifier/chrome_invalidation_client.h" | 11 #include "chrome/browser/sync/notifier/chrome_invalidation_client.h" |
| 12 #include "googleurl/src/gurl.h" |
| 12 #include "jingle/notifier/base/notifier_options.h" | 13 #include "jingle/notifier/base/notifier_options.h" |
| 13 #include "jingle/notifier/listener/notification_defines.h" | 14 #include "jingle/notifier/listener/notification_defines.h" |
| 14 #include "talk/xmpp/xmppclient.h" | 15 #include "talk/xmpp/xmppclient.h" |
| 16 #include "webkit/glue/webkit_glue.h" |
| 15 | 17 |
| 16 namespace sync_notifier { | 18 namespace sync_notifier { |
| 17 | 19 |
| 18 ServerNotifierThread::ServerNotifierThread( | 20 ServerNotifierThread::ServerNotifierThread( |
| 19 const notifier::NotifierOptions& notifier_options, | 21 const notifier::NotifierOptions& notifier_options, |
| 20 const std::string& state, StateWriter* state_writer) | 22 const std::string& state, StateWriter* state_writer) |
| 21 : notifier::MediatorThreadImpl(notifier_options), | 23 : notifier::MediatorThreadImpl(notifier_options), |
| 22 state_(state), | 24 state_(state), |
| 23 state_writers_(new ObserverListThreadSafe<StateWriter>()), | 25 state_writers_(new ObserverListThreadSafe<StateWriter>()), |
| 24 state_writer_(state_writer) { | 26 state_writer_(state_writer) { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 chrome_invalidation_client_->ChangeBaseTask(base_task_); | 108 chrome_invalidation_client_->ChangeBaseTask(base_task_); |
| 107 } else { | 109 } else { |
| 108 // Otherwise, create the invalidation client. | 110 // Otherwise, create the invalidation client. |
| 109 chrome_invalidation_client_.reset(new ChromeInvalidationClient()); | 111 chrome_invalidation_client_.reset(new ChromeInvalidationClient()); |
| 110 | 112 |
| 111 // TODO(akalin): Make cache_guid() part of the client ID. If we do | 113 // TODO(akalin): Make cache_guid() part of the client ID. If we do |
| 112 // so and we somehow propagate it up to the server somehow, we can | 114 // so and we somehow propagate it up to the server somehow, we can |
| 113 // make it so that we won't receive any notifications that were | 115 // make it so that we won't receive any notifications that were |
| 114 // generated from our own changes. | 116 // generated from our own changes. |
| 115 const std::string kClientId = "server_notifier_thread"; | 117 const std::string kClientId = "server_notifier_thread"; |
| 118 // Use user agent as |client_info| so we can use it for debugging |
| 119 // server-side. |
| 120 const std::string& client_info = webkit_glue::GetUserAgent(GURL()); |
| 116 chrome_invalidation_client_->Start( | 121 chrome_invalidation_client_->Start( |
| 117 kClientId, state_, this, this, base_task_); | 122 kClientId, client_info, state_, this, this, base_task_); |
| 118 state_.clear(); | 123 state_.clear(); |
| 119 } | 124 } |
| 120 } | 125 } |
| 121 | 126 |
| 122 void ServerNotifierThread::RegisterTypesAndSignalSubscribed() { | 127 void ServerNotifierThread::RegisterTypesAndSignalSubscribed() { |
| 123 DCHECK_EQ(MessageLoop::current(), worker_message_loop()); | 128 DCHECK_EQ(MessageLoop::current(), worker_message_loop()); |
| 124 if (!chrome_invalidation_client_.get()) { | 129 if (!chrome_invalidation_client_.get()) { |
| 125 return; | 130 return; |
| 126 } | 131 } |
| 127 chrome_invalidation_client_->RegisterTypes(); | 132 chrome_invalidation_client_->RegisterTypes(); |
| 128 observers_->Notify(&Observer::OnSubscriptionStateChange, true); | 133 observers_->Notify(&Observer::OnSubscriptionStateChange, true); |
| 129 } | 134 } |
| 130 | 135 |
| 131 void ServerNotifierThread::StopInvalidationListener() { | 136 void ServerNotifierThread::StopInvalidationListener() { |
| 132 DCHECK_EQ(MessageLoop::current(), worker_message_loop()); | 137 DCHECK_EQ(MessageLoop::current(), worker_message_loop()); |
| 133 chrome_invalidation_client_.reset(); | 138 chrome_invalidation_client_.reset(); |
| 134 } | 139 } |
| 135 | 140 |
| 136 } // namespace sync_notifier | 141 } // namespace sync_notifier |
| OLD | NEW |