OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_UI_APP_LIST_APP_LIST_MODEL_BUILDER_H_ |
| 6 #define CHROME_BROWSER_UI_APP_LIST_APP_LIST_MODEL_BUILDER_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/macros.h" |
| 11 #include "chrome/browser/ui/app_list/app_list_syncable_service.h" |
| 12 #include "ui/app_list/app_list_item_list_observer.h" |
| 13 #include "ui/app_list/app_list_model.h" |
| 14 |
| 15 class AppListControllerDelegate; |
| 16 class Profile; |
| 17 |
| 18 // This abstract class populates and maintains the given |model| with |
| 19 // information from |profile| for the specific item type. |
| 20 class AppListModelBuilder : public app_list::AppListItemListObserver { |
| 21 public: |
| 22 // |controller| is owned by implementation of AppListService. |
| 23 AppListModelBuilder(AppListControllerDelegate* controller, |
| 24 const char* item_type); |
| 25 ~AppListModelBuilder() override; |
| 26 |
| 27 // Initialize to use app-list sync and sets |service_| to |service|. |
| 28 // |service| is the owner of this instance and |model|. |
| 29 void InitializeWithService(app_list::AppListSyncableService* service, |
| 30 app_list::AppListModel* model); |
| 31 |
| 32 // Initialize to use extension sync and sets |service_| to nullptr. Used in |
| 33 // tests and when AppList sync is not enabled. |
| 34 // app_list::AppListSyncableService is the owner of |model| |
| 35 void InitializeWithProfile(Profile* profile, app_list::AppListModel* model); |
| 36 |
| 37 protected: |
| 38 // Builds the model with the current profile. |
| 39 virtual void BuildModel() = 0; |
| 40 |
| 41 app_list::AppListSyncableService* service() { return service_; } |
| 42 |
| 43 Profile* profile() { return profile_; } |
| 44 |
| 45 AppListControllerDelegate* controller() { return controller_; } |
| 46 |
| 47 app_list::AppListModel* model() { return model_; } |
| 48 |
| 49 // Inserts an app based on app ordinal prefs. |
| 50 void InsertApp(scoped_ptr<app_list::AppListItem> app); |
| 51 |
| 52 const app_list::AppListSyncableService::SyncItem* GetSyncItem( |
| 53 const std::string& id); |
| 54 |
| 55 // Returns app instance matching |id| or nullptr. |
| 56 app_list::AppListItem* GetAppItem(const std::string& id); |
| 57 |
| 58 private: |
| 59 // Unowned pointers to the service that owns this and associated profile. |
| 60 app_list::AppListSyncableService* service_ = nullptr; |
| 61 Profile* profile_ = nullptr; |
| 62 |
| 63 // Unowned pointer to the app list model. |
| 64 app_list::AppListModel* model_ = nullptr; |
| 65 |
| 66 // Unowned pointer to the app list controller. |
| 67 AppListControllerDelegate* controller_; |
| 68 |
| 69 // Global constant defined for each item type. |
| 70 const char* item_type_; |
| 71 |
| 72 DISALLOW_COPY_AND_ASSIGN(AppListModelBuilder); |
| 73 }; |
| 74 |
| 75 #endif // CHROME_BROWSER_UI_APP_LIST_APP_LIST_MODEL_BUILDER_H_ |
OLD | NEW |