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/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_string_value_serializer.h" | 9 #include "base/json/json_string_value_serializer.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 } | 73 } |
74 | 74 |
75 // If the merge resulted in an updated value, inform the syncer. | 75 // If the merge resulted in an updated value, inform the syncer. |
76 if (!value->Equals(new_value.get())) { | 76 if (!value->Equals(new_value.get())) { |
77 syncer::SyncData sync_data; | 77 syncer::SyncData sync_data; |
78 if (!CreatePrefSyncData(pref->name(), *new_value, &sync_data)) { | 78 if (!CreatePrefSyncData(pref->name(), *new_value, &sync_data)) { |
79 LOG(ERROR) << "Failed to update preference."; | 79 LOG(ERROR) << "Failed to update preference."; |
80 return; | 80 return; |
81 } | 81 } |
82 sync_changes->push_back( | 82 sync_changes->push_back( |
83 syncer::SyncChange(FROM_HERE, | 83 syncer::SyncChange(syncer::SyncChange::ACTION_UPDATE, sync_data)); |
84 syncer::SyncChange::ACTION_UPDATE, | |
85 sync_data)); | |
86 } | 84 } |
87 } else if (pref->IsUserControlled()) { | 85 } else if (pref->IsUserControlled()) { |
88 // The server does not know about this preference and should be added | 86 // The server does not know about this preference and should be added |
89 // to the syncer's database. | 87 // to the syncer's database. |
90 syncer::SyncData sync_data; | 88 syncer::SyncData sync_data; |
91 if (!CreatePrefSyncData(pref->name(), *pref->GetValue(), &sync_data)) { | 89 if (!CreatePrefSyncData(pref->name(), *pref->GetValue(), &sync_data)) { |
92 LOG(ERROR) << "Failed to update preference."; | 90 LOG(ERROR) << "Failed to update preference."; |
93 return; | 91 return; |
94 } | 92 } |
95 sync_changes->push_back( | 93 sync_changes->push_back( |
96 syncer::SyncChange(FROM_HERE, | 94 syncer::SyncChange(syncer::SyncChange::ACTION_ADD, sync_data)); |
97 syncer::SyncChange::ACTION_ADD, | |
98 sync_data)); | |
99 } else { | 95 } else { |
100 // This pref does not have a sync value but also does not have a user | 96 // This pref does not have a sync value but also does not have a user |
101 // controlled value (either it's a default value or it's policy controlled, | 97 // controlled value (either it's a default value or it's policy controlled, |
102 // either way it's not interesting). We can ignore it. Once it gets changed, | 98 // either way it's not interesting). We can ignore it. Once it gets changed, |
103 // we'll send the new user controlled value to the syncer. | 99 // we'll send the new user controlled value to the syncer. |
104 return; | 100 return; |
105 } | 101 } |
106 | 102 |
107 // Make sure we add it to our list of synced preferences so we know what | 103 // Make sure we add it to our list of synced preferences so we know what |
108 // the server is aware of. | 104 // the server is aware of. |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 // and hasn't been changed yet we don't) and take care syncing any new data. | 421 // and hasn't been changed yet we don't) and take care syncing any new data. |
426 InitPrefAndAssociate(syncer::SyncData(), name, &changes); | 422 InitPrefAndAssociate(syncer::SyncData(), name, &changes); |
427 } else { | 423 } else { |
428 // We are already syncing this preference, just update it's sync node. | 424 // We are already syncing this preference, just update it's sync node. |
429 syncer::SyncData sync_data; | 425 syncer::SyncData sync_data; |
430 if (!CreatePrefSyncData(name, *preference->GetValue(), &sync_data)) { | 426 if (!CreatePrefSyncData(name, *preference->GetValue(), &sync_data)) { |
431 LOG(ERROR) << "Failed to update preference."; | 427 LOG(ERROR) << "Failed to update preference."; |
432 return; | 428 return; |
433 } | 429 } |
434 changes.push_back( | 430 changes.push_back( |
435 syncer::SyncChange(FROM_HERE, | 431 syncer::SyncChange(syncer::SyncChange::ACTION_UPDATE, sync_data)); |
436 syncer::SyncChange::ACTION_UPDATE, | |
437 sync_data)); | |
438 } | 432 } |
439 | 433 |
440 syncer::SyncError error = | 434 syncer::SyncError error = |
441 sync_processor_->ProcessSyncChanges(FROM_HERE, changes); | 435 sync_processor_->ProcessSyncChanges(FROM_HERE, changes); |
442 } | 436 } |
443 | 437 |
444 void PrefModelAssociator::SetPrefService(PrefService* pref_service) { | 438 void PrefModelAssociator::SetPrefService(PrefService* pref_service) { |
445 DCHECK(pref_service_ == NULL); | 439 DCHECK(pref_service_ == NULL); |
446 pref_service_ = pref_service; | 440 pref_service_ = pref_service; |
447 } | 441 } |
OLD | NEW |