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 "chrome/browser/sync/invalidations/invalidator_storage.h" | 5 #include "chrome/browser/sync/invalidations/invalidator_storage.h" |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
97 : pref_service_(pref_service) { | 97 : pref_service_(pref_service) { |
98 // TODO(tim): Create a Mock instead of maintaining the if(!pref_service_) case | 98 // TODO(tim): Create a Mock instead of maintaining the if(!pref_service_) case |
99 // throughout this file. This is a problem now due to lack of injection at | 99 // throughout this file. This is a problem now due to lack of injection at |
100 // ProfileSyncService. Bug 130176. | 100 // ProfileSyncService. Bug 130176. |
101 if (pref_service_) { | 101 if (pref_service_) { |
102 pref_service_->RegisterListPref(prefs::kInvalidatorMaxInvalidationVersions, | 102 pref_service_->RegisterListPref(prefs::kInvalidatorMaxInvalidationVersions, |
103 PrefServiceSyncable::UNSYNCABLE_PREF); | 103 PrefServiceSyncable::UNSYNCABLE_PREF); |
104 pref_service_->RegisterStringPref(prefs::kInvalidatorInvalidationState, | 104 pref_service_->RegisterStringPref(prefs::kInvalidatorInvalidationState, |
105 std::string(), | 105 std::string(), |
106 PrefServiceSyncable::UNSYNCABLE_PREF); | 106 PrefServiceSyncable::UNSYNCABLE_PREF); |
107 pref_service_->RegisterStringPref(prefs::kInvalidatorClientId, | |
108 std::string(), | |
109 PrefServiceSyncable::UNSYNCABLE_PREF); | |
107 | 110 |
108 MigrateMaxInvalidationVersionsPref(); | 111 MigrateMaxInvalidationVersionsPref(); |
109 } | 112 } |
110 } | 113 } |
111 | 114 |
112 InvalidatorStorage::~InvalidatorStorage() { | 115 InvalidatorStorage::~InvalidatorStorage() { |
113 } | 116 } |
114 | 117 |
115 InvalidationStateMap InvalidatorStorage::GetAllInvalidationStates() const { | 118 InvalidationStateMap InvalidatorStorage::GetAllInvalidationStates() const { |
116 DCHECK(thread_checker_.CalledOnValidThread()); | 119 DCHECK(thread_checker_.CalledOnValidThread()); |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
249 } | 252 } |
250 invalidation::ObjectId id; | 253 invalidation::ObjectId id; |
251 if (!syncer::RealModelTypeToObjectId(model_type, &id)) { | 254 if (!syncer::RealModelTypeToObjectId(model_type, &id)) { |
252 DLOG(WARNING) << "Invalid model type: " << model_type; | 255 DLOG(WARNING) << "Invalid model type: " << model_type; |
253 continue; | 256 continue; |
254 } | 257 } |
255 (*map)[id].version = max_version; | 258 (*map)[id].version = max_version; |
256 } | 259 } |
257 } | 260 } |
258 | 261 |
262 void InvalidatorStorage::SetInvalidatorClientId(const std::string& client_id) { | |
263 DCHECK(thread_checker_.CalledOnValidThread()); | |
264 pref_service_->SetString(prefs::kInvalidatorClientId, client_id); | |
265 } | |
266 | |
267 std::string InvalidatorStorage::GetInvalidatorClientId() const { | |
268 return pref_service_ ? | |
269 pref_service_->GetString(prefs::kInvalidatorClientId) : | |
270 std::string(); | |
tim (not reviewing)
2013/02/05 22:05:28
nit - indent 4 spaces from pref_service_.
rlarocque
2013/02/05 22:16:45
Done.
| |
271 } | |
272 | |
259 void InvalidatorStorage::SetBootstrapData(const std::string& data) { | 273 void InvalidatorStorage::SetBootstrapData(const std::string& data) { |
260 DCHECK(thread_checker_.CalledOnValidThread()); | 274 DCHECK(thread_checker_.CalledOnValidThread()); |
261 std::string base64_data; | 275 std::string base64_data; |
262 base::Base64Encode(data, &base64_data); | 276 base::Base64Encode(data, &base64_data); |
263 pref_service_->SetString(prefs::kInvalidatorInvalidationState, | 277 pref_service_->SetString(prefs::kInvalidatorInvalidationState, |
264 base64_data); | 278 base64_data); |
265 } | 279 } |
266 | 280 |
267 std::string InvalidatorStorage::GetBootstrapData() const { | 281 std::string InvalidatorStorage::GetBootstrapData() const { |
268 std::string base64_data(pref_service_ ? | 282 std::string base64_data(pref_service_ ? |
269 pref_service_->GetString(prefs::kInvalidatorInvalidationState) : ""); | 283 pref_service_->GetString(prefs::kInvalidatorInvalidationState) : ""); |
270 std::string data; | 284 std::string data; |
271 base::Base64Decode(base64_data, &data); | 285 base::Base64Decode(base64_data, &data); |
272 return data; | 286 return data; |
273 } | 287 } |
274 | 288 |
275 void InvalidatorStorage::Clear() { | 289 void InvalidatorStorage::Clear() { |
276 DCHECK(thread_checker_.CalledOnValidThread()); | 290 DCHECK(thread_checker_.CalledOnValidThread()); |
277 pref_service_->ClearPref(prefs::kInvalidatorMaxInvalidationVersions); | 291 pref_service_->ClearPref(prefs::kInvalidatorMaxInvalidationVersions); |
292 pref_service_->ClearPref(prefs::kInvalidatorClientId); | |
278 pref_service_->ClearPref(prefs::kInvalidatorInvalidationState); | 293 pref_service_->ClearPref(prefs::kInvalidatorInvalidationState); |
279 } | 294 } |
280 | 295 |
281 void InvalidatorStorage::GenerateAckHandles( | 296 void InvalidatorStorage::GenerateAckHandles( |
282 const syncer::ObjectIdSet& ids, | 297 const syncer::ObjectIdSet& ids, |
283 const scoped_refptr<base::TaskRunner>& task_runner, | 298 const scoped_refptr<base::TaskRunner>& task_runner, |
284 const base::Callback<void(const syncer::AckHandleMap&)> callback) { | 299 const base::Callback<void(const syncer::AckHandleMap&)> callback) { |
285 DCHECK(thread_checker_.CalledOnValidThread()); | 300 DCHECK(thread_checker_.CalledOnValidThread()); |
286 CHECK(pref_service_); | 301 CHECK(pref_service_); |
287 InvalidationStateMap state_map = GetAllInvalidationStates(); | 302 InvalidationStateMap state_map = GetAllInvalidationStates(); |
(...skipping 27 matching lines...) Expand all Loading... | |
315 return; | 330 return; |
316 it->second.current = ack_handle; | 331 it->second.current = ack_handle; |
317 | 332 |
318 base::ListValue state_map_list; | 333 base::ListValue state_map_list; |
319 SerializeToList(state_map, &state_map_list); | 334 SerializeToList(state_map, &state_map_list); |
320 pref_service_->Set(prefs::kInvalidatorMaxInvalidationVersions, | 335 pref_service_->Set(prefs::kInvalidatorMaxInvalidationVersions, |
321 state_map_list); | 336 state_map_list); |
322 } | 337 } |
323 | 338 |
324 } // namespace browser_sync | 339 } // namespace browser_sync |
OLD | NEW |