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

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

Issue 7747043: WORK IN PROGRESS. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Small change 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_settings_sync_data.h"
14 #include "chrome/browser/sync/api/syncable_service.h"
15 #include "chrome/browser/sync/api/sync_change.h"
16
17 // XXX repro/investigate sqlite crash.
18 // XXX rename Push to Send?
19 // ... RemoveFromSyncCallback -> SendRemoveToSyncCallback?
20
21 // Decorates an ExtensionSettingsStorage with sync behaviour.
22 class SyncableExtensionSettingsStorage : public ExtensionSettingsStorage {
23 public:
24 // Bundles the sync dependencies for sync-related callbacks. Since sync may
25 // be disabled at any time, and therefore the sync processor and synced keys
26 // made invalid, callbacks must only be passed weak references to them.
27 // Public for anonymous namespace access.
28 class SyncDeps : public base::SupportsWeakPtr<SyncDeps> {
29 public:
30 // Ownership of processor NOT taken.
31 explicit SyncDeps(SyncChangeProcessor* processor);
32 virtual ~SyncDeps();
33
34 SyncChangeProcessor* processor() { return processor_; }
35 std::set<std::string>* keys() { return &keys_; }
36
37 private:
38 // Sync's SyncChange handler. All changes are pushed through this.
39 SyncChangeProcessor* processor_;
40
41 // Keys of settings that have been synced. Track in order to correctly
42 // send an ACTION_ADD or ACTION_UPDATE to the processor on Set().
43 std::set<std::string> keys_;
44 };
45
46 explicit SyncableExtensionSettingsStorage(
47 std::string extension_id,
48 // Ownership taken.
49 ExtensionSettingsStorage* delegate);
50
51 // ExtensionSettingsStorage implementation.
52 virtual void Get(const std::string& key, Callback* callback) OVERRIDE;
53 virtual void Get(const ListValue& keys, Callback* callback) OVERRIDE;
54 virtual void Get(Callback* callback) OVERRIDE;
55 virtual void Set(
56 const std::string& key, const Value& value, Callback* callback) OVERRIDE;
57 virtual void Set(const DictionaryValue& values, Callback* callback) OVERRIDE;
58 virtual void Remove(const std::string& key, Callback* callback) OVERRIDE;
59 virtual void Remove(const ListValue& keys, Callback* callback) OVERRIDE;
60 virtual void Clear(Callback *callback) OVERRIDE;
61 virtual void DeleteSoon() OVERRIDE;
62
63 // Sync-related methods.
64 void StartSyncing(
65 const DictionaryValue& sync_state,
66 // Guaranteed non-NULL. Ownership NOT taken.
67 SyncChangeProcessor* sync_processor);
68 void StopSyncing();
69 void ProcessSyncChanges(const ExtensionSettingsSyncDataList& sync_changes);
70
71 private:
72 // Deleted from DeleteSoon().
73 virtual ~SyncableExtensionSettingsStorage();
74
75 // Id of the extension these settings are for.
76 std::string extension_id_;
77
78 // Decorated storage. Deleted in DeleteSoon().
79 ExtensionSettingsStorage* delegate_;
80
81 // Weak sync dependencies. Non-NULL while sync enabled (between calls to
82 // MergeDataAndStartSyncing and StopSyncing), NULL at other times.
83 SyncDeps* sync_deps_;
84
85 DISALLOW_COPY_AND_ASSIGN(SyncableExtensionSettingsStorage);
86 };
87
88 #endif // CHROME_BROWSER_EXTENSIONS_SYNCABLE_EXTENSION_SETTINGS_STORAGE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698