| 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 value->SetString(kPayloadKey, state.payload); | 87 value->SetString(kPayloadKey, state.payload); |
| 88 if (state.current.IsValid()) | 88 if (state.current.IsValid()) |
| 89 value->Set(kCurrentAckHandleKey, state.current.ToValue().release()); | 89 value->Set(kCurrentAckHandleKey, state.current.ToValue().release()); |
| 90 if (state.expected.IsValid()) | 90 if (state.expected.IsValid()) |
| 91 value->Set(kExpectedAckHandleKey, state.expected.ToValue().release()); | 91 value->Set(kExpectedAckHandleKey, state.expected.ToValue().release()); |
| 92 return value; | 92 return value; |
| 93 } | 93 } |
| 94 | 94 |
| 95 } // namespace | 95 } // namespace |
| 96 | 96 |
| 97 InvalidatorStorage::InvalidatorStorage(PrefService* pref_service, | 97 // static |
| 98 PrefRegistrySyncable* registry) | 98 void InvalidatorStorage::RegisterUserPrefs(PrefRegistrySyncable* registry) { |
| 99 registry->RegisterListPref(prefs::kInvalidatorMaxInvalidationVersions, |
| 100 PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 101 registry->RegisterStringPref(prefs::kInvalidatorInvalidationState, |
| 102 std::string(), |
| 103 PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 104 registry->RegisterStringPref(prefs::kInvalidatorClientId, |
| 105 std::string(), |
| 106 PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 107 registry->RegisterDictionaryPref(prefs::kSyncMaxInvalidationVersions, |
| 108 PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 109 } |
| 110 |
| 111 InvalidatorStorage::InvalidatorStorage(PrefService* pref_service) |
| 99 : pref_service_(pref_service) { | 112 : pref_service_(pref_service) { |
| 100 // TODO(tim): Create a Mock instead of maintaining the if(!pref_service_) case | 113 // TODO(tim): Create a Mock instead of maintaining the if(!pref_service_) case |
| 101 // throughout this file. This is a problem now due to lack of injection at | 114 // throughout this file. This is a problem now due to lack of injection at |
| 102 // ProfileSyncService. Bug 130176. | 115 // ProfileSyncService. Bug 130176. |
| 103 if (registry) { | 116 MigrateMaxInvalidationVersionsPref(); |
| 104 // TODO(joi): Move to registration function. | |
| 105 registry->RegisterListPref(prefs::kInvalidatorMaxInvalidationVersions, | |
| 106 PrefRegistrySyncable::UNSYNCABLE_PREF); | |
| 107 registry->RegisterStringPref(prefs::kInvalidatorInvalidationState, | |
| 108 std::string(), | |
| 109 PrefRegistrySyncable::UNSYNCABLE_PREF); | |
| 110 registry->RegisterStringPref(prefs::kInvalidatorClientId, | |
| 111 std::string(), | |
| 112 PrefRegistrySyncable::UNSYNCABLE_PREF); | |
| 113 | |
| 114 MigrateMaxInvalidationVersionsPref(registry); | |
| 115 } | |
| 116 } | 117 } |
| 117 | 118 |
| 118 InvalidatorStorage::~InvalidatorStorage() { | 119 InvalidatorStorage::~InvalidatorStorage() { |
| 119 } | 120 } |
| 120 | 121 |
| 121 InvalidationStateMap InvalidatorStorage::GetAllInvalidationStates() const { | 122 InvalidationStateMap InvalidatorStorage::GetAllInvalidationStates() const { |
| 122 DCHECK(thread_checker_.CalledOnValidThread()); | 123 DCHECK(thread_checker_.CalledOnValidThread()); |
| 123 InvalidationStateMap state_map; | 124 InvalidationStateMap state_map; |
| 124 if (!pref_service_) { | 125 if (!pref_service_) { |
| 125 return state_map; | 126 return state_map; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 void InvalidatorStorage::SerializeToList( | 193 void InvalidatorStorage::SerializeToList( |
| 193 const InvalidationStateMap& state_map, | 194 const InvalidationStateMap& state_map, |
| 194 base::ListValue* state_map_list) { | 195 base::ListValue* state_map_list) { |
| 195 for (InvalidationStateMap::const_iterator it = state_map.begin(); | 196 for (InvalidationStateMap::const_iterator it = state_map.begin(); |
| 196 it != state_map.end(); ++it) { | 197 it != state_map.end(); ++it) { |
| 197 state_map_list->Append(ObjectIdAndStateToValue(it->first, it->second)); | 198 state_map_list->Append(ObjectIdAndStateToValue(it->first, it->second)); |
| 198 } | 199 } |
| 199 } | 200 } |
| 200 | 201 |
| 201 // Legacy migration code. | 202 // Legacy migration code. |
| 202 void InvalidatorStorage::MigrateMaxInvalidationVersionsPref( | 203 void InvalidatorStorage::MigrateMaxInvalidationVersionsPref() { |
| 203 PrefRegistrySyncable* registry) { | |
| 204 registry->RegisterDictionaryPref(prefs::kSyncMaxInvalidationVersions, | |
| 205 PrefRegistrySyncable::UNSYNCABLE_PREF); | |
| 206 const base::DictionaryValue* max_versions_dict = | 204 const base::DictionaryValue* max_versions_dict = |
| 207 pref_service_->GetDictionary(prefs::kSyncMaxInvalidationVersions); | 205 pref_service_->GetDictionary(prefs::kSyncMaxInvalidationVersions); |
| 208 CHECK(max_versions_dict); | 206 CHECK(max_versions_dict); |
| 209 if (!max_versions_dict->empty()) { | 207 if (!max_versions_dict->empty()) { |
| 210 InvalidationStateMap state_map; | 208 InvalidationStateMap state_map; |
| 211 DeserializeMap(max_versions_dict, &state_map); | 209 DeserializeMap(max_versions_dict, &state_map); |
| 212 base::ListValue state_map_list; | 210 base::ListValue state_map_list; |
| 213 SerializeToList(state_map, &state_map_list); | 211 SerializeToList(state_map, &state_map_list); |
| 214 pref_service_->Set(prefs::kInvalidatorMaxInvalidationVersions, | 212 pref_service_->Set(prefs::kInvalidatorMaxInvalidationVersions, |
| 215 state_map_list); | 213 state_map_list); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 return; | 332 return; |
| 335 it->second.current = ack_handle; | 333 it->second.current = ack_handle; |
| 336 | 334 |
| 337 base::ListValue state_map_list; | 335 base::ListValue state_map_list; |
| 338 SerializeToList(state_map, &state_map_list); | 336 SerializeToList(state_map, &state_map_list); |
| 339 pref_service_->Set(prefs::kInvalidatorMaxInvalidationVersions, | 337 pref_service_->Set(prefs::kInvalidatorMaxInvalidationVersions, |
| 340 state_map_list); | 338 state_map_list); |
| 341 } | 339 } |
| 342 | 340 |
| 343 } // namespace browser_sync | 341 } // namespace browser_sync |
| OLD | NEW |