OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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_EXTENSION_APP_MODEL_BUILDER_H_ | 5 #ifndef CHROME_BROWSER_UI_APP_LIST_EXTENSION_APP_MODEL_BUILDER_H_ |
6 #define CHROME_BROWSER_UI_APP_LIST_EXTENSION_APP_MODEL_BUILDER_H_ | 6 #define CHROME_BROWSER_UI_APP_LIST_EXTENSION_APP_MODEL_BUILDER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/prefs/pref_change_registrar.h" | 11 #include "base/prefs/pref_change_registrar.h" |
12 #include "base/scoped_observer.h" | |
13 #include "chrome/browser/extensions/install_observer.h" | 12 #include "chrome/browser/extensions/install_observer.h" |
| 13 #include "chrome/browser/ui/app_list/app_list_model_builder.h" |
14 #include "extensions/browser/extension_registry_observer.h" | 14 #include "extensions/browser/extension_registry_observer.h" |
15 #include "ui/app_list/app_list_model.h" | |
16 #include "ui/base/models/list_model_observer.h" | 15 #include "ui/base/models/list_model_observer.h" |
17 | 16 |
18 class AppListControllerDelegate; | 17 class AppListControllerDelegate; |
19 class ExtensionAppItem; | 18 class ExtensionAppItem; |
20 class Profile; | |
21 | |
22 namespace app_list { | |
23 class AppListSyncableService; | |
24 } | |
25 | 19 |
26 namespace extensions { | 20 namespace extensions { |
27 class Extension; | 21 class Extension; |
28 class ExtensionRegistry; | 22 class ExtensionRegistry; |
29 class ExtensionSet; | 23 class ExtensionSet; |
30 class InstallTracker; | 24 class InstallTracker; |
31 } | 25 } |
32 | 26 |
33 namespace gfx { | 27 namespace gfx { |
34 class ImageSkia; | 28 class ImageSkia; |
35 } | 29 } |
36 | 30 |
37 // This class populates and maintains the given |model| with information from | 31 // This class populates and maintains the given |model| for extension items |
38 // |profile|. | 32 // with information from |profile|. |
39 class ExtensionAppModelBuilder : public extensions::InstallObserver, | 33 class ExtensionAppModelBuilder : public AppListModelBuilder, |
40 public extensions::ExtensionRegistryObserver, | 34 public extensions::InstallObserver, |
41 public app_list::AppListItemListObserver { | 35 public extensions::ExtensionRegistryObserver { |
42 public: | 36 public: |
43 explicit ExtensionAppModelBuilder(AppListControllerDelegate* controller); | 37 explicit ExtensionAppModelBuilder(AppListControllerDelegate* controller); |
44 ~ExtensionAppModelBuilder() override; | 38 ~ExtensionAppModelBuilder() override; |
45 | 39 |
46 // Initialize to use app-list sync and sets |service_| to |service|. | |
47 void InitializeWithService(app_list::AppListSyncableService* service, | |
48 app_list::AppListModel* model); | |
49 | |
50 // Initialize to use extension sync and sets |service_| to NULL. Used in | |
51 // tests and when AppList sync is not enabled. | |
52 void InitializeWithProfile(Profile* profile, app_list::AppListModel* model); | |
53 | |
54 private: | 40 private: |
55 typedef std::vector<ExtensionAppItem*> ExtensionAppList; | 41 typedef std::vector<ExtensionAppItem*> ExtensionAppList; |
56 | 42 |
57 // Builds the model with the current profile. | 43 // AppListModelBuilder |
58 void BuildModel(); | 44 void BuildModel() override; |
59 | 45 |
60 // extensions::InstallObserver. | 46 // extensions::InstallObserver. |
61 void OnBeginExtensionInstall(const ExtensionInstallParams& params) override; | 47 void OnBeginExtensionInstall(const ExtensionInstallParams& params) override; |
62 void OnDownloadProgress(const std::string& extension_id, | 48 void OnDownloadProgress(const std::string& extension_id, |
63 int percent_downloaded) override; | 49 int percent_downloaded) override; |
64 void OnInstallFailure(const std::string& extension_id) override; | 50 void OnInstallFailure(const std::string& extension_id) override; |
65 void OnDisabledExtensionUpdated( | 51 void OnDisabledExtensionUpdated( |
66 const extensions::Extension* extension) override; | 52 const extensions::Extension* extension) override; |
67 void OnShutdown() override; | 53 void OnShutdown() override; |
68 | 54 |
(...skipping 16 matching lines...) Expand all Loading... |
85 | 71 |
86 scoped_ptr<ExtensionAppItem> CreateAppItem( | 72 scoped_ptr<ExtensionAppItem> CreateAppItem( |
87 const std::string& extension_id, | 73 const std::string& extension_id, |
88 const std::string& extension_name, | 74 const std::string& extension_name, |
89 const gfx::ImageSkia& installing_icon, | 75 const gfx::ImageSkia& installing_icon, |
90 bool is_platform_app); | 76 bool is_platform_app); |
91 | 77 |
92 // Populates the model with apps. | 78 // Populates the model with apps. |
93 void PopulateApps(); | 79 void PopulateApps(); |
94 | 80 |
95 // Inserts an app based on app ordinal prefs. | |
96 void InsertApp(scoped_ptr<ExtensionAppItem> app); | |
97 | |
98 // Returns app instance matching |extension_id| or NULL. | 81 // Returns app instance matching |extension_id| or NULL. |
99 ExtensionAppItem* GetExtensionAppItem(const std::string& extension_id); | 82 ExtensionAppItem* GetExtensionAppItem(const std::string& extension_id); |
100 | 83 |
101 // Initializes the |profile_pref_change_registrar_| and the | 84 // Initializes the |profile_pref_change_registrar_| and the |
102 // |extension_pref_change_registrar_| to listen for changes to profile and | 85 // |extension_pref_change_registrar_| to listen for changes to profile and |
103 // extension prefs, and call OnProfilePreferenceChanged() or | 86 // extension prefs, and call OnProfilePreferenceChanged() or |
104 // OnExtensionPreferenceChanged(). | 87 // OnExtensionPreferenceChanged(). |
105 void InitializePrefChangeRegistrars(); | 88 void InitializePrefChangeRegistrars(); |
106 | 89 |
107 // Handles profile prefs changes. | 90 // Handles profile prefs changes. |
108 void OnProfilePreferenceChanged(); | 91 void OnProfilePreferenceChanged(); |
109 | 92 |
110 // Handles extension prefs changes. | 93 // Handles extension prefs changes. |
111 void OnExtensionPreferenceChanged(); | 94 void OnExtensionPreferenceChanged(); |
112 | 95 |
113 // Unowned pointers to the service that owns this and associated profile. | |
114 app_list::AppListSyncableService* service_; | |
115 Profile* profile_; | |
116 | |
117 // Registrar used to monitor the profile prefs. | 96 // Registrar used to monitor the profile prefs. |
118 PrefChangeRegistrar profile_pref_change_registrar_; | 97 PrefChangeRegistrar profile_pref_change_registrar_; |
119 | 98 |
120 // Registrar used to monitor the extension prefs. | 99 // Registrar used to monitor the extension prefs. |
121 PrefChangeRegistrar extension_pref_change_registrar_; | 100 PrefChangeRegistrar extension_pref_change_registrar_; |
122 | 101 |
123 // Unowned pointer to the app list controller. | |
124 AppListControllerDelegate* controller_; | |
125 | |
126 // Unowned pointer to the app list model. | |
127 app_list::AppListModel* model_; | |
128 | |
129 // We listen to this to show app installing progress. | 102 // We listen to this to show app installing progress. |
130 extensions::InstallTracker* tracker_; | 103 extensions::InstallTracker* tracker_ = nullptr; |
131 | 104 |
132 // Listen extension's load, unload, uninstalled. | 105 // Listen extension's load, unload, uninstalled. |
133 extensions::ExtensionRegistry* extension_registry_; | 106 extensions::ExtensionRegistry* extension_registry_ = nullptr; |
134 | 107 |
135 DISALLOW_COPY_AND_ASSIGN(ExtensionAppModelBuilder); | 108 DISALLOW_COPY_AND_ASSIGN(ExtensionAppModelBuilder); |
136 }; | 109 }; |
137 | 110 |
138 #endif // CHROME_BROWSER_UI_APP_LIST_EXTENSION_APP_MODEL_BUILDER_H_ | 111 #endif // CHROME_BROWSER_UI_APP_LIST_EXTENSION_APP_MODEL_BUILDER_H_ |
OLD | NEW |