| 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_UI_APP_LIST_APP_LIST_SYNCABLE_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_UI_APP_LIST_APP_LIST_SYNCABLE_SERVICE_H_ |
| 6 #define CHROME_BROWSER_UI_APP_LIST_APP_LIST_SYNCABLE_SERVICE_H_ | 6 #define CHROME_BROWSER_UI_APP_LIST_APP_LIST_SYNCABLE_SERVICE_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| 11 #include <memory> | 11 #include <memory> |
| 12 | 12 |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/weak_ptr.h" |
| 14 #include "base/observer_list.h" | 15 #include "base/observer_list.h" |
| 15 #include "build/build_config.h" | 16 #include "build/build_config.h" |
| 16 #include "chrome/browser/apps/drive/drive_app_uninstall_sync_service.h" | 17 #include "chrome/browser/apps/drive/drive_app_uninstall_sync_service.h" |
| 17 #include "chrome/browser/sync/glue/sync_start_util.h" | 18 #include "chrome/browser/sync/glue/sync_start_util.h" |
| 18 #include "components/keyed_service/core/keyed_service.h" | 19 #include "components/keyed_service/core/keyed_service.h" |
| 19 #include "components/sync/model/string_ordinal.h" | 20 #include "components/sync/model/string_ordinal.h" |
| 20 #include "components/sync/model/sync_change.h" | 21 #include "components/sync/model/sync_change.h" |
| 21 #include "components/sync/model/sync_change_processor.h" | 22 #include "components/sync/model/sync_change_processor.h" |
| 22 #include "components/sync/model/sync_error_factory.h" | 23 #include "components/sync/model/sync_error_factory.h" |
| 23 #include "components/sync/model/syncable_service.h" | 24 #include "components/sync/model/syncable_service.h" |
| 24 #include "components/sync/protocol/app_list_specifics.pb.h" | 25 #include "components/sync/protocol/app_list_specifics.pb.h" |
| 25 | 26 |
| 26 #if defined(OS_CHROMEOS) | 27 #if defined(OS_CHROMEOS) |
| 27 class ArcAppModelBuilder; | 28 class ArcAppModelBuilder; |
| 28 #endif | 29 #endif |
| 29 | 30 |
| 30 class DriveAppProvider; | 31 class DriveAppProvider; |
| 31 class ExtensionAppModelBuilder; | 32 class ExtensionAppModelBuilder; |
| 32 class Profile; | 33 class Profile; |
| 33 | 34 |
| 34 namespace extensions { | 35 namespace extensions { |
| 35 class ExtensionSystem; | 36 class ExtensionSystem; |
| 36 } | 37 } |
| 37 | 38 |
| 38 namespace sync_pb { | 39 namespace sync_pb { |
| 39 class AppListSpecifics; | 40 class AppListSpecifics; |
| 40 } | 41 } |
| 41 | 42 |
| 43 namespace user_prefs { |
| 44 class PrefRegistrySyncable; |
| 45 } |
| 46 |
| 42 namespace app_list { | 47 namespace app_list { |
| 43 | 48 |
| 44 class AppListFolderItem; | 49 class AppListFolderItem; |
| 45 class AppListItem; | 50 class AppListItem; |
| 46 class AppListModel; | 51 class AppListModel; |
| 47 | 52 |
| 48 // Keyed Service that owns, stores, and syncs an AppListModel for a profile. | 53 // Keyed Service that owns, stores, and syncs an AppListModel for a profile. |
| 49 class AppListSyncableService : public syncer::SyncableService, | 54 class AppListSyncableService : public syncer::SyncableService, |
| 50 public KeyedService, | 55 public KeyedService, |
| 51 public DriveAppUninstallSyncService { | 56 public DriveAppUninstallSyncService { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 74 }; | 79 }; |
| 75 | 80 |
| 76 using SyncItemMap = std::map<std::string, std::unique_ptr<SyncItem>>; | 81 using SyncItemMap = std::map<std::string, std::unique_ptr<SyncItem>>; |
| 77 | 82 |
| 78 // Populates the model when |extension_system| is ready. | 83 // Populates the model when |extension_system| is ready. |
| 79 AppListSyncableService(Profile* profile, | 84 AppListSyncableService(Profile* profile, |
| 80 extensions::ExtensionSystem* extension_system); | 85 extensions::ExtensionSystem* extension_system); |
| 81 | 86 |
| 82 ~AppListSyncableService() override; | 87 ~AppListSyncableService() override; |
| 83 | 88 |
| 89 // Registers prefs to support local storage. |
| 90 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
| 91 |
| 84 // Adds |item| to |sync_items_| and |model_|. If a sync item already exists, | 92 // Adds |item| to |sync_items_| and |model_|. If a sync item already exists, |
| 85 // updates the existing sync item instead. | 93 // updates the existing sync item instead. |
| 86 void AddItem(std::unique_ptr<AppListItem> app_item); | 94 void AddItem(std::unique_ptr<AppListItem> app_item); |
| 87 | 95 |
| 88 // Removes sync item matching |id|. | 96 // Removes sync item matching |id|. |
| 89 void RemoveItem(const std::string& id); | 97 void RemoveItem(const std::string& id); |
| 90 | 98 |
| 91 // Removes sync item matching |id| after item uninstall. | 99 // Removes sync item matching |id| after item uninstall. |
| 92 void RemoveUninstalledItem(const std::string& id); | 100 void RemoveUninstalledItem(const std::string& id); |
| 93 | 101 |
| 94 // Called when properties of an item may have changed, e.g. default/oem state. | 102 // Called when properties of an item may have changed, e.g. default/oem state. |
| 95 void UpdateItem(AppListItem* app_item); | 103 void UpdateItem(AppListItem* app_item); |
| 96 | 104 |
| 97 // Returns the existing sync item matching |id| or NULL. | 105 // Returns the existing sync item matching |id| or NULL. |
| 98 const SyncItem* GetSyncItem(const std::string& id) const; | 106 const SyncItem* GetSyncItem(const std::string& id) const; |
| 99 | 107 |
| 100 // Sets the name of the folder for OEM apps. | 108 // Sets the name of the folder for OEM apps. |
| 101 void SetOemFolderName(const std::string& name); | 109 void SetOemFolderName(const std::string& name); |
| 102 | 110 |
| 103 // Returns optional pin position for the app specified by |app_id|. If app is | 111 // Returns optional pin position for the app specified by |app_id|. If app is |
| 104 // not synced or does not have associated pin position then empty ordinal is | 112 // not synced or does not have associated pin position then empty ordinal is |
| 105 // returned. | 113 // returned. |
| 106 syncer::StringOrdinal GetPinPosition(const std::string& app_id); | 114 syncer::StringOrdinal GetPinPosition(const std::string& app_id); |
| 107 | 115 |
| 108 // Sets pin position and how it is pinned for the app specified by |app_id|. | 116 // Sets pin position and how it is pinned for the app specified by |app_id|. |
| 109 // Empty |item_pin_ordinal| indicates that the app has no pin. | 117 // Empty |item_pin_ordinal| indicates that the app has no pin. |
| 110 void SetPinPosition(const std::string& app_id, | 118 void SetPinPosition(const std::string& app_id, |
| 111 const syncer::StringOrdinal& item_pin_ordinal); | 119 const syncer::StringOrdinal& item_pin_ordinal); |
| 112 | 120 |
| 113 // Gets the app list model, building it if it doesn't yet exist. | 121 // Gets the app list model. |
| 114 AppListModel* GetModel(); | 122 AppListModel* GetModel(); |
| 115 | 123 |
| 124 // Returns true if this service was initialized. |
| 125 bool IsInitialized() const; |
| 126 |
| 116 // Registers new observers and makes sure that service is started. | 127 // Registers new observers and makes sure that service is started. |
| 117 void AddObserverAndStart(Observer* observer); | 128 void AddObserverAndStart(Observer* observer); |
| 118 void RemoveObserver(Observer* observer); | 129 void RemoveObserver(Observer* observer); |
| 119 | 130 |
| 120 Profile* profile() { return profile_; } | 131 Profile* profile() { return profile_; } |
| 121 size_t GetNumSyncItemsForTest(); | 132 size_t GetNumSyncItemsForTest(); |
| 122 const std::string& GetOemFolderNameForTest() const { | 133 const std::string& GetOemFolderNameForTest() const { |
| 123 return oem_folder_name_; | 134 return oem_folder_name_; |
| 124 } | 135 } |
| 125 void ResetDriveAppProviderForTest(); | 136 void ResetDriveAppProviderForTest(); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 std::string FindOrCreateOemFolder(); | 233 std::string FindOrCreateOemFolder(); |
| 223 | 234 |
| 224 // Gets the location for the OEM folder. Called when the folder is first | 235 // Gets the location for the OEM folder. Called when the folder is first |
| 225 // created. | 236 // created. |
| 226 syncer::StringOrdinal GetOemFolderPos(); | 237 syncer::StringOrdinal GetOemFolderPos(); |
| 227 | 238 |
| 228 // Returns true if an extension matching |id| exists and was installed by | 239 // Returns true if an extension matching |id| exists and was installed by |
| 229 // an OEM (extension->was_installed_by_oem() is true). | 240 // an OEM (extension->was_installed_by_oem() is true). |
| 230 bool AppIsOem(const std::string& id); | 241 bool AppIsOem(const std::string& id); |
| 231 | 242 |
| 243 // Initializes sync items from the local storage while sync service is not |
| 244 // enabled. |
| 245 void InitFromLocalStorage(); |
| 246 |
| 232 // Helper that notifies observers that sync model has been updated. | 247 // Helper that notifies observers that sync model has been updated. |
| 233 void NotifyObserversSyncUpdated(); | 248 void NotifyObserversSyncUpdated(); |
| 234 | 249 |
| 250 // Handles model update start/finish. |
| 251 void HandleUpdateStarted(); |
| 252 void HandleUpdateFinished(); |
| 253 |
| 254 // Returns true if extension service is ready. |
| 255 bool IsExtensionServiceReady() const; |
| 256 |
| 235 Profile* profile_; | 257 Profile* profile_; |
| 236 extensions::ExtensionSystem* extension_system_; | 258 extensions::ExtensionSystem* extension_system_; |
| 237 std::unique_ptr<AppListModel> model_; | 259 std::unique_ptr<AppListModel> model_; |
| 238 std::unique_ptr<ModelObserver> model_observer_; | 260 std::unique_ptr<ModelObserver> model_observer_; |
| 239 std::unique_ptr<ExtensionAppModelBuilder> apps_builder_; | 261 std::unique_ptr<ExtensionAppModelBuilder> apps_builder_; |
| 240 #if defined(OS_CHROMEOS) | 262 #if defined(OS_CHROMEOS) |
| 241 std::unique_ptr<ArcAppModelBuilder> arc_apps_builder_; | 263 std::unique_ptr<ArcAppModelBuilder> arc_apps_builder_; |
| 242 #endif | 264 #endif |
| 243 std::unique_ptr<syncer::SyncChangeProcessor> sync_processor_; | 265 std::unique_ptr<syncer::SyncChangeProcessor> sync_processor_; |
| 244 std::unique_ptr<syncer::SyncErrorFactory> sync_error_handler_; | 266 std::unique_ptr<syncer::SyncErrorFactory> sync_error_handler_; |
| 245 SyncItemMap sync_items_; | 267 SyncItemMap sync_items_; |
| 246 syncer::SyncableService::StartSyncFlare flare_; | 268 syncer::SyncableService::StartSyncFlare flare_; |
| 247 bool initial_sync_data_processed_; | 269 bool initial_sync_data_processed_; |
| 248 bool first_app_list_sync_; | 270 bool first_app_list_sync_; |
| 249 std::string oem_folder_name_; | 271 std::string oem_folder_name_; |
| 250 | 272 |
| 251 // List of observers. | 273 // List of observers. |
| 252 base::ObserverList<Observer> observer_list_; | 274 base::ObserverList<Observer> observer_list_; |
| 253 | 275 |
| 254 // Provides integration with Drive apps. | 276 // Provides integration with Drive apps. |
| 255 std::unique_ptr<DriveAppProvider> drive_app_provider_; | 277 std::unique_ptr<DriveAppProvider> drive_app_provider_; |
| 256 | 278 |
| 279 base::WeakPtrFactory<AppListSyncableService> weak_ptr_factory_; |
| 280 |
| 257 DISALLOW_COPY_AND_ASSIGN(AppListSyncableService); | 281 DISALLOW_COPY_AND_ASSIGN(AppListSyncableService); |
| 258 }; | 282 }; |
| 259 | 283 |
| 260 } // namespace app_list | 284 } // namespace app_list |
| 261 | 285 |
| 262 #endif // CHROME_BROWSER_UI_APP_LIST_APP_LIST_SYNCABLE_SERVICE_H_ | 286 #endif // CHROME_BROWSER_UI_APP_LIST_APP_LIST_SYNCABLE_SERVICE_H_ |
| OLD | NEW |