| 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/extensions/api/storage/settings_sync_processor.h" | 5 #include "chrome/browser/extensions/api/storage/settings_sync_processor.h" |
| 6 #include "chrome/browser/extensions/api/storage/settings_sync_util.h" | 6 #include "chrome/browser/extensions/api/storage/settings_sync_util.h" |
| 7 #include "components/sync/model/sync_change_processor.h" | 7 #include "components/sync/model/sync_change_processor.h" |
| 8 #include "components/sync/model/sync_data.h" | 8 #include "components/sync/model/sync_data.h" |
| 9 #include "components/sync/protocol/extension_setting_specifics.pb.h" | 9 #include "components/sync/protocol/extension_setting_specifics.pb.h" |
| 10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 CHECK(type == syncer::EXTENSION_SETTINGS || type == syncer::APP_SETTINGS); | 26 CHECK(type == syncer::EXTENSION_SETTINGS || type == syncer::APP_SETTINGS); |
| 27 CHECK(sync_processor); | 27 CHECK(sync_processor); |
| 28 } | 28 } |
| 29 | 29 |
| 30 SettingsSyncProcessor::~SettingsSyncProcessor() { | 30 SettingsSyncProcessor::~SettingsSyncProcessor() { |
| 31 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 31 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 32 } | 32 } |
| 33 | 33 |
| 34 void SettingsSyncProcessor::Init(const base::DictionaryValue& initial_state) { | 34 void SettingsSyncProcessor::Init(const base::DictionaryValue& initial_state) { |
| 35 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 35 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 36 CHECK(!initialized_) << "Init called multiple times"; | 36 // Init called multiple times |
| 37 CHECK(!initialized_); |
| 37 | 38 |
| 38 for (base::DictionaryValue::Iterator i(initial_state); !i.IsAtEnd(); | 39 for (base::DictionaryValue::Iterator i(initial_state); !i.IsAtEnd(); |
| 39 i.Advance()) | 40 i.Advance()) |
| 40 synced_keys_.insert(i.key()); | 41 synced_keys_.insert(i.key()); |
| 41 | 42 |
| 42 initialized_ = true; | 43 initialized_ = true; |
| 43 } | 44 } |
| 44 | 45 |
| 45 syncer::SyncError SettingsSyncProcessor::SendChanges( | 46 syncer::SyncError SettingsSyncProcessor::SendChanges( |
| 46 const ValueStoreChangeList& changes) { | 47 const ValueStoreChangeList& changes) { |
| 47 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 48 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 48 CHECK(initialized_) << "Init not called"; | 49 // Init not called |
| 50 CHECK(initialized_); |
| 49 | 51 |
| 50 syncer::SyncChangeList sync_changes; | 52 syncer::SyncChangeList sync_changes; |
| 51 std::set<std::string> added_keys; | 53 std::set<std::string> added_keys; |
| 52 std::set<std::string> deleted_keys; | 54 std::set<std::string> deleted_keys; |
| 53 | 55 |
| 54 for (ValueStoreChangeList::const_iterator i = changes.begin(); | 56 for (ValueStoreChangeList::const_iterator i = changes.begin(); |
| 55 i != changes.end(); ++i) { | 57 i != changes.end(); ++i) { |
| 56 const std::string& key = i->key(); | 58 const std::string& key = i->key(); |
| 57 const base::Value* value = i->new_value(); | 59 const base::Value* value = i->new_value(); |
| 58 if (value) { | 60 if (value) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 for (std::set<std::string>::iterator i = deleted_keys.begin(); | 92 for (std::set<std::string>::iterator i = deleted_keys.begin(); |
| 91 i != deleted_keys.end(); ++i) { | 93 i != deleted_keys.end(); ++i) { |
| 92 synced_keys_.erase(*i); | 94 synced_keys_.erase(*i); |
| 93 } | 95 } |
| 94 | 96 |
| 95 return syncer::SyncError(); | 97 return syncer::SyncError(); |
| 96 } | 98 } |
| 97 | 99 |
| 98 void SettingsSyncProcessor::NotifyChanges(const ValueStoreChangeList& changes) { | 100 void SettingsSyncProcessor::NotifyChanges(const ValueStoreChangeList& changes) { |
| 99 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 101 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 100 CHECK(initialized_) << "Init not called"; | 102 // Init not called |
| 103 CHECK(initialized_); |
| 101 | 104 |
| 102 for (ValueStoreChangeList::const_iterator i = changes.begin(); | 105 for (ValueStoreChangeList::const_iterator i = changes.begin(); |
| 103 i != changes.end(); ++i) { | 106 i != changes.end(); ++i) { |
| 104 if (i->new_value()) | 107 if (i->new_value()) |
| 105 synced_keys_.insert(i->key()); | 108 synced_keys_.insert(i->key()); |
| 106 else | 109 else |
| 107 synced_keys_.erase(i->key()); | 110 synced_keys_.erase(i->key()); |
| 108 } | 111 } |
| 109 } | 112 } |
| 110 | 113 |
| 111 } // namespace extensions | 114 } // namespace extensions |
| OLD | NEW |