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 #ifndef CHROME_BROWSER_EXTENSIONS_SETTINGS_SETTINGS_SYNC_PROCESSOR_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_SETTINGS_SETTINGS_SYNC_PROCESSOR_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_SETTINGS_SETTINGS_SYNC_PROCESSOR_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_SETTINGS_SETTINGS_SYNC_PROCESSOR_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "chrome/browser/value_store/value_store_change.h" | 12 #include "chrome/browser/value_store/value_store_change.h" |
13 #include "sync/api/sync_error.h" | 13 #include "sync/api/sync_error.h" |
14 | 14 |
| 15 namespace csync { |
15 class SyncChangeProcessor; | 16 class SyncChangeProcessor; |
| 17 } // namespace csync |
16 | 18 |
17 namespace extensions { | 19 namespace extensions { |
18 | 20 |
19 // A wrapper for a SyncChangeProcessor that deals specifically with the syncing | 21 // A wrapper for a SyncChangeProcessor that deals specifically with the syncing |
20 // of a single extension's settings. Handles: | 22 // of a single extension's settings. Handles: |
21 // - translating SettingChanges into calls into the Sync API. | 23 // - translating SettingChanges into calls into the Sync API. |
22 // - deciding whether to ADD/REMOVE/SET depending on the current state of | 24 // - deciding whether to ADD/REMOVE/SET depending on the current state of |
23 // settings. | 25 // settings. |
24 // - rate limiting (inherently per-extension, which is what we want). | 26 // - rate limiting (inherently per-extension, which is what we want). |
25 class SettingsSyncProcessor { | 27 class SettingsSyncProcessor { |
26 public: | 28 public: |
27 SettingsSyncProcessor(const std::string& extension_id, | 29 SettingsSyncProcessor(const std::string& extension_id, |
28 syncable::ModelType type, | 30 syncable::ModelType type, |
29 SyncChangeProcessor* sync_processor); | 31 csync::SyncChangeProcessor* sync_processor); |
30 ~SettingsSyncProcessor(); | 32 ~SettingsSyncProcessor(); |
31 | 33 |
32 // Initializes this with the initial state of sync. | 34 // Initializes this with the initial state of sync. |
33 void Init(const DictionaryValue& initial_state); | 35 void Init(const DictionaryValue& initial_state); |
34 | 36 |
35 // Sends |changes| to sync. | 37 // Sends |changes| to sync. |
36 SyncError SendChanges(const ValueStoreChangeList& changes); | 38 csync::SyncError SendChanges(const ValueStoreChangeList& changes); |
37 | 39 |
38 // Informs this that |changes| have been receieved from sync. No action will | 40 // Informs this that |changes| have been receieved from sync. No action will |
39 // be taken, but this must be notified for internal bookkeeping. | 41 // be taken, but this must be notified for internal bookkeeping. |
40 void NotifyChanges(const ValueStoreChangeList& changes); | 42 void NotifyChanges(const ValueStoreChangeList& changes); |
41 | 43 |
42 syncable::ModelType type() { return type_; } | 44 syncable::ModelType type() { return type_; } |
43 | 45 |
44 private: | 46 private: |
45 // ID of the extension the changes are for. | 47 // ID of the extension the changes are for. |
46 const std::string extension_id_; | 48 const std::string extension_id_; |
47 | 49 |
48 // Sync model type. Either EXTENSION_SETTING or APP_SETTING. | 50 // Sync model type. Either EXTENSION_SETTING or APP_SETTING. |
49 const syncable::ModelType type_; | 51 const syncable::ModelType type_; |
50 | 52 |
51 // The sync processor used to send changes to sync. | 53 // The sync processor used to send changes to sync. |
52 SyncChangeProcessor* const sync_processor_; | 54 csync::SyncChangeProcessor* const sync_processor_; |
53 | 55 |
54 // Whether Init() has been called. | 56 // Whether Init() has been called. |
55 bool initialized_; | 57 bool initialized_; |
56 | 58 |
57 // Keys of the settings that are currently being synced. Used to decide what | 59 // Keys of the settings that are currently being synced. Used to decide what |
58 // kind of action (ADD, UPDATE, REMOVE) to send to sync. | 60 // kind of action (ADD, UPDATE, REMOVE) to send to sync. |
59 std::set<std::string> synced_keys_; | 61 std::set<std::string> synced_keys_; |
60 | 62 |
61 DISALLOW_COPY_AND_ASSIGN(SettingsSyncProcessor); | 63 DISALLOW_COPY_AND_ASSIGN(SettingsSyncProcessor); |
62 }; | 64 }; |
63 | 65 |
64 } // namespace extensions | 66 } // namespace extensions |
65 | 67 |
66 #endif // CHROME_BROWSER_EXTENSIONS_SETTINGS_SETTINGS_SYNC_PROCESSOR_H_ | 68 #endif // CHROME_BROWSER_EXTENSIONS_SETTINGS_SETTINGS_SYNC_PROCESSOR_H_ |
OLD | NEW |