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

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

Issue 981893002: Lazily build the app list model. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@fix_set_enabled
Patch Set: Created 5 years, 9 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 <map> 8 #include <map>
9 9
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "chrome/browser/apps/drive/drive_app_uninstall_sync_service.h" 11 #include "chrome/browser/apps/drive/drive_app_uninstall_sync_service.h"
12 #include "chrome/browser/sync/glue/sync_start_util.h" 12 #include "chrome/browser/sync/glue/sync_start_util.h"
13 #include "components/keyed_service/core/keyed_service.h" 13 #include "components/keyed_service/core/keyed_service.h"
14 #include "content/public/browser/notification_observer.h"
15 #include "content/public/browser/notification_registrar.h"
16 #include "sync/api/string_ordinal.h" 14 #include "sync/api/string_ordinal.h"
17 #include "sync/api/sync_change.h" 15 #include "sync/api/sync_change.h"
18 #include "sync/api/sync_change_processor.h" 16 #include "sync/api/sync_change_processor.h"
19 #include "sync/api/sync_error_factory.h" 17 #include "sync/api/sync_error_factory.h"
20 #include "sync/api/syncable_service.h" 18 #include "sync/api/syncable_service.h"
21 #include "sync/protocol/app_list_specifics.pb.h" 19 #include "sync/protocol/app_list_specifics.pb.h"
22 20
23 class DriveAppProvider; 21 class DriveAppProvider;
24 class ExtensionAppModelBuilder; 22 class ExtensionAppModelBuilder;
25 class Profile; 23 class Profile;
26 24
27 namespace extensions { 25 namespace extensions {
28 class ExtensionSystem; 26 class ExtensionSystem;
29 } 27 }
30 28
31 namespace sync_pb { 29 namespace sync_pb {
32 class AppListSpecifics; 30 class AppListSpecifics;
33 } 31 }
34 32
35 namespace app_list { 33 namespace app_list {
36 34
37 class AppListFolderItem; 35 class AppListFolderItem;
38 class AppListItem; 36 class AppListItem;
39 class AppListModel; 37 class AppListModel;
40 class ModelPrefUpdater; 38 class ModelPrefUpdater;
41 39
42 // Keyed Service that owns, stores, and syncs an AppListModel for a profile. 40 // Keyed Service that owns, stores, and syncs an AppListModel for a profile.
43 class AppListSyncableService : public syncer::SyncableService, 41 class AppListSyncableService : public syncer::SyncableService,
44 public KeyedService, 42 public KeyedService,
45 public DriveAppUninstallSyncService, 43 public DriveAppUninstallSyncService {
46 public content::NotificationObserver {
47 public: 44 public:
48 struct SyncItem { 45 struct SyncItem {
49 SyncItem(const std::string& id, 46 SyncItem(const std::string& id,
50 sync_pb::AppListSpecifics::AppListItemType type); 47 sync_pb::AppListSpecifics::AppListItemType type);
51 ~SyncItem(); 48 ~SyncItem();
52 const std::string item_id; 49 const std::string item_id;
53 sync_pb::AppListSpecifics::AppListItemType item_type; 50 sync_pb::AppListSpecifics::AppListItemType item_type;
54 std::string item_name; 51 std::string item_name;
55 std::string parent_id; 52 std::string parent_id;
56 syncer::StringOrdinal item_ordinal; 53 syncer::StringOrdinal item_ordinal;
(...skipping 16 matching lines...) Expand all
73 70
74 // Called when properties of an item may have changed, e.g. default/oem state. 71 // Called when properties of an item may have changed, e.g. default/oem state.
75 void UpdateItem(AppListItem* app_item); 72 void UpdateItem(AppListItem* app_item);
76 73
77 // Returns the existing sync item matching |id| or NULL. 74 // Returns the existing sync item matching |id| or NULL.
78 const SyncItem* GetSyncItem(const std::string& id) const; 75 const SyncItem* GetSyncItem(const std::string& id) const;
79 76
80 // Sets the name of the folder for OEM apps. 77 // Sets the name of the folder for OEM apps.
81 void SetOemFolderName(const std::string& name); 78 void SetOemFolderName(const std::string& name);
82 79
80 // Gets the app list model, building it if it doesn't yet exist.
81 AppListModel* GetModel();
82
83 Profile* profile() { return profile_; } 83 Profile* profile() { return profile_; }
84 AppListModel* model() { return model_.get(); } 84 size_t GetNumSyncItemsForTest();
85 size_t GetNumSyncItemsForTest() const { return sync_items_.size(); }
86 const std::string& GetOemFolderNameForTest() const { 85 const std::string& GetOemFolderNameForTest() const {
87 return oem_folder_name_; 86 return oem_folder_name_;
88 } 87 }
89 void ResetDriveAppProviderForTest(); 88 void ResetDriveAppProviderForTest();
90 89
91 // syncer::SyncableService 90 // syncer::SyncableService
92 syncer::SyncMergeResult MergeDataAndStartSyncing( 91 syncer::SyncMergeResult MergeDataAndStartSyncing(
93 syncer::ModelType type, 92 syncer::ModelType type,
94 const syncer::SyncDataList& initial_sync_data, 93 const syncer::SyncDataList& initial_sync_data,
95 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, 94 scoped_ptr<syncer::SyncChangeProcessor> sync_processor,
96 scoped_ptr<syncer::SyncErrorFactory> error_handler) override; 95 scoped_ptr<syncer::SyncErrorFactory> error_handler) override;
97 void StopSyncing(syncer::ModelType type) override; 96 void StopSyncing(syncer::ModelType type) override;
98 syncer::SyncDataList GetAllSyncData(syncer::ModelType type) const override; 97 syncer::SyncDataList GetAllSyncData(syncer::ModelType type) const override;
99 syncer::SyncError ProcessSyncChanges( 98 syncer::SyncError ProcessSyncChanges(
100 const tracked_objects::Location& from_here, 99 const tracked_objects::Location& from_here,
101 const syncer::SyncChangeList& change_list) override; 100 const syncer::SyncChangeList& change_list) override;
102 101
103 private: 102 private:
104 class ModelObserver; 103 class ModelObserver;
105 typedef std::map<std::string, SyncItem*> SyncItemMap; 104 typedef std::map<std::string, SyncItem*> SyncItemMap;
106 105
107 // KeyedService 106 // KeyedService
108 void Shutdown() override; 107 void Shutdown() override;
109 108
110 // DriveAppUninstallSyncService 109 // DriveAppUninstallSyncService
111 void TrackUninstalledDriveApp(const std::string& drive_app_id) override; 110 void TrackUninstalledDriveApp(const std::string& drive_app_id) override;
112 void UntrackUninstalledDriveApp(const std::string& drive_app_id) override; 111 void UntrackUninstalledDriveApp(const std::string& drive_app_id) override;
113 112
114 // content::NotificationObserver
115 void Observe(int type,
116 const content::NotificationSource& source,
117 const content::NotificationDetails& details) override;
118
119 // Builds the model once ExtensionService is ready. 113 // Builds the model once ExtensionService is ready.
120 void BuildModel(); 114 void BuildModel();
121 115
122 // Returns true if sync has restarted, otherwise runs |flare_|. 116 // Returns true if sync has restarted, otherwise runs |flare_|.
123 bool SyncStarted(); 117 bool SyncStarted();
124 118
125 // If |app_item| matches an existing sync item, returns it. Otherwise adds 119 // If |app_item| matches an existing sync item, returns it. Otherwise adds
126 // |app_item| to |sync_items_| and returns the new item. If |app_item| is 120 // |app_item| to |sync_items_| and returns the new item. If |app_item| is
127 // invalid returns NULL. 121 // invalid returns NULL.
128 SyncItem* FindOrAddSyncItem(AppListItem* app_item); 122 SyncItem* FindOrAddSyncItem(AppListItem* app_item);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 // Gets the location for the OEM folder. Called when the folder is first 186 // Gets the location for the OEM folder. Called when the folder is first
193 // created. 187 // created.
194 syncer::StringOrdinal GetOemFolderPos(); 188 syncer::StringOrdinal GetOemFolderPos();
195 189
196 // Returns true if an extension matching |id| exists and was installed by 190 // Returns true if an extension matching |id| exists and was installed by
197 // an OEM (extension->was_installed_by_oem() is true). 191 // an OEM (extension->was_installed_by_oem() is true).
198 bool AppIsOem(const std::string& id); 192 bool AppIsOem(const std::string& id);
199 193
200 Profile* profile_; 194 Profile* profile_;
201 extensions::ExtensionSystem* extension_system_; 195 extensions::ExtensionSystem* extension_system_;
202 content::NotificationRegistrar registrar_;
203 scoped_ptr<AppListModel> model_; 196 scoped_ptr<AppListModel> model_;
204 scoped_ptr<ModelObserver> model_observer_; 197 scoped_ptr<ModelObserver> model_observer_;
205 scoped_ptr<ModelPrefUpdater> model_pref_updater_; 198 scoped_ptr<ModelPrefUpdater> model_pref_updater_;
206 scoped_ptr<ExtensionAppModelBuilder> apps_builder_; 199 scoped_ptr<ExtensionAppModelBuilder> apps_builder_;
207 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; 200 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_;
208 scoped_ptr<syncer::SyncErrorFactory> sync_error_handler_; 201 scoped_ptr<syncer::SyncErrorFactory> sync_error_handler_;
209 SyncItemMap sync_items_; 202 SyncItemMap sync_items_;
210 syncer::SyncableService::StartSyncFlare flare_; 203 syncer::SyncableService::StartSyncFlare flare_;
211 bool initial_sync_data_processed_; 204 bool initial_sync_data_processed_;
212 bool first_app_list_sync_; 205 bool first_app_list_sync_;
213 std::string oem_folder_name_; 206 std::string oem_folder_name_;
214 207
215 // Provides integration with Drive apps. 208 // Provides integration with Drive apps.
216 scoped_ptr<DriveAppProvider> drive_app_provider_; 209 scoped_ptr<DriveAppProvider> drive_app_provider_;
217 210
218 DISALLOW_COPY_AND_ASSIGN(AppListSyncableService); 211 DISALLOW_COPY_AND_ASSIGN(AppListSyncableService);
219 }; 212 };
220 213
221 } // namespace app_list 214 } // namespace app_list
222 215
223 #endif // CHROME_BROWSER_UI_APP_LIST_APP_LIST_SYNCABLE_SERVICE_H_ 216 #endif // CHROME_BROWSER_UI_APP_LIST_APP_LIST_SYNCABLE_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698