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

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: cleanup and update 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;
64 bool item_pin_by_policy;
stevenjb 2016/06/10 18:00:40 item_pinned_by_policy
khmel 2016/06/10 22:08:10 Done.
62 65
63 std::string ToString() const; 66 std::string ToString() const;
64 }; 67 };
65 68
69 class Observer {
70 public:
71 // Notifies that sync model was updated.
72 virtual void OnSyncModelUpdated() = 0;
73
74 protected:
75 virtual ~Observer() = default;
76 };
77
78 using SyncItemMap = std::map<std::string, SyncItem*>;
79
66 // Populates the model when |extension_system| is ready. 80 // Populates the model when |extension_system| is ready.
67 AppListSyncableService(Profile* profile, 81 AppListSyncableService(Profile* profile,
68 extensions::ExtensionSystem* extension_system); 82 extensions::ExtensionSystem* extension_system);
69 83
70 ~AppListSyncableService() override; 84 ~AppListSyncableService() override;
71 85
86 static AppListSyncableService* Get(Profile* profile);
87
72 // Adds |item| to |sync_items_| and |model_|. If a sync item already exists, 88 // Adds |item| to |sync_items_| and |model_|. If a sync item already exists,
73 // updates the existing sync item instead. 89 // updates the existing sync item instead.
74 void AddItem(std::unique_ptr<AppListItem> app_item); 90 void AddItem(std::unique_ptr<AppListItem> app_item);
75 91
76 // Removes sync item matching |id|. 92 // Removes sync item matching |id|.
77 void RemoveItem(const std::string& id); 93 void RemoveItem(const std::string& id);
78 94
79 // Removes sync item matching |id| after item uninstall. 95 // Removes sync item matching |id| after item uninstall.
80 void RemoveUninstalledItem(const std::string& id); 96 void RemoveUninstalledItem(const std::string& id);
81 97
82 // Called when properties of an item may have changed, e.g. default/oem state. 98 // Called when properties of an item may have changed, e.g. default/oem state.
83 void UpdateItem(AppListItem* app_item); 99 void UpdateItem(AppListItem* app_item);
84 100
85 // Returns the existing sync item matching |id| or NULL. 101 // Returns the existing sync item matching |id| or NULL.
86 const SyncItem* GetSyncItem(const std::string& id) const; 102 const SyncItem* GetSyncItem(const std::string& id) const;
87 103
88 // Sets the name of the folder for OEM apps. 104 // Sets the name of the folder for OEM apps.
89 void SetOemFolderName(const std::string& name); 105 void SetOemFolderName(const std::string& name);
90 106
107 // Returns true if app specified by |app_id| is synced and marked as pinned
108 // by policy.
109 bool GetPinByPolicy(const std::string& app_id);
stevenjb 2016/06/10 18:00:40 GetPinnedByPolicy
khmel 2016/06/10 22:08:10 Done.
110
111 // Returns optional pin position for the app specified by |app_id|. If app is
112 // not synced or does not have associated pin position then empty ordinal is
113 // returned.
114 syncer::StringOrdinal GetPinPosition(const std::string& app_id);
115
116 // Sets pin position and how it is pinned for the app specified by |app_id|.
117 // Empty |item_pin_ordinal| indicates that the app has no pin.
118 void SetPinPosition(const std::string& app_id,
119 const syncer::StringOrdinal& item_pin_ordinal,
120 bool pinned_by_policy);
121
91 // Gets the app list model, building it if it doesn't yet exist. 122 // Gets the app list model, building it if it doesn't yet exist.
92 AppListModel* GetModel(); 123 AppListModel* GetModel();
93 124
125 // Registers new observers and makes sure that service is started.
126 void AddObserverAndStart(Observer* observer);
127 void RemoveObserver(Observer* observer);
128
94 Profile* profile() { return profile_; } 129 Profile* profile() { return profile_; }
95 size_t GetNumSyncItemsForTest(); 130 size_t GetNumSyncItemsForTest();
96 const std::string& GetOemFolderNameForTest() const { 131 const std::string& GetOemFolderNameForTest() const {
97 return oem_folder_name_; 132 return oem_folder_name_;
98 } 133 }
99 void ResetDriveAppProviderForTest(); 134 void ResetDriveAppProviderForTest();
100 135
136 const SyncItemMap& sync_items() const { return sync_items_; }
137
101 // syncer::SyncableService 138 // syncer::SyncableService
102 syncer::SyncMergeResult MergeDataAndStartSyncing( 139 syncer::SyncMergeResult MergeDataAndStartSyncing(
103 syncer::ModelType type, 140 syncer::ModelType type,
104 const syncer::SyncDataList& initial_sync_data, 141 const syncer::SyncDataList& initial_sync_data,
105 std::unique_ptr<syncer::SyncChangeProcessor> sync_processor, 142 std::unique_ptr<syncer::SyncChangeProcessor> sync_processor,
106 std::unique_ptr<syncer::SyncErrorFactory> error_handler) override; 143 std::unique_ptr<syncer::SyncErrorFactory> error_handler) override;
107 void StopSyncing(syncer::ModelType type) override; 144 void StopSyncing(syncer::ModelType type) override;
108 syncer::SyncDataList GetAllSyncData(syncer::ModelType type) const override; 145 syncer::SyncDataList GetAllSyncData(syncer::ModelType type) const override;
109 syncer::SyncError ProcessSyncChanges( 146 syncer::SyncError ProcessSyncChanges(
110 const tracked_objects::Location& from_here, 147 const tracked_objects::Location& from_here,
111 const syncer::SyncChangeList& change_list) override; 148 const syncer::SyncChangeList& change_list) override;
112 149
113 private: 150 private:
114 class ModelObserver; 151 class ModelObserver;
115 typedef std::map<std::string, SyncItem*> SyncItemMap;
116 152
117 // KeyedService 153 // KeyedService
118 void Shutdown() override; 154 void Shutdown() override;
119 155
120 // DriveAppUninstallSyncService 156 // DriveAppUninstallSyncService
121 void TrackUninstalledDriveApp(const std::string& drive_app_id) override; 157 void TrackUninstalledDriveApp(const std::string& drive_app_id) override;
122 void UntrackUninstalledDriveApp(const std::string& drive_app_id) override; 158 void UntrackUninstalledDriveApp(const std::string& drive_app_id) override;
123 159
124 // Builds the model once ExtensionService is ready. 160 // Builds the model once ExtensionService is ready.
125 void BuildModel(); 161 void BuildModel();
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 std::string FindOrCreateOemFolder(); 231 std::string FindOrCreateOemFolder();
196 232
197 // Gets the location for the OEM folder. Called when the folder is first 233 // Gets the location for the OEM folder. Called when the folder is first
198 // created. 234 // created.
199 syncer::StringOrdinal GetOemFolderPos(); 235 syncer::StringOrdinal GetOemFolderPos();
200 236
201 // Returns true if an extension matching |id| exists and was installed by 237 // Returns true if an extension matching |id| exists and was installed by
202 // an OEM (extension->was_installed_by_oem() is true). 238 // an OEM (extension->was_installed_by_oem() is true).
203 bool AppIsOem(const std::string& id); 239 bool AppIsOem(const std::string& id);
204 240
241 // Helper that notifies observers that sync model has been updated.
242 void NotifyObserversSyncUpdated();
243
205 Profile* profile_; 244 Profile* profile_;
206 extensions::ExtensionSystem* extension_system_; 245 extensions::ExtensionSystem* extension_system_;
207 std::unique_ptr<AppListModel> model_; 246 std::unique_ptr<AppListModel> model_;
208 std::unique_ptr<ModelObserver> model_observer_; 247 std::unique_ptr<ModelObserver> model_observer_;
209 std::unique_ptr<ModelPrefUpdater> model_pref_updater_; 248 std::unique_ptr<ModelPrefUpdater> model_pref_updater_;
210 std::unique_ptr<ExtensionAppModelBuilder> apps_builder_; 249 std::unique_ptr<ExtensionAppModelBuilder> apps_builder_;
211 #if defined(OS_CHROMEOS) 250 #if defined(OS_CHROMEOS)
212 std::unique_ptr<ArcAppModelBuilder> arc_apps_builder_; 251 std::unique_ptr<ArcAppModelBuilder> arc_apps_builder_;
213 #endif 252 #endif
214 std::unique_ptr<syncer::SyncChangeProcessor> sync_processor_; 253 std::unique_ptr<syncer::SyncChangeProcessor> sync_processor_;
215 std::unique_ptr<syncer::SyncErrorFactory> sync_error_handler_; 254 std::unique_ptr<syncer::SyncErrorFactory> sync_error_handler_;
216 SyncItemMap sync_items_; 255 SyncItemMap sync_items_;
217 syncer::SyncableService::StartSyncFlare flare_; 256 syncer::SyncableService::StartSyncFlare flare_;
218 bool initial_sync_data_processed_; 257 bool initial_sync_data_processed_;
219 bool first_app_list_sync_; 258 bool first_app_list_sync_;
220 std::string oem_folder_name_; 259 std::string oem_folder_name_;
221 260
261 // List of observers.
262 base::ObserverList<Observer> observer_list_;
263
222 // Provides integration with Drive apps. 264 // Provides integration with Drive apps.
223 std::unique_ptr<DriveAppProvider> drive_app_provider_; 265 std::unique_ptr<DriveAppProvider> drive_app_provider_;
224 266
225 DISALLOW_COPY_AND_ASSIGN(AppListSyncableService); 267 DISALLOW_COPY_AND_ASSIGN(AppListSyncableService);
226 }; 268 };
227 269
228 } // namespace app_list 270 } // namespace app_list
229 271
230 #endif // CHROME_BROWSER_UI_APP_LIST_APP_LIST_SYNCABLE_SERVICE_H_ 272 #endif // CHROME_BROWSER_UI_APP_LIST_APP_LIST_SYNCABLE_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698