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" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
14 #include "base/task_runner.h" | 14 #include "base/task_runner.h" |
15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "chrome/browser/prefs/pref_registry_syncable.h" |
16 #include "chrome/browser/prefs/pref_service.h" | 17 #include "chrome/browser/prefs/pref_service.h" |
17 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
18 #include "sync/internal_api/public/base/model_type.h" | 19 #include "sync/internal_api/public/base/model_type.h" |
19 | 20 |
20 using syncer::InvalidationStateMap; | 21 using syncer::InvalidationStateMap; |
21 | 22 |
22 namespace browser_sync { | 23 namespace browser_sync { |
23 | 24 |
24 namespace { | 25 namespace { |
25 | 26 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 value->SetString(kPayloadKey, state.payload); | 87 value->SetString(kPayloadKey, state.payload); |
87 if (state.current.IsValid()) | 88 if (state.current.IsValid()) |
88 value->Set(kCurrentAckHandleKey, state.current.ToValue().release()); | 89 value->Set(kCurrentAckHandleKey, state.current.ToValue().release()); |
89 if (state.expected.IsValid()) | 90 if (state.expected.IsValid()) |
90 value->Set(kExpectedAckHandleKey, state.expected.ToValue().release()); | 91 value->Set(kExpectedAckHandleKey, state.expected.ToValue().release()); |
91 return value; | 92 return value; |
92 } | 93 } |
93 | 94 |
94 } // namespace | 95 } // namespace |
95 | 96 |
96 InvalidatorStorage::InvalidatorStorage(PrefServiceSyncable* pref_service) | 97 InvalidatorStorage::InvalidatorStorage(PrefService* pref_service, |
| 98 PrefRegistrySyncable* registry) |
97 : pref_service_(pref_service) { | 99 : pref_service_(pref_service) { |
98 // TODO(tim): Create a Mock instead of maintaining the if(!pref_service_) case | 100 // 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 | 101 // throughout this file. This is a problem now due to lack of injection at |
100 // ProfileSyncService. Bug 130176. | 102 // ProfileSyncService. Bug 130176. |
101 if (pref_service_) { | 103 if (registry) { |
102 pref_service_->RegisterListPref(prefs::kInvalidatorMaxInvalidationVersions, | 104 // TODO(joi): Move to registration function. |
103 PrefServiceSyncable::UNSYNCABLE_PREF); | 105 registry->RegisterListPref(prefs::kInvalidatorMaxInvalidationVersions, |
104 pref_service_->RegisterStringPref(prefs::kInvalidatorInvalidationState, | 106 PrefRegistrySyncable::UNSYNCABLE_PREF); |
105 std::string(), | 107 registry->RegisterStringPref(prefs::kInvalidatorInvalidationState, |
106 PrefServiceSyncable::UNSYNCABLE_PREF); | 108 std::string(), |
107 pref_service_->RegisterStringPref(prefs::kInvalidatorClientId, | 109 PrefRegistrySyncable::UNSYNCABLE_PREF); |
108 std::string(), | 110 registry->RegisterStringPref(prefs::kInvalidatorClientId, |
109 PrefServiceSyncable::UNSYNCABLE_PREF); | 111 std::string(), |
| 112 PrefRegistrySyncable::UNSYNCABLE_PREF); |
110 | 113 |
111 MigrateMaxInvalidationVersionsPref(); | 114 MigrateMaxInvalidationVersionsPref(registry); |
112 } | 115 } |
113 } | 116 } |
114 | 117 |
115 InvalidatorStorage::~InvalidatorStorage() { | 118 InvalidatorStorage::~InvalidatorStorage() { |
116 } | 119 } |
117 | 120 |
118 InvalidationStateMap InvalidatorStorage::GetAllInvalidationStates() const { | 121 InvalidationStateMap InvalidatorStorage::GetAllInvalidationStates() const { |
119 DCHECK(thread_checker_.CalledOnValidThread()); | 122 DCHECK(thread_checker_.CalledOnValidThread()); |
120 InvalidationStateMap state_map; | 123 InvalidationStateMap state_map; |
121 if (!pref_service_) { | 124 if (!pref_service_) { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 void InvalidatorStorage::SerializeToList( | 192 void InvalidatorStorage::SerializeToList( |
190 const InvalidationStateMap& state_map, | 193 const InvalidationStateMap& state_map, |
191 base::ListValue* state_map_list) { | 194 base::ListValue* state_map_list) { |
192 for (InvalidationStateMap::const_iterator it = state_map.begin(); | 195 for (InvalidationStateMap::const_iterator it = state_map.begin(); |
193 it != state_map.end(); ++it) { | 196 it != state_map.end(); ++it) { |
194 state_map_list->Append(ObjectIdAndStateToValue(it->first, it->second)); | 197 state_map_list->Append(ObjectIdAndStateToValue(it->first, it->second)); |
195 } | 198 } |
196 } | 199 } |
197 | 200 |
198 // Legacy migration code. | 201 // Legacy migration code. |
199 void InvalidatorStorage::MigrateMaxInvalidationVersionsPref() { | 202 void InvalidatorStorage::MigrateMaxInvalidationVersionsPref( |
200 pref_service_->RegisterDictionaryPref(prefs::kSyncMaxInvalidationVersions, | 203 PrefRegistrySyncable* registry) { |
201 PrefServiceSyncable::UNSYNCABLE_PREF); | 204 registry->RegisterDictionaryPref(prefs::kSyncMaxInvalidationVersions, |
| 205 PrefRegistrySyncable::UNSYNCABLE_PREF); |
202 const base::DictionaryValue* max_versions_dict = | 206 const base::DictionaryValue* max_versions_dict = |
203 pref_service_->GetDictionary(prefs::kSyncMaxInvalidationVersions); | 207 pref_service_->GetDictionary(prefs::kSyncMaxInvalidationVersions); |
204 CHECK(max_versions_dict); | 208 CHECK(max_versions_dict); |
205 if (!max_versions_dict->empty()) { | 209 if (!max_versions_dict->empty()) { |
206 InvalidationStateMap state_map; | 210 InvalidationStateMap state_map; |
207 DeserializeMap(max_versions_dict, &state_map); | 211 DeserializeMap(max_versions_dict, &state_map); |
208 base::ListValue state_map_list; | 212 base::ListValue state_map_list; |
209 SerializeToList(state_map, &state_map_list); | 213 SerializeToList(state_map, &state_map_list); |
210 pref_service_->Set(prefs::kInvalidatorMaxInvalidationVersions, | 214 pref_service_->Set(prefs::kInvalidatorMaxInvalidationVersions, |
211 state_map_list); | 215 state_map_list); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 return; | 334 return; |
331 it->second.current = ack_handle; | 335 it->second.current = ack_handle; |
332 | 336 |
333 base::ListValue state_map_list; | 337 base::ListValue state_map_list; |
334 SerializeToList(state_map, &state_map_list); | 338 SerializeToList(state_map, &state_map_list); |
335 pref_service_->Set(prefs::kInvalidatorMaxInvalidationVersions, | 339 pref_service_->Set(prefs::kInvalidatorMaxInvalidationVersions, |
336 state_map_list); | 340 state_map_list); |
337 } | 341 } |
338 | 342 |
339 } // namespace browser_sync | 343 } // namespace browser_sync |
OLD | NEW |