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

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: Reordering 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
19 : public ExtensionSettingsStorage,
20 public base::SupportsWeakPtr<SyncableExtensionSettingsStorage> {
21 public:
22 // Bundles the sync dependencies for sync-related callbacks. Since sync may
23 // be disabled at any time, and therefore the sync processor and synced keys
24 // made invalid, callbacks must only be passed weak references to them.
25 // Public for anonymous namespace access.
26 class SyncDeps : public base::SupportsWeakPtr<SyncDeps> {
27 public:
28 // Ownership of processor NOT taken.
29 explicit SyncDeps(SyncChangeProcessor* processor);
30 virtual ~SyncDeps();
31
32 SyncChangeProcessor* processor() { return processor_; }
33 std::set<std::string>* keys() { return &keys_; }
34
35 private:
36 // Sync's SyncChange handler. All changes are pushed through this.
37 SyncChangeProcessor* processor_;
38
39 // Keys of settings that have been synced. Track in order to correctly
40 // send an ACTION_ADD or ACTION_UPDATE to the processor on Set().
41 std::set<std::string> keys_;
42 };
43
44 explicit SyncableExtensionSettingsStorage(
45 std::string extension_id,
46 // Ownership taken.
47 ExtensionSettingsStorage* delegate);
48
49 // ExtensionSettingsStorage implementation.
50 virtual void Get(const std::string& key, Callback* callback) OVERRIDE;
Ben Olmstead 2011/08/31 17:36:43 No need for virtual and OVERRIDE together, just OV
akalin 2011/08/31 21:12:51 Don't we always want 'virtual' for clarity? Since
Ben Olmstead 2011/08/31 21:19:43 For some reason, I thought we didn't use the two t
not at google - send to devlin 2011/09/02 05:00:40 OVERRIDE and virtual are separate things, yes.
51 virtual void Get(const ListValue& keys, Callback* callback) OVERRIDE;
52 virtual void Get(Callback* callback) OVERRIDE;
53 virtual void Set(
54 const std::string& key, const Value& value, Callback* callback) OVERRIDE;
55 virtual void Set(const DictionaryValue& values, Callback* callback) OVERRIDE;
56 virtual void Remove(const std::string& key, Callback* callback) OVERRIDE;
57 virtual void Remove(const ListValue& keys, Callback* callback) OVERRIDE;
58 virtual void Clear(Callback *callback) OVERRIDE;
59 virtual void DeleteSoon() OVERRIDE;
60
61 // Sync-related methods.
62 void StartSyncing(
63 const DictionaryValue& sync_state,
64 // Guaranteed non-NULL. Ownership NOT taken.
65 SyncChangeProcessor* sync_processor);
66 void StopSyncing();
67 void ProcessSyncChanges(const ExtensionSettingSyncDataList& sync_changes);
68
69 private:
70 // Deleted from DeleteSoon().
71 virtual ~SyncableExtensionSettingsStorage();
72
73 // Id of the extension these settings are for.
74 std::string extension_id_;
75
76 // Decorated storage. Deleted in DeleteSoon().
77 ExtensionSettingsStorage* delegate_;
78
79 // Weak sync dependencies. Non-NULL while sync enabled (between calls to
80 // MergeDataAndStartSyncing and StopSyncing), NULL at other times.
81 SyncDeps* sync_deps_;
82
83 DISALLOW_COPY_AND_ASSIGN(SyncableExtensionSettingsStorage);
84 };
85
86 #endif // CHROME_BROWSER_EXTENSIONS_SYNCABLE_EXTENSION_SETTINGS_STORAGE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698