| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "sync/notifier/chrome_invalidation_client.h" | 5 #include "sync/notifier/chrome_invalidation_client.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/tracked_objects.h" | 12 #include "base/tracked_objects.h" |
| 13 #include "google/cacheinvalidation/include/invalidation-client-factory.h" | 13 #include "google/cacheinvalidation/include/invalidation-client-factory.h" |
| 14 #include "google/cacheinvalidation/include/invalidation-client.h" | 14 #include "google/cacheinvalidation/include/invalidation-client.h" |
| 15 #include "google/cacheinvalidation/include/types.h" | 15 #include "google/cacheinvalidation/include/types.h" |
| 16 #include "google/cacheinvalidation/v2/types.pb.h" | 16 #include "google/cacheinvalidation/v2/types.pb.h" |
| 17 #include "sync/notifier/cache_invalidation_packet_handler.h" | 17 #include "jingle/notifier/listener/push_client.h" |
| 18 #include "sync/notifier/invalidation_util.h" | 18 #include "sync/notifier/invalidation_util.h" |
| 19 #include "sync/notifier/registration_manager.h" | 19 #include "sync/notifier/registration_manager.h" |
| 20 #include "sync/syncable/model_type.h" | 20 #include "sync/syncable/model_type.h" |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 const char kApplicationName[] = "chrome-sync"; | 24 const char kApplicationName[] = "chrome-sync"; |
| 25 | 25 |
| 26 } // anonymous namespace | 26 } // namespace |
| 27 | 27 |
| 28 namespace sync_notifier { | 28 namespace sync_notifier { |
| 29 | 29 |
| 30 ChromeInvalidationClient::Listener::~Listener() {} | 30 ChromeInvalidationClient::Listener::~Listener() {} |
| 31 | 31 |
| 32 ChromeInvalidationClient::ChromeInvalidationClient() | 32 ChromeInvalidationClient::ChromeInvalidationClient( |
| 33 : chrome_system_resources_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 33 scoped_ptr<notifier::PushClient> push_client) |
| 34 : chrome_system_resources_(push_client.Pass(), |
| 35 ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 34 listener_(NULL), | 36 listener_(NULL), |
| 35 state_writer_(NULL), | 37 state_writer_(NULL), |
| 36 ticl_ready_(false) { | 38 ticl_ready_(false) { |
| 37 DCHECK(non_thread_safe_.CalledOnValidThread()); | 39 DCHECK(non_thread_safe_.CalledOnValidThread()); |
| 38 } | 40 } |
| 39 | 41 |
| 40 ChromeInvalidationClient::~ChromeInvalidationClient() { | 42 ChromeInvalidationClient::~ChromeInvalidationClient() { |
| 41 DCHECK(non_thread_safe_.CalledOnValidThread()); | 43 DCHECK(non_thread_safe_.CalledOnValidThread()); |
| 42 Stop(); | 44 Stop(); |
| 43 DCHECK(!listener_); | 45 DCHECK(!listener_); |
| 44 DCHECK(!state_writer_); | 46 DCHECK(!state_writer_); |
| 45 } | 47 } |
| 46 | 48 |
| 47 void ChromeInvalidationClient::Start( | 49 void ChromeInvalidationClient::Start( |
| 48 const std::string& client_id, const std::string& client_info, | 50 const std::string& client_id, const std::string& client_info, |
| 49 const std::string& state, | 51 const std::string& state, |
| 50 const InvalidationVersionMap& initial_max_invalidation_versions, | 52 const InvalidationVersionMap& initial_max_invalidation_versions, |
| 51 const browser_sync::WeakHandle<InvalidationStateTracker>& | 53 const browser_sync::WeakHandle<InvalidationStateTracker>& |
| 52 invalidation_state_tracker, | 54 invalidation_state_tracker, |
| 53 Listener* listener, | 55 Listener* listener, |
| 54 StateWriter* state_writer, | 56 StateWriter* state_writer) { |
| 55 base::WeakPtr<buzz::XmppTaskParentInterface> base_task) { | |
| 56 DCHECK(non_thread_safe_.CalledOnValidThread()); | 57 DCHECK(non_thread_safe_.CalledOnValidThread()); |
| 57 Stop(); | 58 Stop(); |
| 58 | 59 |
| 59 chrome_system_resources_.set_platform(client_info); | 60 chrome_system_resources_.set_platform(client_info); |
| 60 chrome_system_resources_.Start(); | 61 chrome_system_resources_.Start(); |
| 61 | 62 |
| 62 // The Storage resource is implemented as a write-through cache. We populate | 63 // The Storage resource is implemented as a write-through cache. We populate |
| 63 // it with the initial state on startup, so subsequent writes go to disk and | 64 // it with the initial state on startup, so subsequent writes go to disk and |
| 64 // update the in-memory cache, while reads just return the cached state. | 65 // update the in-memory cache, while reads just return the cached state. |
| 65 chrome_system_resources_.storage()->SetInitialState(state); | 66 chrome_system_resources_.storage()->SetInitialState(state); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 84 listener_ = listener; | 85 listener_ = listener; |
| 85 DCHECK(!state_writer_); | 86 DCHECK(!state_writer_); |
| 86 DCHECK(state_writer); | 87 DCHECK(state_writer); |
| 87 state_writer_ = state_writer; | 88 state_writer_ = state_writer; |
| 88 | 89 |
| 89 int client_type = ipc::invalidation::ClientType::CHROME_SYNC; | 90 int client_type = ipc::invalidation::ClientType::CHROME_SYNC; |
| 90 invalidation_client_.reset( | 91 invalidation_client_.reset( |
| 91 invalidation::CreateInvalidationClient( | 92 invalidation::CreateInvalidationClient( |
| 92 &chrome_system_resources_, client_type, client_id, | 93 &chrome_system_resources_, client_type, client_id, |
| 93 kApplicationName, this)); | 94 kApplicationName, this)); |
| 94 ChangeBaseTask(base_task); | |
| 95 invalidation_client_->Start(); | 95 invalidation_client_->Start(); |
| 96 | 96 |
| 97 registration_manager_.reset( | 97 registration_manager_.reset( |
| 98 new RegistrationManager(invalidation_client_.get())); | 98 new RegistrationManager(invalidation_client_.get())); |
| 99 } | 99 } |
| 100 | 100 |
| 101 void ChromeInvalidationClient::ChangeBaseTask( | 101 void ChromeInvalidationClient::UpdateCredentials( |
| 102 base::WeakPtr<buzz::XmppTaskParentInterface> base_task) { | 102 const std::string& email, const std::string& token) { |
| 103 DCHECK(invalidation_client_.get()); | 103 DCHECK(non_thread_safe_.CalledOnValidThread()); |
| 104 DCHECK(base_task.get()); | 104 chrome_system_resources_.network()->UpdateCredentials(email, token); |
| 105 cache_invalidation_packet_handler_.reset( | |
| 106 new CacheInvalidationPacketHandler(base_task)); | |
| 107 chrome_system_resources_.network()->UpdatePacketHandler( | |
| 108 cache_invalidation_packet_handler_.get()); | |
| 109 } | 105 } |
| 110 | 106 |
| 111 void ChromeInvalidationClient::Stop() { | 107 void ChromeInvalidationClient::Stop() { |
| 112 DCHECK(non_thread_safe_.CalledOnValidThread()); | 108 DCHECK(non_thread_safe_.CalledOnValidThread()); |
| 113 if (!invalidation_client_.get()) { | 109 if (!invalidation_client_.get()) { |
| 114 DCHECK(!cache_invalidation_packet_handler_.get()); | |
| 115 return; | 110 return; |
| 116 } | 111 } |
| 117 | 112 |
| 118 registration_manager_.reset(); | 113 registration_manager_.reset(); |
| 119 cache_invalidation_packet_handler_.reset(); | |
| 120 chrome_system_resources_.Stop(); | 114 chrome_system_resources_.Stop(); |
| 121 invalidation_client_->Stop(); | 115 invalidation_client_->Stop(); |
| 122 | 116 |
| 123 invalidation_client_.reset(); | 117 invalidation_client_.reset(); |
| 124 state_writer_ = NULL; | 118 state_writer_ = NULL; |
| 125 listener_ = NULL; | 119 listener_ = NULL; |
| 126 | 120 |
| 127 invalidation_state_tracker_.Reset(); | 121 invalidation_state_tracker_.Reset(); |
| 128 max_invalidation_versions_.clear(); | 122 max_invalidation_versions_.clear(); |
| 129 } | 123 } |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 // TODO(ghc): handle the error. | 298 // TODO(ghc): handle the error. |
| 305 } | 299 } |
| 306 | 300 |
| 307 void ChromeInvalidationClient::WriteState(const std::string& state) { | 301 void ChromeInvalidationClient::WriteState(const std::string& state) { |
| 308 DCHECK(non_thread_safe_.CalledOnValidThread()); | 302 DCHECK(non_thread_safe_.CalledOnValidThread()); |
| 309 CHECK(state_writer_); | 303 CHECK(state_writer_); |
| 310 state_writer_->WriteState(state); | 304 state_writer_->WriteState(state); |
| 311 } | 305 } |
| 312 | 306 |
| 313 } // namespace sync_notifier | 307 } // namespace sync_notifier |
| OLD | NEW |