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

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

Issue 175853002: Revert of Add a Restore() method to ValueStore and make StorageAPI use it (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 10 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
OLDNEW
(Empty)
1 // Copyright 2014 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_SYNC_STORAGE_BACKEND_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_STORAGE_SYNC_STORAGE_BACKEND_H_
7
8 #include <map>
9 #include <set>
10 #include <string>
11
12 #include "base/compiler_specific.h"
13 #include "base/files/file_path.h"
14 #include "base/memory/linked_ptr.h"
15 #include "base/memory/ref_counted.h"
16 #include "base/memory/scoped_ptr.h"
17 #include "chrome/browser/extensions/api/storage/settings_backend.h"
18 #include "chrome/browser/extensions/api/storage/settings_observer.h"
19 #include "chrome/browser/extensions/api/storage/settings_storage_factory.h"
20 #include "chrome/browser/extensions/api/storage/settings_storage_quota_enforcer. h"
21 #include "sync/api/syncable_service.h"
22
23 namespace syncer {
24 class SyncErrorFactory;
25 }
26
27 namespace extensions {
28
29 class SettingsSyncProcessor;
30 class SyncableSettingsStorage;
31
32 // Manages ValueStore objects for extensions, including routing
33 // changes from sync to them.
34 // Lives entirely on the FILE thread.
35 class SyncStorageBackend : public SettingsBackend,
36 public syncer::SyncableService {
37 public:
38 // |storage_factory| is use to create leveldb storage areas.
39 // |base_path| is the base of the extension settings directory, so the
40 // databases will be at base_path/extension_id.
41 // |observers| is the list of observers to settings changes.
42 SyncStorageBackend(
43 const scoped_refptr<SettingsStorageFactory>& storage_factory,
44 const base::FilePath& base_path,
45 const SettingsStorageQuotaEnforcer::Limits& quota,
46 const scoped_refptr<SettingsObserverList>& observers,
47 syncer::ModelType sync_type,
48 const syncer::SyncableService::StartSyncFlare& flare);
49
50 virtual ~SyncStorageBackend();
51
52 // SettingsBackend implementation.
53 virtual ValueStore* GetStorage(const std::string& extension_id) OVERRIDE;
54 virtual void DeleteStorage(const std::string& extension_id) OVERRIDE;
55 virtual syncer::SyncableService* GetAsSyncableService() OVERRIDE;
56
57 // syncer::SyncableService implementation.
58 virtual syncer::SyncDataList GetAllSyncData(syncer::ModelType type)
59 const OVERRIDE;
60 virtual syncer::SyncMergeResult MergeDataAndStartSyncing(
61 syncer::ModelType type,
62 const syncer::SyncDataList& initial_sync_data,
63 scoped_ptr<syncer::SyncChangeProcessor> sync_processor,
64 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory) OVERRIDE;
65 virtual syncer::SyncError ProcessSyncChanges(
66 const tracked_objects::Location& from_here,
67 const syncer::SyncChangeList& change_list) OVERRIDE;
68 virtual void StopSyncing(syncer::ModelType type) OVERRIDE;
69
70 private:
71 // Gets a weak reference to the storage area for a given extension,
72 // initializing sync with some initial data if sync enabled.
73 SyncableSettingsStorage* GetOrCreateStorageWithSyncData(
74 const std::string& extension_id,
75 const base::DictionaryValue& sync_data) const;
76
77 // Gets all extension IDs known to extension settings. This may not be all
78 // installed extensions.
79 std::set<std::string> GetKnownExtensionIDs() const;
80
81 // Creates a new SettingsSyncProcessor for an extension.
82 scoped_ptr<SettingsSyncProcessor> CreateSettingsSyncProcessor(
83 const std::string& extension_id) const;
84
85 // The list of observers to settings changes.
86 const scoped_refptr<SettingsObserverList> observers_;
87
88 // A cache of ValueStore objects that have already been created.
89 // Ensure that there is only ever one created per extension.
90 typedef std::map<std::string, linked_ptr<SyncableSettingsStorage> >
91 StorageObjMap;
92 mutable StorageObjMap storage_objs_;
93
94 // Current sync model type. Either EXTENSION_SETTINGS or APP_SETTINGS.
95 syncer::ModelType sync_type_;
96
97 // Current sync processor, if any.
98 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_;
99
100 // Current sync error handler if any.
101 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory_;
102
103 syncer::SyncableService::StartSyncFlare flare_;
104
105 DISALLOW_COPY_AND_ASSIGN(SyncStorageBackend);
106 };
107
108 } // namespace extensions
109
110 #endif // CHROME_BROWSER_EXTENSIONS_API_STORAGE_SYNC_STORAGE_BACKEND_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698