| 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   if (pref_service_) | 
| 104     // TODO(joi): Move to registration function. | 117     MigrateMaxInvalidationVersionsPref(); | 
| 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 } | 118 } | 
| 117 | 119 | 
| 118 InvalidatorStorage::~InvalidatorStorage() { | 120 InvalidatorStorage::~InvalidatorStorage() { | 
| 119 } | 121 } | 
| 120 | 122 | 
| 121 InvalidationStateMap InvalidatorStorage::GetAllInvalidationStates() const { | 123 InvalidationStateMap InvalidatorStorage::GetAllInvalidationStates() const { | 
| 122   DCHECK(thread_checker_.CalledOnValidThread()); | 124   DCHECK(thread_checker_.CalledOnValidThread()); | 
| 123   InvalidationStateMap state_map; | 125   InvalidationStateMap state_map; | 
| 124   if (!pref_service_) { | 126   if (!pref_service_) { | 
| 125     return state_map; | 127     return state_map; | 
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 192 void InvalidatorStorage::SerializeToList( | 194 void InvalidatorStorage::SerializeToList( | 
| 193     const InvalidationStateMap& state_map, | 195     const InvalidationStateMap& state_map, | 
| 194     base::ListValue* state_map_list) { | 196     base::ListValue* state_map_list) { | 
| 195   for (InvalidationStateMap::const_iterator it = state_map.begin(); | 197   for (InvalidationStateMap::const_iterator it = state_map.begin(); | 
| 196        it != state_map.end(); ++it) { | 198        it != state_map.end(); ++it) { | 
| 197     state_map_list->Append(ObjectIdAndStateToValue(it->first, it->second)); | 199     state_map_list->Append(ObjectIdAndStateToValue(it->first, it->second)); | 
| 198   } | 200   } | 
| 199 } | 201 } | 
| 200 | 202 | 
| 201 // Legacy migration code. | 203 // Legacy migration code. | 
| 202 void InvalidatorStorage::MigrateMaxInvalidationVersionsPref( | 204 void InvalidatorStorage::MigrateMaxInvalidationVersionsPref() { | 
| 203     PrefRegistrySyncable* registry) { |  | 
| 204   registry->RegisterDictionaryPref(prefs::kSyncMaxInvalidationVersions, |  | 
| 205                                    PrefRegistrySyncable::UNSYNCABLE_PREF); |  | 
| 206   const base::DictionaryValue* max_versions_dict = | 205   const base::DictionaryValue* max_versions_dict = | 
| 207       pref_service_->GetDictionary(prefs::kSyncMaxInvalidationVersions); | 206       pref_service_->GetDictionary(prefs::kSyncMaxInvalidationVersions); | 
| 208   CHECK(max_versions_dict); | 207   CHECK(max_versions_dict); | 
| 209   if (!max_versions_dict->empty()) { | 208   if (!max_versions_dict->empty()) { | 
| 210     InvalidationStateMap state_map; | 209     InvalidationStateMap state_map; | 
| 211     DeserializeMap(max_versions_dict, &state_map); | 210     DeserializeMap(max_versions_dict, &state_map); | 
| 212     base::ListValue state_map_list; | 211     base::ListValue state_map_list; | 
| 213     SerializeToList(state_map, &state_map_list); | 212     SerializeToList(state_map, &state_map_list); | 
| 214     pref_service_->Set(prefs::kInvalidatorMaxInvalidationVersions, | 213     pref_service_->Set(prefs::kInvalidatorMaxInvalidationVersions, | 
| 215                        state_map_list); | 214                        state_map_list); | 
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 334     return; | 333     return; | 
| 335   it->second.current = ack_handle; | 334   it->second.current = ack_handle; | 
| 336 | 335 | 
| 337   base::ListValue state_map_list; | 336   base::ListValue state_map_list; | 
| 338   SerializeToList(state_map, &state_map_list); | 337   SerializeToList(state_map, &state_map_list); | 
| 339   pref_service_->Set(prefs::kInvalidatorMaxInvalidationVersions, | 338   pref_service_->Set(prefs::kInvalidatorMaxInvalidationVersions, | 
| 340                      state_map_list); | 339                      state_map_list); | 
| 341 } | 340 } | 
| 342 | 341 | 
| 343 }  // namespace browser_sync | 342 }  // namespace browser_sync | 
| OLD | NEW | 
|---|