| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/prefs/pref_model_associator.h" | 5 #include "chrome/browser/prefs/pref_model_associator.h" |
| 6 | 6 |
| 7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
| 9 #include "base/json/json_value_serializer.h" | 9 #include "base/json/json_value_serializer.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "chrome/browser/sync/api/sync_change.h" | 14 #include "chrome/browser/sync/api/sync_change.h" |
| 15 #include "chrome/browser/sync/protocol/preference_specifics.pb.h" | 15 #include "chrome/browser/sync/protocol/preference_specifics.pb.h" |
| 16 #include "chrome/common/chrome_notification_types.h" | 16 #include "chrome/common/chrome_notification_types.h" |
| 17 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
| 18 | 18 |
| 19 using syncable::PREFERENCES; | 19 using syncable::PREFERENCES; |
| 20 | 20 |
| 21 PrefModelAssociator::PrefModelAssociator() | 21 PrefModelAssociator::PrefModelAssociator() |
| 22 : models_associated_(false), | 22 : models_associated_(false), |
| 23 processing_syncer_changes_(false), | 23 processing_syncer_changes_(false), |
| 24 pref_service_(NULL), | 24 pref_service_(NULL), |
| 25 sync_processor_(NULL) { | 25 sync_processor_(NULL) { |
| 26 } | |
| 27 | |
| 28 PrefModelAssociator::PrefModelAssociator( | |
| 29 PrefService* pref_service) | |
| 30 : models_associated_(false), | |
| 31 processing_syncer_changes_(false), | |
| 32 pref_service_(pref_service), | |
| 33 sync_processor_(NULL) { | |
| 34 DCHECK(CalledOnValidThread()); | 26 DCHECK(CalledOnValidThread()); |
| 35 } | 27 } |
| 36 | 28 |
| 37 PrefModelAssociator::~PrefModelAssociator() { | 29 PrefModelAssociator::~PrefModelAssociator() { |
| 38 DCHECK(CalledOnValidThread()); | 30 DCHECK(CalledOnValidThread()); |
| 39 sync_processor_ = NULL; | 31 sync_processor_ = NULL; |
| 40 pref_service_ = NULL; | 32 pref_service_ = NULL; |
| 41 } | 33 } |
| 42 | 34 |
| 43 void PrefModelAssociator::InitPrefAndAssociate( | 35 void PrefModelAssociator::InitPrefAndAssociate( |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 // we'll send the new user controlled value to the syncer. | 98 // we'll send the new user controlled value to the syncer. |
| 107 return; | 99 return; |
| 108 } | 100 } |
| 109 | 101 |
| 110 // Make sure we add it to our list of synced preferences so we know what | 102 // Make sure we add it to our list of synced preferences so we know what |
| 111 // the server is aware of. | 103 // the server is aware of. |
| 112 synced_preferences_.insert(pref_name); | 104 synced_preferences_.insert(pref_name); |
| 113 return; | 105 return; |
| 114 } | 106 } |
| 115 | 107 |
| 108 void PrefModelAssociator::SetPrefService(PrefService* pref_service) { |
| 109 DCHECK(pref_service_ == NULL); |
| 110 pref_service = pref_service_; |
| 111 } |
| 112 |
| 116 SyncError PrefModelAssociator::MergeDataAndStartSyncing( | 113 SyncError PrefModelAssociator::MergeDataAndStartSyncing( |
| 117 syncable::ModelType type, | 114 syncable::ModelType type, |
| 118 const SyncDataList& initial_sync_data, | 115 const SyncDataList& initial_sync_data, |
| 119 SyncChangeProcessor* sync_processor) { | 116 SyncChangeProcessor* sync_processor) { |
| 120 DCHECK_EQ(type, PREFERENCES); | 117 DCHECK_EQ(type, PREFERENCES); |
| 121 DCHECK(CalledOnValidThread()); | 118 DCHECK(CalledOnValidThread()); |
| 122 DCHECK(!sync_processor_); | 119 DCHECK(!sync_processor_); |
| 123 sync_processor_ = sync_processor; | 120 sync_processor_ = sync_processor; |
| 124 | 121 |
| 125 SyncChangeList new_changes; | 122 SyncChangeList new_changes; |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 return; | 420 return; |
| 424 } | 421 } |
| 425 changes.push_back(SyncChange(SyncChange::ACTION_UPDATE, sync_data)); | 422 changes.push_back(SyncChange(SyncChange::ACTION_UPDATE, sync_data)); |
| 426 } | 423 } |
| 427 | 424 |
| 428 SyncError error = | 425 SyncError error = |
| 429 sync_processor_->ProcessSyncChanges(FROM_HERE, changes); | 426 sync_processor_->ProcessSyncChanges(FROM_HERE, changes); |
| 430 if (error.IsSet()) | 427 if (error.IsSet()) |
| 431 StopSyncing(PREFERENCES); | 428 StopSyncing(PREFERENCES); |
| 432 } | 429 } |
| OLD | NEW |