Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(262)

Side by Side Diff: chrome/browser/extensions/syncable_extension_settings_storage.h

Issue 7775008: Enable sync for the settings from the Extension Settings API. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Sync to tip. Latest comments. Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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, analogous to those on SyncableService (handled by
38 // ExtensionSettings).
39 SyncError StartSyncing(
40 const DictionaryValue& sync_state,
41 // Must NOT be NULL. Ownership NOT taken.
42 SyncChangeProcessor* sync_processor);
43 void StopSyncing();
44 std::vector<SyncError> ProcessSyncChanges(
45 const ExtensionSettingSyncDataList& sync_changes);
46
47 private:
48 // Either adds to sync or send updates to sync for some settings.
49 // Whether they're adds or updates depends on the state of synced_keys_.
50 void SendAddsOrUpdatesToSync(const DictionaryValue& settings);
51
52 // Sends deletes to sync for some settings.
53 void SendDeletesToSync(const std::vector<std::string>& keys);
54
55 // Sends all local settings to sync (synced settings assumed to be empty).
56 SyncError SendLocalSettingsToSync(
57 const DictionaryValue& settings);
58
59 // Overwrites local state with sync state.
60 SyncError OverwriteLocalSettingsWithSync(
61 const DictionaryValue& sync_state, const DictionaryValue& settings);
62
63 // Id of the extension these settings are for.
64 std::string const extension_id_;
65
66 // Storage area to sync.
67 const scoped_ptr<ExtensionSettingsStorage> delegate_;
68
69 // Sync processor. Non-NULL while sync is enabled (between calls to
70 // StartSyncing and StopSyncing).
71 SyncChangeProcessor* sync_processor_;
72
73 // Keys of the settings that are currently being synced.
74 std::set<std::string> synced_keys_;
75
76 DISALLOW_COPY_AND_ASSIGN(SyncableExtensionSettingsStorage);
77 };
78
79 #endif // CHROME_BROWSER_EXTENSIONS_SYNCABLE_EXTENSION_SETTINGS_STORAGE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698