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