Cleanup ExtensionSyncService and SyncBundle.
[chromium-blink-merge.git] / chrome / browser / extensions / extension_sync_service.h
blob270aad1e7b12d897d895cbdb6d22f42d60fbdff5
1 // Copyright 2013 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.
5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_SYNC_SERVICE_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SYNC_SERVICE_H_
8 #include <string>
9 #include <vector>
11 #include "chrome/browser/extensions/pending_enables.h"
12 #include "chrome/browser/extensions/sync_bundle.h"
13 #include "components/keyed_service/core/keyed_service.h"
14 #include "extensions/browser/extension_prefs.h"
15 #include "extensions/common/extension.h"
16 #include "sync/api/syncable_service.h"
18 class Profile;
20 namespace extensions {
21 class Extension;
22 class ExtensionSet;
23 class ExtensionSyncData;
24 } // namespace extensions
26 namespace syncer {
27 class SyncChange;
28 class SyncChangeProcessor;
29 class SyncErrorFactory;
32 class ExtensionSyncService : public syncer::SyncableService,
33 public KeyedService {
34 public:
35 ExtensionSyncService(Profile* profile,
36 extensions::ExtensionPrefs* extension_prefs,
37 ExtensionService* extension_service);
39 ~ExtensionSyncService() override;
41 // Convenience function to get the ExtensionSyncService for a BrowserContext.
42 static ExtensionSyncService* Get(content::BrowserContext* context);
44 // Extracts the data needed to sync the uninstall of |extension|, but doesn't
45 // actually sync anything now. Call |ProcessSyncUninstallExtension| later with
46 // the returned SyncData to actually commit the change.
47 syncer::SyncData PrepareToSyncUninstallExtension(
48 const extensions::Extension& extension);
49 // Commit a sync uninstall that was previously prepared with
50 // PrepareToSyncUninstallExtension.
51 void ProcessSyncUninstallExtension(const std::string& extension_id,
52 const syncer::SyncData& sync_data);
54 void SyncEnableExtension(const extensions::Extension& extension);
55 void SyncDisableExtension(const extensions::Extension& extension);
57 void SyncOrderingChange(const std::string& extension_id);
59 // Notifies Sync (if needed) of a newly-installed extension or a change to
60 // an existing extension.
61 void SyncExtensionChangeIfNeeded(const extensions::Extension& extension);
63 // syncer::SyncableService implementation.
64 syncer::SyncMergeResult MergeDataAndStartSyncing(
65 syncer::ModelType type,
66 const syncer::SyncDataList& initial_sync_data,
67 scoped_ptr<syncer::SyncChangeProcessor> sync_processor,
68 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory) override;
69 void StopSyncing(syncer::ModelType type) override;
70 syncer::SyncDataList GetAllSyncData(syncer::ModelType type) const override;
71 syncer::SyncError ProcessSyncChanges(
72 const tracked_objects::Location& from_here,
73 const syncer::SyncChangeList& change_list) override;
75 // Creates the ExtensionSyncData for the given app/extension.
76 extensions::ExtensionSyncData CreateSyncData(
77 const extensions::Extension& extension) const;
79 // Applies the change specified passed in by either ExtensionSyncData to the
80 // current system.
81 // Returns false if the changes were not completely applied and were added
82 // to the pending list to be tried again.
83 bool ApplySyncData(const extensions::ExtensionSyncData& extension_sync_data);
85 // |flare| provides a StartSyncFlare to the SyncableService. See
86 // sync_start_util for more. Public for testing.
87 void SetSyncStartFlare(const syncer::SyncableService::StartSyncFlare& flare);
89 private:
90 // Whether the given extension has been enabled before sync has started.
91 bool IsPendingEnable(const std::string& extension_id) const;
93 // Gets the SyncBundle for the given |type|.
94 extensions::SyncBundle* GetSyncBundle(syncer::ModelType type);
95 const extensions::SyncBundle* GetSyncBundle(syncer::ModelType type) const;
97 // Gets the ExtensionSyncData for all apps or extensions.
98 std::vector<extensions::ExtensionSyncData> GetSyncDataList(
99 syncer::ModelType type) const;
101 void FillSyncDataList(
102 const extensions::ExtensionSet& extensions,
103 syncer::ModelType type,
104 std::vector<extensions::ExtensionSyncData>* sync_data_list) const;
106 // Handles applying the extension specific values in |extension_sync_data| to
107 // the current system.
108 // Returns false if the changes were not completely applied and need to be
109 // tried again later.
110 bool ApplyExtensionSyncDataHelper(
111 const extensions::ExtensionSyncData& extension_sync_data,
112 syncer::ModelType type);
114 // Processes the bookmark app specific parts of an AppSyncData.
115 void ApplyBookmarkAppSyncData(
116 const extensions::ExtensionSyncData& extension_sync_data);
118 // The normal profile associated with this ExtensionService.
119 Profile* profile_;
121 // Preferences for the owning profile.
122 extensions::ExtensionPrefs* extension_prefs_;
124 ExtensionService* extension_service_;
126 extensions::SyncBundle app_sync_bundle_;
127 extensions::SyncBundle extension_sync_bundle_;
129 // Set of extensions/apps that have been enabled before sync has started.
130 // TODO(treib,kalman): This seems wrong. Why are enables special, as opposed
131 // to disables, or any other changes?
132 extensions::PendingEnables pending_app_enables_;
133 extensions::PendingEnables pending_extension_enables_;
135 // Run()ning tells sync to try and start soon, because syncable changes
136 // have started happening. It will cause sync to call us back
137 // asynchronously via MergeDataAndStartSyncing as soon as possible.
138 syncer::SyncableService::StartSyncFlare flare_;
140 DISALLOW_COPY_AND_ASSIGN(ExtensionSyncService);
143 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SYNC_SERVICE_H_