MacViews: Get c/b/ui/views/tabs to build on Mac
[chromium-blink-merge.git] / chrome / browser / extensions / extension_sync_service.h
blob0b359d7c9eff88a5ec0f871735d91d1406241ab5
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 "base/compiler_specific.h"
12 #include "chrome/browser/extensions/app_sync_bundle.h"
13 #include "chrome/browser/extensions/extension_sync_bundle.h"
14 #include "chrome/browser/extensions/pending_enables.h"
15 #include "components/keyed_service/core/keyed_service.h"
16 #include "extensions/browser/extension_prefs.h"
17 #include "extensions/common/extension.h"
18 #include "sync/api/string_ordinal.h"
19 #include "sync/api/sync_change.h"
20 #include "sync/api/syncable_service.h"
22 class ExtensionSyncData;
23 class Profile;
25 namespace base {
26 class SequencedTaskRunner;
29 namespace extensions {
30 class AppSyncData;
31 class ExtensionPrefs;
32 class ExtensionSyncData;
33 } // namespace extensions
35 namespace syncer {
36 class SyncErrorFactory;
39 class ExtensionSyncService : public syncer::SyncableService,
40 public KeyedService {
41 public:
42 ExtensionSyncService(Profile* profile,
43 extensions::ExtensionPrefs* extension_prefs,
44 ExtensionService* extension_service);
46 ~ExtensionSyncService() override;
48 // Convenience function to get the ExtensionSyncService for a Profile.
49 static ExtensionSyncService* Get(Profile* profile);
51 const extensions::ExtensionPrefs& extension_prefs() const {
52 return *extension_prefs_;
55 // Notifies Sync (if needed) of a newly-installed extension or a change to
56 // an existing extension.
57 virtual void SyncExtensionChangeIfNeeded(
58 const extensions::Extension& extension);
60 // syncer::SyncableService implementation.
61 syncer::SyncMergeResult MergeDataAndStartSyncing(
62 syncer::ModelType type,
63 const syncer::SyncDataList& initial_sync_data,
64 scoped_ptr<syncer::SyncChangeProcessor> sync_processor,
65 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory) override;
66 void StopSyncing(syncer::ModelType type) override;
67 syncer::SyncDataList GetAllSyncData(syncer::ModelType type) const override;
68 syncer::SyncError ProcessSyncChanges(
69 const tracked_objects::Location& from_here,
70 const syncer::SyncChangeList& change_list) override;
72 // Gets the sync data for the given extension, assuming that the extension is
73 // syncable.
74 extensions::ExtensionSyncData GetExtensionSyncData(
75 const extensions::Extension& extension) const;
77 // Gets the sync data for the given app, assuming that the app is
78 // syncable.
79 extensions::AppSyncData GetAppSyncData(
80 const extensions::Extension& extension) const;
82 // Gets the ExtensionSyncData for all extensions.
83 std::vector<extensions::ExtensionSyncData> GetExtensionSyncDataList() const;
85 // Gets the AppSyncData for all extensions.
86 std::vector<extensions::AppSyncData> GetAppSyncDataList() const;
88 // Applies the change specified passed in by either ExtensionSyncData or
89 // AppSyncData to the current system.
90 // Returns false if the changes were not completely applied and were added
91 // to the pending list to be tried again.
92 bool ProcessExtensionSyncData(
93 const extensions::ExtensionSyncData& extension_sync_data);
94 bool ProcessAppSyncData(const extensions::AppSyncData& app_sync_data);
96 // Processes the bookmark app specific parts of an AppSyncData.
97 void ProcessBookmarkAppSyncData(const extensions::AppSyncData& app_sync_data);
99 syncer::SyncChange PrepareToSyncUninstallExtension(
100 const extensions::Extension* extension,
101 bool extensions_ready);
102 void ProcessSyncUninstallExtension(const std::string& extension_id,
103 const syncer::SyncChange& sync_change);
105 void SyncEnableExtension(const extensions::Extension& extension);
106 void SyncDisableExtension(const extensions::Extension& extension);
108 void SyncOrderingChange(const std::string& extension_id);
110 // |flare| provides a StartSyncFlare to the SyncableService. See
111 // sync_start_util for more.
112 void SetSyncStartFlare(const syncer::SyncableService::StartSyncFlare& flare);
114 Profile* profile() { return profile_; }
116 private:
117 // Return true if the sync type of |extension| matches |type|.
118 bool IsCorrectSyncType(const extensions::Extension& extension,
119 syncer::ModelType type)
120 const;
122 // Whether the given extension has been enabled before sync has started.
123 bool IsPendingEnable(const std::string& extension_id) const;
125 // Handles setting the extension specific values in |extension_sync_data| to
126 // the current system.
127 // Returns false if the changes were not completely applied and need to be
128 // tried again later.
129 bool ProcessExtensionSyncDataHelper(
130 const extensions::ExtensionSyncData& extension_sync_data,
131 syncer::ModelType type);
133 // The normal profile associated with this ExtensionService.
134 Profile* profile_;
136 // Preferences for the owning profile.
137 extensions::ExtensionPrefs* extension_prefs_;
139 ExtensionService* extension_service_;
141 extensions::AppSyncBundle app_sync_bundle_;
142 extensions::ExtensionSyncBundle extension_sync_bundle_;
144 // Set of extensions/apps that have been enabled before sync has started.
145 extensions::PendingEnables pending_app_enables_;
146 extensions::PendingEnables pending_extension_enables_;
148 // Sequenced task runner for extension related file operations.
149 scoped_refptr<base::SequencedTaskRunner> file_task_runner_;
151 // Run()ning tells sync to try and start soon, because syncable changes
152 // have started happening. It will cause sync to call us back
153 // asynchronously via MergeDataAndStartSyncing as soon as possible.
154 syncer::SyncableService::StartSyncFlare flare_;
156 DISALLOW_COPY_AND_ASSIGN(ExtensionSyncService);
159 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SYNC_SERVICE_H_