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 30 matching lines...) Expand all Loading... |
41 DCHECK(non_thread_safe_.CalledOnValidThread()); | 41 DCHECK(non_thread_safe_.CalledOnValidThread()); |
42 Stop(); | 42 Stop(); |
43 DCHECK(!listener_); | 43 DCHECK(!listener_); |
44 DCHECK(!state_writer_); | 44 DCHECK(!state_writer_); |
45 } | 45 } |
46 | 46 |
47 void ChromeInvalidationClient::Start( | 47 void ChromeInvalidationClient::Start( |
48 const std::string& client_id, const std::string& client_info, | 48 const std::string& client_id, const std::string& client_info, |
49 const std::string& state, | 49 const std::string& state, |
50 const InvalidationVersionMap& initial_max_invalidation_versions, | 50 const InvalidationVersionMap& initial_max_invalidation_versions, |
51 const browser_sync::WeakHandle<InvalidationVersionTracker>& | 51 const browser_sync::WeakHandle<InvalidationStateTracker>& |
52 invalidation_version_tracker, | 52 invalidation_state_tracker, |
53 Listener* listener, | 53 Listener* listener, |
54 StateWriter* state_writer, | 54 StateWriter* state_writer, |
55 base::WeakPtr<buzz::XmppTaskParentInterface> base_task) { | 55 base::WeakPtr<buzz::XmppTaskParentInterface> base_task) { |
56 DCHECK(non_thread_safe_.CalledOnValidThread()); | 56 DCHECK(non_thread_safe_.CalledOnValidThread()); |
57 Stop(); | 57 Stop(); |
58 | 58 |
59 chrome_system_resources_.set_platform(client_info); | 59 chrome_system_resources_.set_platform(client_info); |
60 chrome_system_resources_.Start(); | 60 chrome_system_resources_.Start(); |
61 | 61 |
62 // The Storage resource is implemented as a write-through cache. We populate | 62 // 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 | 63 // 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. | 64 // update the in-memory cache, while reads just return the cached state. |
65 chrome_system_resources_.storage()->SetInitialState(state); | 65 chrome_system_resources_.storage()->SetInitialState(state); |
66 | 66 |
67 max_invalidation_versions_ = initial_max_invalidation_versions; | 67 max_invalidation_versions_ = initial_max_invalidation_versions; |
68 if (max_invalidation_versions_.empty()) { | 68 if (max_invalidation_versions_.empty()) { |
69 DVLOG(2) << "No initial max invalidation versions for any type"; | 69 DVLOG(2) << "No initial max invalidation versions for any type"; |
70 } else { | 70 } else { |
71 for (InvalidationVersionMap::const_iterator it = | 71 for (InvalidationVersionMap::const_iterator it = |
72 max_invalidation_versions_.begin(); | 72 max_invalidation_versions_.begin(); |
73 it != max_invalidation_versions_.end(); ++it) { | 73 it != max_invalidation_versions_.end(); ++it) { |
74 DVLOG(2) << "Initial max invalidation version for " | 74 DVLOG(2) << "Initial max invalidation version for " |
75 << syncable::ModelTypeToString(it->first) << " is " | 75 << syncable::ModelTypeToString(it->first) << " is " |
76 << it->second; | 76 << it->second; |
77 } | 77 } |
78 } | 78 } |
79 invalidation_version_tracker_ = invalidation_version_tracker; | 79 invalidation_state_tracker_ = invalidation_state_tracker; |
80 DCHECK(invalidation_version_tracker_.IsInitialized()); | 80 DCHECK(invalidation_state_tracker_.IsInitialized()); |
81 | 81 |
82 DCHECK(!listener_); | 82 DCHECK(!listener_); |
83 DCHECK(listener); | 83 DCHECK(listener); |
84 listener_ = listener; | 84 listener_ = listener; |
85 DCHECK(!state_writer_); | 85 DCHECK(!state_writer_); |
86 DCHECK(state_writer); | 86 DCHECK(state_writer); |
87 state_writer_ = state_writer; | 87 state_writer_ = state_writer; |
88 | 88 |
89 int client_type = ipc::invalidation::ClientType::CHROME_SYNC; | 89 int client_type = ipc::invalidation::ClientType::CHROME_SYNC; |
90 invalidation_client_.reset( | 90 invalidation_client_.reset( |
(...skipping 26 matching lines...) Expand all Loading... |
117 | 117 |
118 registration_manager_.reset(); | 118 registration_manager_.reset(); |
119 cache_invalidation_packet_handler_.reset(); | 119 cache_invalidation_packet_handler_.reset(); |
120 chrome_system_resources_.Stop(); | 120 chrome_system_resources_.Stop(); |
121 invalidation_client_->Stop(); | 121 invalidation_client_->Stop(); |
122 | 122 |
123 invalidation_client_.reset(); | 123 invalidation_client_.reset(); |
124 state_writer_ = NULL; | 124 state_writer_ = NULL; |
125 listener_ = NULL; | 125 listener_ = NULL; |
126 | 126 |
127 invalidation_version_tracker_.Reset(); | 127 invalidation_state_tracker_.Reset(); |
128 max_invalidation_versions_.clear(); | 128 max_invalidation_versions_.clear(); |
129 } | 129 } |
130 | 130 |
131 void ChromeInvalidationClient::RegisterTypes(syncable::ModelTypeSet types) { | 131 void ChromeInvalidationClient::RegisterTypes(syncable::ModelTypeSet types) { |
132 DCHECK(non_thread_safe_.CalledOnValidThread()); | 132 DCHECK(non_thread_safe_.CalledOnValidThread()); |
133 registered_types_ = types; | 133 registered_types_ = types; |
134 if (ticl_ready_ && registration_manager_.get()) { | 134 if (ticl_ready_ && registration_manager_.get()) { |
135 registration_manager_->SetRegisteredTypes(registered_types_); | 135 registration_manager_->SetRegisteredTypes(registered_types_); |
136 } | 136 } |
137 // TODO(akalin): Clear invalidation versions for unregistered types. | 137 // TODO(akalin): Clear invalidation versions for unregistered types. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 if ((it != max_invalidation_versions_.end()) && | 171 if ((it != max_invalidation_versions_.end()) && |
172 (invalidation.version() <= it->second)) { | 172 (invalidation.version() <= it->second)) { |
173 // Drop redundant invalidations. | 173 // Drop redundant invalidations. |
174 client->Acknowledge(ack_handle); | 174 client->Acknowledge(ack_handle); |
175 return; | 175 return; |
176 } | 176 } |
177 DVLOG(2) << "Setting max invalidation version for " | 177 DVLOG(2) << "Setting max invalidation version for " |
178 << syncable::ModelTypeToString(model_type) << " to " | 178 << syncable::ModelTypeToString(model_type) << " to " |
179 << invalidation.version(); | 179 << invalidation.version(); |
180 max_invalidation_versions_[model_type] = invalidation.version(); | 180 max_invalidation_versions_[model_type] = invalidation.version(); |
181 invalidation_version_tracker_.Call( | 181 invalidation_state_tracker_.Call( |
182 FROM_HERE, | 182 FROM_HERE, |
183 &InvalidationVersionTracker::SetMaxVersion, | 183 &InvalidationStateTracker::SetMaxVersion, |
184 model_type, invalidation.version()); | 184 model_type, invalidation.version()); |
185 | 185 |
186 std::string payload; | 186 std::string payload; |
187 // payload() CHECK()'s has_payload(), so we must check it ourselves first. | 187 // payload() CHECK()'s has_payload(), so we must check it ourselves first. |
188 if (invalidation.has_payload()) | 188 if (invalidation.has_payload()) |
189 payload = invalidation.payload(); | 189 payload = invalidation.payload(); |
190 | 190 |
191 EmitInvalidation(syncable::ModelTypeSet(model_type), payload); | 191 EmitInvalidation(syncable::ModelTypeSet(model_type), payload); |
192 // TODO(akalin): We should really acknowledge only after we get the | 192 // TODO(akalin): We should really acknowledge only after we get the |
193 // updates from the sync server. (see http://crbug.com/78462). | 193 // updates from the sync server. (see http://crbug.com/78462). |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 // TODO(ghc): handle the error. | 304 // TODO(ghc): handle the error. |
305 } | 305 } |
306 | 306 |
307 void ChromeInvalidationClient::WriteState(const std::string& state) { | 307 void ChromeInvalidationClient::WriteState(const std::string& state) { |
308 DCHECK(non_thread_safe_.CalledOnValidThread()); | 308 DCHECK(non_thread_safe_.CalledOnValidThread()); |
309 CHECK(state_writer_); | 309 CHECK(state_writer_); |
310 state_writer_->WriteState(state); | 310 state_writer_->WriteState(state); |
311 } | 311 } |
312 | 312 |
313 } // namespace sync_notifier | 313 } // namespace sync_notifier |
OLD | NEW |