Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1455)

Side by Side Diff: chrome/browser/ui/app_list/app_list_syncable_service.h

Issue 2055553004: arc: Support pinned apps across Arc-enabled and Arc-disabled platforms. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: chrome_mash_shelf_controller.cc update due namespace renaming Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/observer_list.h"
14 #include "build/build_config.h" 15 #include "build/build_config.h"
15 #include "chrome/browser/apps/drive/drive_app_uninstall_sync_service.h" 16 #include "chrome/browser/apps/drive/drive_app_uninstall_sync_service.h"
16 #include "chrome/browser/sync/glue/sync_start_util.h" 17 #include "chrome/browser/sync/glue/sync_start_util.h"
17 #include "components/keyed_service/core/keyed_service.h" 18 #include "components/keyed_service/core/keyed_service.h"
18 #include "sync/api/string_ordinal.h" 19 #include "sync/api/string_ordinal.h"
19 #include "sync/api/sync_change.h" 20 #include "sync/api/sync_change.h"
20 #include "sync/api/sync_change_processor.h" 21 #include "sync/api/sync_change_processor.h"
21 #include "sync/api/sync_error_factory.h" 22 #include "sync/api/sync_error_factory.h"
22 #include "sync/api/syncable_service.h" 23 #include "sync/api/syncable_service.h"
23 #include "sync/protocol/app_list_specifics.pb.h" 24 #include "sync/protocol/app_list_specifics.pb.h"
(...skipping 28 matching lines...) Expand all
52 public: 53 public:
53 struct SyncItem { 54 struct SyncItem {
54 SyncItem(const std::string& id, 55 SyncItem(const std::string& id,
55 sync_pb::AppListSpecifics::AppListItemType type); 56 sync_pb::AppListSpecifics::AppListItemType type);
56 ~SyncItem(); 57 ~SyncItem();
57 const std::string item_id; 58 const std::string item_id;
58 sync_pb::AppListSpecifics::AppListItemType item_type; 59 sync_pb::AppListSpecifics::AppListItemType item_type;
59 std::string item_name; 60 std::string item_name;
60 std::string parent_id; 61 std::string parent_id;
61 syncer::StringOrdinal item_ordinal; 62 syncer::StringOrdinal item_ordinal;
63 syncer::StringOrdinal item_pin_ordinal;
62 64
63 std::string ToString() const; 65 std::string ToString() const;
64 }; 66 };
65 67
68 class Observer {
69 public:
70 // Notifies that sync model was updated.
71 virtual void OnSyncModelUpdated() = 0;
72
73 protected:
74 virtual ~Observer() = default;
75 };
76
77 using SyncItemMap = std::map<std::string, SyncItem*>;
78
66 // Populates the model when |extension_system| is ready. 79 // Populates the model when |extension_system| is ready.
67 AppListSyncableService(Profile* profile, 80 AppListSyncableService(Profile* profile,
68 extensions::ExtensionSystem* extension_system); 81 extensions::ExtensionSystem* extension_system);
69 82
70 ~AppListSyncableService() override; 83 ~AppListSyncableService() override;
71 84
72 // Adds |item| to |sync_items_| and |model_|. If a sync item already exists, 85 // Adds |item| to |sync_items_| and |model_|. If a sync item already exists,
73 // updates the existing sync item instead. 86 // updates the existing sync item instead.
74 void AddItem(std::unique_ptr<AppListItem> app_item); 87 void AddItem(std::unique_ptr<AppListItem> app_item);
75 88
76 // Removes sync item matching |id|. 89 // Removes sync item matching |id|.
77 void RemoveItem(const std::string& id); 90 void RemoveItem(const std::string& id);
78 91
79 // Removes sync item matching |id| after item uninstall. 92 // Removes sync item matching |id| after item uninstall.
80 void RemoveUninstalledItem(const std::string& id); 93 void RemoveUninstalledItem(const std::string& id);
81 94
82 // Called when properties of an item may have changed, e.g. default/oem state. 95 // Called when properties of an item may have changed, e.g. default/oem state.
83 void UpdateItem(AppListItem* app_item); 96 void UpdateItem(AppListItem* app_item);
84 97
85 // Returns the existing sync item matching |id| or NULL. 98 // Returns the existing sync item matching |id| or NULL.
86 const SyncItem* GetSyncItem(const std::string& id) const; 99 const SyncItem* GetSyncItem(const std::string& id) const;
87 100
88 // Sets the name of the folder for OEM apps. 101 // Sets the name of the folder for OEM apps.
89 void SetOemFolderName(const std::string& name); 102 void SetOemFolderName(const std::string& name);
90 103
104 // Returns optional pin position for the app specified by |app_id|. If app is
105 // not synced or does not have associated pin position then empty ordinal is
106 // returned.
107 syncer::StringOrdinal GetPinPosition(const std::string& app_id);
108
109 // Sets pin position and how it is pinned for the app specified by |app_id|.
110 // Empty |item_pin_ordinal| indicates that the app has no pin.
111 void SetPinPosition(const std::string& app_id,
112 const syncer::StringOrdinal& item_pin_ordinal);
113
91 // Gets the app list model, building it if it doesn't yet exist. 114 // Gets the app list model, building it if it doesn't yet exist.
92 AppListModel* GetModel(); 115 AppListModel* GetModel();
93 116
117 // Registers new observers and makes sure that service is started.
118 void AddObserverAndStart(Observer* observer);
119 void RemoveObserver(Observer* observer);
120
94 Profile* profile() { return profile_; } 121 Profile* profile() { return profile_; }
95 size_t GetNumSyncItemsForTest(); 122 size_t GetNumSyncItemsForTest();
96 const std::string& GetOemFolderNameForTest() const { 123 const std::string& GetOemFolderNameForTest() const {
97 return oem_folder_name_; 124 return oem_folder_name_;
98 } 125 }
99 void ResetDriveAppProviderForTest(); 126 void ResetDriveAppProviderForTest();
100 127
128 const SyncItemMap& sync_items() const { return sync_items_; }
129
101 // syncer::SyncableService 130 // syncer::SyncableService
102 syncer::SyncMergeResult MergeDataAndStartSyncing( 131 syncer::SyncMergeResult MergeDataAndStartSyncing(
103 syncer::ModelType type, 132 syncer::ModelType type,
104 const syncer::SyncDataList& initial_sync_data, 133 const syncer::SyncDataList& initial_sync_data,
105 std::unique_ptr<syncer::SyncChangeProcessor> sync_processor, 134 std::unique_ptr<syncer::SyncChangeProcessor> sync_processor,
106 std::unique_ptr<syncer::SyncErrorFactory> error_handler) override; 135 std::unique_ptr<syncer::SyncErrorFactory> error_handler) override;
107 void StopSyncing(syncer::ModelType type) override; 136 void StopSyncing(syncer::ModelType type) override;
108 syncer::SyncDataList GetAllSyncData(syncer::ModelType type) const override; 137 syncer::SyncDataList GetAllSyncData(syncer::ModelType type) const override;
109 syncer::SyncError ProcessSyncChanges( 138 syncer::SyncError ProcessSyncChanges(
110 const tracked_objects::Location& from_here, 139 const tracked_objects::Location& from_here,
111 const syncer::SyncChangeList& change_list) override; 140 const syncer::SyncChangeList& change_list) override;
112 141
113 private: 142 private:
114 class ModelObserver; 143 class ModelObserver;
115 typedef std::map<std::string, SyncItem*> SyncItemMap;
116 144
117 // KeyedService 145 // KeyedService
118 void Shutdown() override; 146 void Shutdown() override;
119 147
120 // DriveAppUninstallSyncService 148 // DriveAppUninstallSyncService
121 void TrackUninstalledDriveApp(const std::string& drive_app_id) override; 149 void TrackUninstalledDriveApp(const std::string& drive_app_id) override;
122 void UntrackUninstalledDriveApp(const std::string& drive_app_id) override; 150 void UntrackUninstalledDriveApp(const std::string& drive_app_id) override;
123 151
124 // Builds the model once ExtensionService is ready. 152 // Builds the model once ExtensionService is ready.
125 void BuildModel(); 153 void BuildModel();
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 std::string FindOrCreateOemFolder(); 223 std::string FindOrCreateOemFolder();
196 224
197 // Gets the location for the OEM folder. Called when the folder is first 225 // Gets the location for the OEM folder. Called when the folder is first
198 // created. 226 // created.
199 syncer::StringOrdinal GetOemFolderPos(); 227 syncer::StringOrdinal GetOemFolderPos();
200 228
201 // Returns true if an extension matching |id| exists and was installed by 229 // Returns true if an extension matching |id| exists and was installed by
202 // an OEM (extension->was_installed_by_oem() is true). 230 // an OEM (extension->was_installed_by_oem() is true).
203 bool AppIsOem(const std::string& id); 231 bool AppIsOem(const std::string& id);
204 232
233 // Helper that notifies observers that sync model has been updated.
234 void NotifyObserversSyncUpdated();
235
205 Profile* profile_; 236 Profile* profile_;
206 extensions::ExtensionSystem* extension_system_; 237 extensions::ExtensionSystem* extension_system_;
207 std::unique_ptr<AppListModel> model_; 238 std::unique_ptr<AppListModel> model_;
208 std::unique_ptr<ModelObserver> model_observer_; 239 std::unique_ptr<ModelObserver> model_observer_;
209 std::unique_ptr<ModelPrefUpdater> model_pref_updater_; 240 std::unique_ptr<ModelPrefUpdater> model_pref_updater_;
210 std::unique_ptr<ExtensionAppModelBuilder> apps_builder_; 241 std::unique_ptr<ExtensionAppModelBuilder> apps_builder_;
211 #if defined(OS_CHROMEOS) 242 #if defined(OS_CHROMEOS)
212 std::unique_ptr<ArcAppModelBuilder> arc_apps_builder_; 243 std::unique_ptr<ArcAppModelBuilder> arc_apps_builder_;
213 #endif 244 #endif
214 std::unique_ptr<syncer::SyncChangeProcessor> sync_processor_; 245 std::unique_ptr<syncer::SyncChangeProcessor> sync_processor_;
215 std::unique_ptr<syncer::SyncErrorFactory> sync_error_handler_; 246 std::unique_ptr<syncer::SyncErrorFactory> sync_error_handler_;
216 SyncItemMap sync_items_; 247 SyncItemMap sync_items_;
217 syncer::SyncableService::StartSyncFlare flare_; 248 syncer::SyncableService::StartSyncFlare flare_;
218 bool initial_sync_data_processed_; 249 bool initial_sync_data_processed_;
219 bool first_app_list_sync_; 250 bool first_app_list_sync_;
220 std::string oem_folder_name_; 251 std::string oem_folder_name_;
221 252
253 // List of observers.
254 base::ObserverList<Observer> observer_list_;
255
222 // Provides integration with Drive apps. 256 // Provides integration with Drive apps.
223 std::unique_ptr<DriveAppProvider> drive_app_provider_; 257 std::unique_ptr<DriveAppProvider> drive_app_provider_;
224 258
225 DISALLOW_COPY_AND_ASSIGN(AppListSyncableService); 259 DISALLOW_COPY_AND_ASSIGN(AppListSyncableService);
226 }; 260 };
227 261
228 } // namespace app_list 262 } // namespace app_list
229 263
230 #endif // CHROME_BROWSER_UI_APP_LIST_APP_LIST_SYNCABLE_SERVICE_H_ 264 #endif // CHROME_BROWSER_UI_APP_LIST_APP_LIST_SYNCABLE_SERVICE_H_
OLDNEW
« no previous file with comments | « chrome/browser/prefs/browser_prefs.cc ('k') | chrome/browser/ui/app_list/app_list_syncable_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698