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 "extensions/browser/api/storage/backend_task_runner.h" |
11 #include "extensions/browser/api/storage/settings_namespace.h" | 11 #include "extensions/browser/api/storage/settings_namespace.h" |
12 | 12 |
13 using content::BrowserThread; | |
14 | |
15 namespace extensions { | 13 namespace extensions { |
16 | 14 |
17 SettingsSyncProcessor::SettingsSyncProcessor( | 15 SettingsSyncProcessor::SettingsSyncProcessor( |
18 const std::string& extension_id, | 16 const std::string& extension_id, |
19 syncer::ModelType type, | 17 syncer::ModelType type, |
20 syncer::SyncChangeProcessor* sync_processor) | 18 syncer::SyncChangeProcessor* sync_processor) |
21 : extension_id_(extension_id), | 19 : extension_id_(extension_id), |
22 type_(type), | 20 type_(type), |
23 sync_processor_(sync_processor), | 21 sync_processor_(sync_processor), |
24 initialized_(false) { | 22 initialized_(false) { |
25 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 23 DCHECK(IsOnBackendSequence()); |
26 CHECK(type == syncer::EXTENSION_SETTINGS || type == syncer::APP_SETTINGS); | 24 CHECK(type == syncer::EXTENSION_SETTINGS || type == syncer::APP_SETTINGS); |
27 CHECK(sync_processor); | 25 CHECK(sync_processor); |
28 } | 26 } |
29 | 27 |
30 SettingsSyncProcessor::~SettingsSyncProcessor() { | 28 SettingsSyncProcessor::~SettingsSyncProcessor() { |
31 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 29 DCHECK(IsOnBackendSequence()); |
32 } | 30 } |
33 | 31 |
34 void SettingsSyncProcessor::Init(const base::DictionaryValue& initial_state) { | 32 void SettingsSyncProcessor::Init(const base::DictionaryValue& initial_state) { |
35 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 33 DCHECK(IsOnBackendSequence()); |
36 CHECK(!initialized_) << "Init called multiple times"; | 34 CHECK(!initialized_) << "Init called multiple times"; |
37 | 35 |
38 for (base::DictionaryValue::Iterator i(initial_state); !i.IsAtEnd(); | 36 for (base::DictionaryValue::Iterator i(initial_state); !i.IsAtEnd(); |
39 i.Advance()) | 37 i.Advance()) |
40 synced_keys_.insert(i.key()); | 38 synced_keys_.insert(i.key()); |
41 | 39 |
42 initialized_ = true; | 40 initialized_ = true; |
43 } | 41 } |
44 | 42 |
45 syncer::SyncError SettingsSyncProcessor::SendChanges( | 43 syncer::SyncError SettingsSyncProcessor::SendChanges( |
46 const ValueStoreChangeList& changes) { | 44 const ValueStoreChangeList& changes) { |
47 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 45 DCHECK(IsOnBackendSequence()); |
48 CHECK(initialized_) << "Init not called"; | 46 CHECK(initialized_) << "Init not called"; |
49 | 47 |
50 syncer::SyncChangeList sync_changes; | 48 syncer::SyncChangeList sync_changes; |
51 std::set<std::string> added_keys; | 49 std::set<std::string> added_keys; |
52 std::set<std::string> deleted_keys; | 50 std::set<std::string> deleted_keys; |
53 | 51 |
54 for (ValueStoreChangeList::const_iterator i = changes.begin(); | 52 for (ValueStoreChangeList::const_iterator i = changes.begin(); |
55 i != changes.end(); ++i) { | 53 i != changes.end(); ++i) { |
56 const std::string& key = i->key(); | 54 const std::string& key = i->key(); |
57 const base::Value* value = i->new_value(); | 55 const base::Value* value = i->new_value(); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 synced_keys_.insert(added_keys.begin(), added_keys.end()); | 87 synced_keys_.insert(added_keys.begin(), added_keys.end()); |
90 for (std::set<std::string>::iterator i = deleted_keys.begin(); | 88 for (std::set<std::string>::iterator i = deleted_keys.begin(); |
91 i != deleted_keys.end(); ++i) { | 89 i != deleted_keys.end(); ++i) { |
92 synced_keys_.erase(*i); | 90 synced_keys_.erase(*i); |
93 } | 91 } |
94 | 92 |
95 return syncer::SyncError(); | 93 return syncer::SyncError(); |
96 } | 94 } |
97 | 95 |
98 void SettingsSyncProcessor::NotifyChanges(const ValueStoreChangeList& changes) { | 96 void SettingsSyncProcessor::NotifyChanges(const ValueStoreChangeList& changes) { |
99 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 97 DCHECK(IsOnBackendSequence()); |
100 CHECK(initialized_) << "Init not called"; | 98 CHECK(initialized_) << "Init not called"; |
101 | 99 |
102 for (ValueStoreChangeList::const_iterator i = changes.begin(); | 100 for (ValueStoreChangeList::const_iterator i = changes.begin(); |
103 i != changes.end(); ++i) { | 101 i != changes.end(); ++i) { |
104 if (i->new_value()) | 102 if (i->new_value()) |
105 synced_keys_.insert(i->key()); | 103 synced_keys_.insert(i->key()); |
106 else | 104 else |
107 synced_keys_.erase(i->key()); | 105 synced_keys_.erase(i->key()); |
108 } | 106 } |
109 } | 107 } |
110 | 108 |
111 } // namespace extensions | 109 } // namespace extensions |
OLD | NEW |