OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 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_SYNCABLE_EXTENSION_SETTINGS_STORAGE_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_SYNCABLE_EXTENSION_SETTINGS_STORAGE_H_ |
| 7 #pragma once |
| 8 |
| 9 #include "base/compiler_specific.h" |
| 10 #include "base/memory/weak_ptr.h" |
| 11 #include "base/values.h" |
| 12 #include "chrome/browser/extensions/extension_settings_storage.h" |
| 13 #include "chrome/browser/extensions/extension_setting_sync_data.h" |
| 14 #include "chrome/browser/sync/api/syncable_service.h" |
| 15 #include "chrome/browser/sync/api/sync_change.h" |
| 16 |
| 17 // Decorates an ExtensionSettingsStorage with sync behaviour. |
| 18 class SyncableExtensionSettingsStorage : public ExtensionSettingsStorage { |
| 19 public: |
| 20 explicit SyncableExtensionSettingsStorage( |
| 21 std::string extension_id, |
| 22 // Ownership taken. |
| 23 ExtensionSettingsStorage* delegate); |
| 24 |
| 25 virtual ~SyncableExtensionSettingsStorage(); |
| 26 |
| 27 // ExtensionSettingsStorage implementation. |
| 28 virtual Result Get(const std::string& key) OVERRIDE; |
| 29 virtual Result Get(const std::vector<std::string>& keys) OVERRIDE; |
| 30 virtual Result Get() OVERRIDE; |
| 31 virtual Result Set(const std::string& key, const Value& value) OVERRIDE; |
| 32 virtual Result Set(const DictionaryValue& settings) OVERRIDE; |
| 33 virtual Result Remove(const std::string& key) OVERRIDE; |
| 34 virtual Result Remove(const std::vector<std::string>& keys) OVERRIDE; |
| 35 virtual Result Clear() OVERRIDE; |
| 36 |
| 37 // Sync-related methods. |
| 38 void StartSyncing( |
| 39 const DictionaryValue& sync_state, |
| 40 // Must be non-NULL. Ownership NOT taken. |
| 41 SyncChangeProcessor* sync_processor); |
| 42 void StopSyncing(); |
| 43 void ProcessSyncChanges(const ExtensionSettingSyncDataList& sync_changes); |
| 44 |
| 45 private: |
| 46 // Either adds to sync or send updates to sync for some settings. |
| 47 // Whether they're adds or updates depends on the state of synced_keys_. |
| 48 void SendAddsOrUpdatesToSync(const DictionaryValue& settings); |
| 49 |
| 50 // Sends deletes to sync for some settings. |
| 51 void SendDeletesToSync(const std::vector<std::string>& keys); |
| 52 |
| 53 // Sends all local settings to sync (synced settings assumed to be empty). |
| 54 void SendLocalSettingsToSync( |
| 55 const DictionaryValue& settings); |
| 56 |
| 57 // Overwrites local state with sync state. |
| 58 void OverwriteLocalSettingsWithSync( |
| 59 const DictionaryValue& sync_state, const DictionaryValue& settings); |
| 60 |
| 61 // Id of the extension these settings are for. |
| 62 std::string const extension_id_; |
| 63 |
| 64 // Storage area to sync. |
| 65 const scoped_ptr<ExtensionSettingsStorage> const delegate_; |
| 66 |
| 67 // Sync processor. Non-NULL while sync is enabled (between calls to |
| 68 // StartSyncing and StopSyncing). |
| 69 SyncChangeProcessor* sync_processor_; |
| 70 |
| 71 // Keys of the settings that are currently being synced. |
| 72 std::set<std::string> synced_keys_; |
| 73 |
| 74 DISALLOW_COPY_AND_ASSIGN(SyncableExtensionSettingsStorage); |
| 75 }; |
| 76 |
| 77 #endif // CHROME_BROWSER_EXTENSIONS_SYNCABLE_EXTENSION_SETTINGS_STORAGE_H_ |
OLD | NEW |