| 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" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 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 scoped_ptr<notifier::PushClient> push_client) | 33 scoped_ptr<notifier::PushClient> push_client) |
| 34 : chrome_system_resources_(push_client.Pass(), | 34 : chrome_system_resources_(push_client.Pass(), |
| 35 ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 35 ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 36 listener_(NULL), | 36 listener_(NULL), |
| 37 state_writer_(NULL), | |
| 38 ticl_ready_(false) { | 37 ticl_ready_(false) { |
| 39 DCHECK(non_thread_safe_.CalledOnValidThread()); | 38 DCHECK(non_thread_safe_.CalledOnValidThread()); |
| 40 } | 39 } |
| 41 | 40 |
| 42 ChromeInvalidationClient::~ChromeInvalidationClient() { | 41 ChromeInvalidationClient::~ChromeInvalidationClient() { |
| 43 DCHECK(non_thread_safe_.CalledOnValidThread()); | 42 DCHECK(non_thread_safe_.CalledOnValidThread()); |
| 44 Stop(); | 43 Stop(); |
| 45 DCHECK(!listener_); | 44 DCHECK(!listener_); |
| 46 DCHECK(!state_writer_); | |
| 47 } | 45 } |
| 48 | 46 |
| 49 void ChromeInvalidationClient::Start( | 47 void ChromeInvalidationClient::Start( |
| 50 const std::string& client_id, const std::string& client_info, | 48 const std::string& client_id, const std::string& client_info, |
| 51 const std::string& state, | 49 const std::string& state, |
| 52 const InvalidationVersionMap& initial_max_invalidation_versions, | 50 const InvalidationVersionMap& initial_max_invalidation_versions, |
| 53 const browser_sync::WeakHandle<InvalidationStateTracker>& | 51 const browser_sync::WeakHandle<InvalidationStateTracker>& |
| 54 invalidation_state_tracker, | 52 invalidation_state_tracker, |
| 55 Listener* listener, | 53 Listener* listener) { |
| 56 StateWriter* state_writer) { | |
| 57 DCHECK(non_thread_safe_.CalledOnValidThread()); | 54 DCHECK(non_thread_safe_.CalledOnValidThread()); |
| 58 Stop(); | 55 Stop(); |
| 59 | 56 |
| 60 chrome_system_resources_.set_platform(client_info); | 57 chrome_system_resources_.set_platform(client_info); |
| 61 chrome_system_resources_.Start(); | 58 chrome_system_resources_.Start(); |
| 62 | 59 |
| 63 // The Storage resource is implemented as a write-through cache. We populate | 60 // The Storage resource is implemented as a write-through cache. We populate |
| 64 // it with the initial state on startup, so subsequent writes go to disk and | 61 // it with the initial state on startup, so subsequent writes go to disk and |
| 65 // update the in-memory cache, while reads just return the cached state. | 62 // update the in-memory cache, while reads just return the cached state. |
| 66 chrome_system_resources_.storage()->SetInitialState(state); | 63 chrome_system_resources_.storage()->SetInitialState(state); |
| 67 | 64 |
| 68 max_invalidation_versions_ = initial_max_invalidation_versions; | 65 max_invalidation_versions_ = initial_max_invalidation_versions; |
| 69 if (max_invalidation_versions_.empty()) { | 66 if (max_invalidation_versions_.empty()) { |
| 70 DVLOG(2) << "No initial max invalidation versions for any type"; | 67 DVLOG(2) << "No initial max invalidation versions for any type"; |
| 71 } else { | 68 } else { |
| 72 for (InvalidationVersionMap::const_iterator it = | 69 for (InvalidationVersionMap::const_iterator it = |
| 73 max_invalidation_versions_.begin(); | 70 max_invalidation_versions_.begin(); |
| 74 it != max_invalidation_versions_.end(); ++it) { | 71 it != max_invalidation_versions_.end(); ++it) { |
| 75 DVLOG(2) << "Initial max invalidation version for " | 72 DVLOG(2) << "Initial max invalidation version for " |
| 76 << syncable::ModelTypeToString(it->first) << " is " | 73 << syncable::ModelTypeToString(it->first) << " is " |
| 77 << it->second; | 74 << it->second; |
| 78 } | 75 } |
| 79 } | 76 } |
| 80 invalidation_state_tracker_ = invalidation_state_tracker; | 77 invalidation_state_tracker_ = invalidation_state_tracker; |
| 81 DCHECK(invalidation_state_tracker_.IsInitialized()); | 78 DCHECK(invalidation_state_tracker_.IsInitialized()); |
| 82 | 79 |
| 83 DCHECK(!listener_); | 80 DCHECK(!listener_); |
| 84 DCHECK(listener); | 81 DCHECK(listener); |
| 85 listener_ = listener; | 82 listener_ = listener; |
| 86 DCHECK(!state_writer_); | |
| 87 DCHECK(state_writer); | |
| 88 state_writer_ = state_writer; | |
| 89 | 83 |
| 90 int client_type = ipc::invalidation::ClientType::CHROME_SYNC; | 84 int client_type = ipc::invalidation::ClientType::CHROME_SYNC; |
| 91 invalidation_client_.reset( | 85 invalidation_client_.reset( |
| 92 invalidation::CreateInvalidationClient( | 86 invalidation::CreateInvalidationClient( |
| 93 &chrome_system_resources_, client_type, client_id, | 87 &chrome_system_resources_, client_type, client_id, |
| 94 kApplicationName, this)); | 88 kApplicationName, this)); |
| 95 invalidation_client_->Start(); | 89 invalidation_client_->Start(); |
| 96 | 90 |
| 97 registration_manager_.reset( | 91 registration_manager_.reset( |
| 98 new RegistrationManager(invalidation_client_.get())); | 92 new RegistrationManager(invalidation_client_.get())); |
| 99 } | 93 } |
| 100 | 94 |
| 101 void ChromeInvalidationClient::UpdateCredentials( | 95 void ChromeInvalidationClient::UpdateCredentials( |
| 102 const std::string& email, const std::string& token) { | 96 const std::string& email, const std::string& token) { |
| 103 DCHECK(non_thread_safe_.CalledOnValidThread()); | 97 DCHECK(non_thread_safe_.CalledOnValidThread()); |
| 104 chrome_system_resources_.network()->UpdateCredentials(email, token); | 98 chrome_system_resources_.network()->UpdateCredentials(email, token); |
| 105 } | 99 } |
| 106 | 100 |
| 107 void ChromeInvalidationClient::Stop() { | 101 void ChromeInvalidationClient::Stop() { |
| 108 DCHECK(non_thread_safe_.CalledOnValidThread()); | 102 DCHECK(non_thread_safe_.CalledOnValidThread()); |
| 109 if (!invalidation_client_.get()) { | 103 if (!invalidation_client_.get()) { |
| 110 return; | 104 return; |
| 111 } | 105 } |
| 112 | 106 |
| 113 registration_manager_.reset(); | 107 registration_manager_.reset(); |
| 114 chrome_system_resources_.Stop(); | 108 chrome_system_resources_.Stop(); |
| 115 invalidation_client_->Stop(); | 109 invalidation_client_->Stop(); |
| 116 | 110 |
| 117 invalidation_client_.reset(); | 111 invalidation_client_.reset(); |
| 118 state_writer_ = NULL; | |
| 119 listener_ = NULL; | 112 listener_ = NULL; |
| 120 | 113 |
| 121 invalidation_state_tracker_.Reset(); | 114 invalidation_state_tracker_.Reset(); |
| 122 max_invalidation_versions_.clear(); | 115 max_invalidation_versions_.clear(); |
| 123 } | 116 } |
| 124 | 117 |
| 125 void ChromeInvalidationClient::RegisterTypes(syncable::ModelTypeSet types) { | 118 void ChromeInvalidationClient::RegisterTypes(syncable::ModelTypeSet types) { |
| 126 DCHECK(non_thread_safe_.CalledOnValidThread()); | 119 DCHECK(non_thread_safe_.CalledOnValidThread()); |
| 127 registered_types_ = types; | 120 registered_types_ = types; |
| 128 if (ticl_ready_ && registration_manager_.get()) { | 121 if (ticl_ready_ && registration_manager_.get()) { |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 void ChromeInvalidationClient::InformError( | 286 void ChromeInvalidationClient::InformError( |
| 294 invalidation::InvalidationClient* client, | 287 invalidation::InvalidationClient* client, |
| 295 const invalidation::ErrorInfo& error_info) { | 288 const invalidation::ErrorInfo& error_info) { |
| 296 listener_->OnSessionStatusChanged(false); | 289 listener_->OnSessionStatusChanged(false); |
| 297 LOG(ERROR) << "Invalidation client encountered an error"; | 290 LOG(ERROR) << "Invalidation client encountered an error"; |
| 298 // TODO(ghc): handle the error. | 291 // TODO(ghc): handle the error. |
| 299 } | 292 } |
| 300 | 293 |
| 301 void ChromeInvalidationClient::WriteState(const std::string& state) { | 294 void ChromeInvalidationClient::WriteState(const std::string& state) { |
| 302 DCHECK(non_thread_safe_.CalledOnValidThread()); | 295 DCHECK(non_thread_safe_.CalledOnValidThread()); |
| 303 CHECK(state_writer_); | 296 DVLOG(1) << "WriteState"; |
| 304 state_writer_->WriteState(state); | 297 invalidation_state_tracker_.Call( |
| 298 FROM_HERE, &InvalidationStateTracker::SetInvalidationState, state); |
| 305 } | 299 } |
| 306 | 300 |
| 307 } // namespace sync_notifier | 301 } // namespace sync_notifier |
| OLD | NEW |