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 | |
74 // current system. | |
75 // Returns false if the changes were not completely applied and were added | |
76 // to the pending list to be tried again. | |
77 bool ApplySyncData(const extensions::ExtensionSyncData& extension_sync_data); | |
78 | |
79 // |flare| provides a StartSyncFlare to the SyncableService. See | 67 // |flare| provides a StartSyncFlare to the SyncableService. See |
80 // sync_start_util for more. Public for testing. | 68 // sync_start_util for more. Public for testing. |
81 void SetSyncStartFlare(const syncer::SyncableService::StartSyncFlare& flare); | 69 void SetSyncStartFlare(const syncer::SyncableService::StartSyncFlare& flare); |
82 | 70 |
83 private: | 71 private: |
84 // Whether the given extension has been enabled before sync has started. | 72 FRIEND_TEST_ALL_PREFIXES(TwoClientAppsSyncTest, UnexpectedLaunchType); |
85 bool IsPendingEnable(const std::string& extension_id) const; | 73 FRIEND_TEST_ALL_PREFIXES(ExtensionDisabledGlobalErrorTest, |
| 74 HigherPermissionsFromSync); |
| 75 FRIEND_TEST_ALL_PREFIXES(ExtensionDisabledGlobalErrorTest, RemoteInstall); |
| 76 friend class EphemeralAppBrowserTest; |
86 | 77 |
87 // Gets the SyncBundle for the given |type|. | 78 // Gets the SyncBundle for the given |type|. |
88 extensions::SyncBundle* GetSyncBundle(syncer::ModelType type); | 79 extensions::SyncBundle* GetSyncBundle(syncer::ModelType type); |
89 const extensions::SyncBundle* GetSyncBundle(syncer::ModelType type) const; | 80 const extensions::SyncBundle* GetSyncBundle(syncer::ModelType type) const; |
90 | 81 |
91 // Gets the PendingEnables for apps/extensions. | 82 // Creates the ExtensionSyncData for the given app/extension. |
92 extensions::PendingEnables* GetPendingEnables(bool for_apps); | 83 extensions::ExtensionSyncData CreateSyncData( |
| 84 const extensions::Extension& extension) const; |
93 | 85 |
94 // Gets the ExtensionSyncData for all apps or extensions. | 86 // Applies the given change coming in from the server to the local state. |
95 std::vector<extensions::ExtensionSyncData> GetSyncDataList( | 87 // Returns false if the changes were not completely applied and were added |
96 syncer::ModelType type) const; | 88 // to the pending list. |
| 89 bool ApplySyncData(const extensions::ExtensionSyncData& extension_sync_data); |
97 | 90 |
| 91 // Collects the ExtensionSyncData for all installed apps or extensions. |
| 92 // If |include_everything| is true, includes all installed extensions, |
| 93 // otherwise only those that have the NeedsSync pref set, i.e. which have |
| 94 // local changes that need to be pushed. |
| 95 std::vector<extensions::ExtensionSyncData> GetLocalSyncDataList( |
| 96 syncer::ModelType type, bool include_everything) const; |
| 97 |
| 98 // Helper for GetLocalSyncDataList. |
98 void FillSyncDataList( | 99 void FillSyncDataList( |
99 const extensions::ExtensionSet& extensions, | 100 const extensions::ExtensionSet& extensions, |
100 syncer::ModelType type, | 101 syncer::ModelType type, |
| 102 bool include_everything, |
101 std::vector<extensions::ExtensionSyncData>* sync_data_list) const; | 103 std::vector<extensions::ExtensionSyncData>* sync_data_list) const; |
102 | 104 |
103 // Handles applying the extension specific values in |extension_sync_data| to | 105 // Handles applying the extension specific values in |extension_sync_data| to |
104 // the current system. | 106 // the local state. |
105 // Returns false if the changes were not completely applied and need to be | 107 // Returns false if the changes were not completely applied. |
106 // 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 |