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