OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_SYNC_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_SYNC_SERVICE_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SYNC_SERVICE_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SYNC_SERVICE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "chrome/browser/extensions/pending_enables.h" | |
12 #include "chrome/browser/extensions/sync_bundle.h" | 11 #include "chrome/browser/extensions/sync_bundle.h" |
13 #include "components/keyed_service/core/keyed_service.h" | 12 #include "components/keyed_service/core/keyed_service.h" |
14 #include "extensions/browser/extension_prefs.h" | 13 #include "extensions/browser/extension_prefs.h" |
15 #include "extensions/common/extension.h" | 14 #include "extensions/common/extension.h" |
16 #include "sync/api/syncable_service.h" | 15 #include "sync/api/syncable_service.h" |
17 | 16 |
17 class ExtensionService; | |
18 class Profile; | 18 class Profile; |
19 | 19 |
20 namespace extensions { | 20 namespace extensions { |
21 class Extension; | 21 class Extension; |
22 class ExtensionSet; | 22 class ExtensionSet; |
23 class ExtensionSyncData; | 23 class ExtensionSyncData; |
24 } // namespace extensions | 24 } // namespace extensions |
25 | 25 |
26 namespace syncer { | 26 namespace syncer { |
27 class SyncChange; | 27 class SyncChange; |
28 class SyncChangeProcessor; | 28 class SyncChangeProcessor; |
29 class SyncErrorFactory; | 29 class SyncErrorFactory; |
30 } | 30 } |
31 | 31 |
32 // SyncableService implementation responsible for the APPS and EXTENSIONS data | 32 // SyncableService implementation responsible for the APPS and EXTENSIONS data |
33 // types, i.e. "proper" apps/extensions (not themes). | 33 // types, i.e. "proper" apps/extensions (not themes). |
34 class ExtensionSyncService : public syncer::SyncableService, | 34 class ExtensionSyncService : public syncer::SyncableService, |
35 public KeyedService { | 35 public KeyedService { |
36 public: | 36 public: |
37 ExtensionSyncService(Profile* profile, | 37 ExtensionSyncService(Profile* profile, |
38 extensions::ExtensionPrefs* extension_prefs, | 38 extensions::ExtensionPrefs* extension_prefs, |
39 ExtensionService* extension_service); | 39 ExtensionService* extension_service); |
40 | 40 |
41 ~ExtensionSyncService() override; | 41 ~ExtensionSyncService() override; |
42 | 42 |
43 // Convenience function to get the ExtensionSyncService for a BrowserContext. | 43 // Convenience function to get the ExtensionSyncService for a BrowserContext. |
44 static ExtensionSyncService* Get(content::BrowserContext* context); | 44 static ExtensionSyncService* Get(content::BrowserContext* context); |
45 | 45 |
46 // Notifies Sync that the given |extension| has been uninstalled. | |
46 void SyncUninstallExtension(const extensions::Extension& extension); | 47 void SyncUninstallExtension(const extensions::Extension& extension); |
47 | 48 |
48 void SyncEnableExtension(const extensions::Extension& extension); | |
49 void SyncDisableExtension(const extensions::Extension& extension); | |
50 | |
51 void SyncOrderingChange(const std::string& extension_id); | 49 void SyncOrderingChange(const std::string& extension_id); |
52 | 50 |
53 // Notifies Sync (if needed) of a newly-installed extension or a change to | 51 // Notifies Sync (if needed) of a newly-installed extension or a change to |
54 // an existing extension. | 52 // an existing extension. |
55 void SyncExtensionChangeIfNeeded(const extensions::Extension& extension); | 53 void SyncExtensionChangeIfNeeded(const extensions::Extension& extension); |
56 | 54 |
57 // syncer::SyncableService implementation. | 55 // syncer::SyncableService implementation. |
58 syncer::SyncMergeResult MergeDataAndStartSyncing( | 56 syncer::SyncMergeResult MergeDataAndStartSyncing( |
59 syncer::ModelType type, | 57 syncer::ModelType type, |
60 const syncer::SyncDataList& initial_sync_data, | 58 const syncer::SyncDataList& initial_sync_data, |
61 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, | 59 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, |
62 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory) override; | 60 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory) override; |
63 void StopSyncing(syncer::ModelType type) override; | 61 void StopSyncing(syncer::ModelType type) override; |
64 syncer::SyncDataList GetAllSyncData(syncer::ModelType type) const override; | 62 syncer::SyncDataList GetAllSyncData(syncer::ModelType type) const override; |
65 syncer::SyncError ProcessSyncChanges( | 63 syncer::SyncError ProcessSyncChanges( |
66 const tracked_objects::Location& from_here, | 64 const tracked_objects::Location& from_here, |
67 const syncer::SyncChangeList& change_list) override; | 65 const syncer::SyncChangeList& change_list) override; |
68 | 66 |
69 // Creates the ExtensionSyncData for the given app/extension. | |
70 extensions::ExtensionSyncData CreateSyncData( | |
71 const extensions::Extension& extension) const; | |
72 | |
73 // Applies the change specified passed in by either ExtensionSyncData to the | 67 // Applies the change specified passed in by either ExtensionSyncData to the |
not at google - send to devlin
2015/07/16 18:25:47
This applies a change *from the sync server* right
Marc Treib
2015/07/17 10:24:06
Yes, "apply" = server -> local, "push" = local ->
| |
74 // current system. | 68 // current system. |
75 // Returns false if the changes were not completely applied and were added | 69 // Returns false if the changes were not completely applied and were added |
76 // to the pending list to be tried again. | 70 // to the pending list to be tried again. |
77 bool ApplySyncData(const extensions::ExtensionSyncData& extension_sync_data); | 71 bool ApplySyncData(const extensions::ExtensionSyncData& extension_sync_data); |
78 | 72 |
73 // Returns whether the extension with the given |extension_id| has local | |
74 // changes that need to be synced. This can only be true before sync has | |
75 // started, i.e. before MergeDataAndStartSyncing has been called. | |
76 bool ExtensionNeedsSync(const std::string& extension_id) const; | |
77 | |
79 // |flare| provides a StartSyncFlare to the SyncableService. See | 78 // |flare| provides a StartSyncFlare to the SyncableService. See |
80 // sync_start_util for more. Public for testing. | 79 // sync_start_util for more. Public for testing. |
81 void SetSyncStartFlare(const syncer::SyncableService::StartSyncFlare& flare); | 80 void SetSyncStartFlare(const syncer::SyncableService::StartSyncFlare& flare); |
82 | 81 |
83 private: | 82 private: |
84 // Whether the given extension has been enabled before sync has started. | |
85 bool IsPendingEnable(const std::string& extension_id) const; | |
86 | |
87 // Gets the SyncBundle for the given |type|. | 83 // Gets the SyncBundle for the given |type|. |
88 extensions::SyncBundle* GetSyncBundle(syncer::ModelType type); | 84 extensions::SyncBundle* GetSyncBundle(syncer::ModelType type); |
89 const extensions::SyncBundle* GetSyncBundle(syncer::ModelType type) const; | 85 const extensions::SyncBundle* GetSyncBundle(syncer::ModelType type) const; |
90 | 86 |
91 // Gets the PendingEnables for apps/extensions. | 87 // Creates the ExtensionSyncData for the given app/extension. |
92 extensions::PendingEnables* GetPendingEnables(bool for_apps); | 88 extensions::ExtensionSyncData CreateSyncData( |
89 const extensions::Extension& extension) const; | |
93 | 90 |
94 // Gets the ExtensionSyncData for all apps or extensions. | 91 // Collects the ExtensionSyncData for all installed apps or extensions. |
95 std::vector<extensions::ExtensionSyncData> GetSyncDataList( | 92 // If |only_with_needs_sync| is true, includes only extensions that have the |
96 syncer::ModelType type) const; | 93 // NeedsSync pref set, i.e. which have local changes that need to be pushed. |
94 std::vector<extensions::ExtensionSyncData> GetLocalSyncDataList( | |
95 syncer::ModelType type, bool only_with_needs_sync) const; | |
97 | 96 |
97 // Helper for GetLocalSyncDataList. | |
98 void FillSyncDataList( | 98 void FillSyncDataList( |
99 const extensions::ExtensionSet& extensions, | 99 const extensions::ExtensionSet& extensions, |
100 syncer::ModelType type, | 100 syncer::ModelType type, |
101 bool only_with_needs_sync, | |
101 std::vector<extensions::ExtensionSyncData>* sync_data_list) const; | 102 std::vector<extensions::ExtensionSyncData>* sync_data_list) const; |
102 | 103 |
103 // Handles applying the extension specific values in |extension_sync_data| to | 104 // Handles applying the extension specific values in |extension_sync_data| to |
104 // the current system. | 105 // the current system. |
105 // Returns false if the changes were not completely applied and need to be | 106 // Returns false if the changes were not completely applied and need to be |
106 // tried again later. | 107 // tried again later. |
107 bool ApplyExtensionSyncDataHelper( | 108 bool ApplyExtensionSyncDataHelper( |
108 const extensions::ExtensionSyncData& extension_sync_data, | 109 const extensions::ExtensionSyncData& extension_sync_data, |
109 syncer::ModelType type); | 110 syncer::ModelType type); |
110 | 111 |
111 // Processes the bookmark app specific parts of an AppSyncData. | 112 // Processes the bookmark app specific parts of an AppSyncData. |
112 void ApplyBookmarkAppSyncData( | 113 void ApplyBookmarkAppSyncData( |
113 const extensions::ExtensionSyncData& extension_sync_data); | 114 const extensions::ExtensionSyncData& extension_sync_data); |
114 | 115 |
115 // The normal profile associated with this ExtensionService. | 116 // The normal profile associated with this ExtensionService. |
116 Profile* profile_; | 117 Profile* profile_; |
117 | 118 |
118 // Preferences for the owning profile. | 119 // Preferences for the owning profile. |
119 extensions::ExtensionPrefs* extension_prefs_; | 120 extensions::ExtensionPrefs* extension_prefs_; |
120 | 121 |
121 ExtensionService* extension_service_; | 122 ExtensionService* extension_service_; |
122 | 123 |
123 extensions::SyncBundle app_sync_bundle_; | 124 extensions::SyncBundle app_sync_bundle_; |
124 extensions::SyncBundle extension_sync_bundle_; | 125 extensions::SyncBundle extension_sync_bundle_; |
125 | 126 |
126 // Set of extensions/apps that have been enabled before sync has started. | |
127 // TODO(treib,kalman): This seems wrong. Why are enables special, as opposed | |
128 // to disables, or any other changes? | |
129 extensions::PendingEnables pending_app_enables_; | |
130 extensions::PendingEnables pending_extension_enables_; | |
131 | |
132 // Run()ning tells sync to try and start soon, because syncable changes | 127 // Run()ning tells sync to try and start soon, because syncable changes |
133 // have started happening. It will cause sync to call us back | 128 // have started happening. It will cause sync to call us back |
134 // asynchronously via MergeDataAndStartSyncing as soon as possible. | 129 // asynchronously via MergeDataAndStartSyncing as soon as possible. |
135 syncer::SyncableService::StartSyncFlare flare_; | 130 syncer::SyncableService::StartSyncFlare flare_; |
136 | 131 |
137 DISALLOW_COPY_AND_ASSIGN(ExtensionSyncService); | 132 DISALLOW_COPY_AND_ASSIGN(ExtensionSyncService); |
138 }; | 133 }; |
139 | 134 |
140 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SYNC_SERVICE_H_ | 135 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SYNC_SERVICE_H_ |
OLD | NEW |