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/string_number_conversions.h" | 13 #include "base/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) { |
Mattias Nissler (ping if slow)
2013/02/06 17:53:33
TODO: Move to registration function.
Jói
2013/02/07 14:52:32
Done.
| |
102 pref_service_->RegisterListPref(prefs::kInvalidatorMaxInvalidationVersions, | 104 registry->RegisterListPref(prefs::kInvalidatorMaxInvalidationVersions, |
103 PrefServiceSyncable::UNSYNCABLE_PREF); | 105 PrefRegistrySyncable::UNSYNCABLE_PREF); |
104 pref_service_->RegisterStringPref(prefs::kInvalidatorInvalidationState, | 106 registry->RegisterStringPref(prefs::kInvalidatorInvalidationState, |
105 std::string(), | 107 std::string(), |
106 PrefServiceSyncable::UNSYNCABLE_PREF); | 108 PrefRegistrySyncable::UNSYNCABLE_PREF); |
107 | 109 |
108 MigrateMaxInvalidationVersionsPref(); | 110 MigrateMaxInvalidationVersionsPref(registry); |
109 } | 111 } |
110 } | 112 } |
111 | 113 |
112 InvalidatorStorage::~InvalidatorStorage() { | 114 InvalidatorStorage::~InvalidatorStorage() { |
113 } | 115 } |
114 | 116 |
115 InvalidationStateMap InvalidatorStorage::GetAllInvalidationStates() const { | 117 InvalidationStateMap InvalidatorStorage::GetAllInvalidationStates() const { |
116 DCHECK(thread_checker_.CalledOnValidThread()); | 118 DCHECK(thread_checker_.CalledOnValidThread()); |
117 InvalidationStateMap state_map; | 119 InvalidationStateMap state_map; |
118 if (!pref_service_) { | 120 if (!pref_service_) { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
186 void InvalidatorStorage::SerializeToList( | 188 void InvalidatorStorage::SerializeToList( |
187 const InvalidationStateMap& state_map, | 189 const InvalidationStateMap& state_map, |
188 base::ListValue* state_map_list) { | 190 base::ListValue* state_map_list) { |
189 for (InvalidationStateMap::const_iterator it = state_map.begin(); | 191 for (InvalidationStateMap::const_iterator it = state_map.begin(); |
190 it != state_map.end(); ++it) { | 192 it != state_map.end(); ++it) { |
191 state_map_list->Append(ObjectIdAndStateToValue(it->first, it->second)); | 193 state_map_list->Append(ObjectIdAndStateToValue(it->first, it->second)); |
192 } | 194 } |
193 } | 195 } |
194 | 196 |
195 // Legacy migration code. | 197 // Legacy migration code. |
196 void InvalidatorStorage::MigrateMaxInvalidationVersionsPref() { | 198 void InvalidatorStorage::MigrateMaxInvalidationVersionsPref( |
197 pref_service_->RegisterDictionaryPref(prefs::kSyncMaxInvalidationVersions, | 199 PrefRegistrySyncable* registry) { |
198 PrefServiceSyncable::UNSYNCABLE_PREF); | 200 registry->RegisterDictionaryPref(prefs::kSyncMaxInvalidationVersions, |
201 PrefRegistrySyncable::UNSYNCABLE_PREF); | |
199 const base::DictionaryValue* max_versions_dict = | 202 const base::DictionaryValue* max_versions_dict = |
200 pref_service_->GetDictionary(prefs::kSyncMaxInvalidationVersions); | 203 pref_service_->GetDictionary(prefs::kSyncMaxInvalidationVersions); |
201 CHECK(max_versions_dict); | 204 CHECK(max_versions_dict); |
202 if (!max_versions_dict->empty()) { | 205 if (!max_versions_dict->empty()) { |
203 InvalidationStateMap state_map; | 206 InvalidationStateMap state_map; |
204 DeserializeMap(max_versions_dict, &state_map); | 207 DeserializeMap(max_versions_dict, &state_map); |
205 base::ListValue state_map_list; | 208 base::ListValue state_map_list; |
206 SerializeToList(state_map, &state_map_list); | 209 SerializeToList(state_map, &state_map_list); |
207 pref_service_->Set(prefs::kInvalidatorMaxInvalidationVersions, | 210 pref_service_->Set(prefs::kInvalidatorMaxInvalidationVersions, |
208 state_map_list); | 211 state_map_list); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
315 return; | 318 return; |
316 it->second.current = ack_handle; | 319 it->second.current = ack_handle; |
317 | 320 |
318 base::ListValue state_map_list; | 321 base::ListValue state_map_list; |
319 SerializeToList(state_map, &state_map_list); | 322 SerializeToList(state_map, &state_map_list); |
320 pref_service_->Set(prefs::kInvalidatorMaxInvalidationVersions, | 323 pref_service_->Set(prefs::kInvalidatorMaxInvalidationVersions, |
321 state_map_list); | 324 state_map_list); |
322 } | 325 } |
323 | 326 |
324 } // namespace browser_sync | 327 } // namespace browser_sync |
OLD | NEW |