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

Side by Side Diff: chrome/browser/extensions/api/storage/syncable_settings_storage.h

Issue 11826048: Revert 176015 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 11 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) 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_SYNCABLE_SETTINGS_STORAGE_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_STORAGE_SYNCABLE_SETTINGS_STORAGE_H_
7
8 #include "base/compiler_specific.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/observer_list_threadsafe.h"
12 #include "base/values.h"
13 #include "chrome/browser/extensions/api/storage/setting_sync_data.h"
14 #include "chrome/browser/extensions/api/storage/settings_observer.h"
15 #include "chrome/browser/value_store/value_store.h"
16 #include "sync/api/sync_change.h"
17 #include "sync/api/syncable_service.h"
18
19 namespace extensions {
20
21 class SettingsSyncProcessor;
22
23 // Decorates a ValueStore with sync behaviour.
24 class SyncableSettingsStorage : public ValueStore {
25 public:
26 SyncableSettingsStorage(
27 const scoped_refptr<SettingsObserverList>& observers,
28 const std::string& extension_id,
29 // Ownership taken.
30 ValueStore* delegate);
31
32 virtual ~SyncableSettingsStorage();
33
34 // ValueStore implementation.
35 virtual size_t GetBytesInUse(const std::string& key) OVERRIDE;
36 virtual size_t GetBytesInUse(const std::vector<std::string>& keys) OVERRIDE;
37 virtual size_t GetBytesInUse() OVERRIDE;
38 virtual ReadResult Get(const std::string& key) OVERRIDE;
39 virtual ReadResult Get(const std::vector<std::string>& keys) OVERRIDE;
40 virtual ReadResult Get() OVERRIDE;
41 virtual WriteResult Set(
42 WriteOptions options,
43 const std::string& key,
44 const Value& value) OVERRIDE;
45 virtual WriteResult Set(
46 WriteOptions options, const DictionaryValue& values) OVERRIDE;
47 virtual WriteResult Remove(const std::string& key) OVERRIDE;
48 virtual WriteResult Remove(const std::vector<std::string>& keys) OVERRIDE;
49 virtual WriteResult Clear() OVERRIDE;
50
51 // Sync-related methods, analogous to those on SyncableService (handled by
52 // ExtensionSettings), but with looser guarantees about when the methods
53 // can be called.
54
55 // Must only be called if sync isn't already active.
56 syncer::SyncError StartSyncing(
57 const DictionaryValue& sync_state,
58 scoped_ptr<SettingsSyncProcessor> sync_processor);
59
60 // May be called at any time (idempotent).
61 void StopSyncing();
62
63 // May be called at any time; changes will be ignored if sync isn't active.
64 syncer::SyncError ProcessSyncChanges(const SettingSyncDataList& sync_changes);
65
66 private:
67 // Sends the changes from |result| to sync if it's enabled.
68 void SyncResultIfEnabled(const ValueStore::WriteResult& result);
69
70 // Sends all local settings to sync (synced settings assumed to be empty).
71 syncer::SyncError SendLocalSettingsToSync(
72 const DictionaryValue& settings);
73
74 // Overwrites local state with sync state.
75 syncer::SyncError OverwriteLocalSettingsWithSync(
76 const DictionaryValue& sync_state, const DictionaryValue& settings);
77
78 // Called when an Add/Update/Remove comes from sync. Ownership of Value*s
79 // are taken.
80 syncer::SyncError OnSyncAdd(
81 const std::string& key,
82 Value* new_value,
83 ValueStoreChangeList* changes);
84 syncer::SyncError OnSyncUpdate(
85 const std::string& key,
86 Value* old_value,
87 Value* new_value,
88 ValueStoreChangeList* changes);
89 syncer::SyncError OnSyncDelete(
90 const std::string& key,
91 Value* old_value,
92 ValueStoreChangeList* changes);
93
94 // List of observers to settings changes.
95 const scoped_refptr<SettingsObserverList> observers_;
96
97 // Id of the extension these settings are for.
98 std::string const extension_id_;
99
100 // Storage area to sync.
101 const scoped_ptr<ValueStore> delegate_;
102
103 // Object which sends changes to sync.
104 scoped_ptr<SettingsSyncProcessor> sync_processor_;
105
106 DISALLOW_COPY_AND_ASSIGN(SyncableSettingsStorage);
107 };
108
109 } // namespace extensions
110
111 #endif // CHROME_BROWSER_EXTENSIONS_API_STORAGE_SYNCABLE_SETTINGS_STORAGE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698