Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / chrome / browser / ui / app_list / extension_app_model_builder.h
blob5266079ea7a6888c18cbac3813e309413661d264
1 // Copyright (c) 2012 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.
5 #ifndef CHROME_BROWSER_UI_APP_LIST_EXTENSION_APP_MODEL_BUILDER_H_
6 #define CHROME_BROWSER_UI_APP_LIST_EXTENSION_APP_MODEL_BUILDER_H_
8 #include <string>
9 #include <vector>
11 #include "base/gtest_prod_util.h"
12 #include "base/prefs/pref_change_registrar.h"
13 #include "base/scoped_observer.h"
14 #include "chrome/browser/extensions/install_observer.h"
15 #include "extensions/browser/extension_registry_observer.h"
16 #include "ui/app_list/app_list_model.h"
17 #include "ui/base/models/list_model_observer.h"
19 class AppListControllerDelegate;
20 class ExtensionAppItem;
21 class Profile;
23 namespace app_list {
24 class AppListSyncableService;
27 namespace extensions {
28 class Extension;
29 class ExtensionRegistry;
30 class ExtensionSet;
31 class InstallTracker;
34 namespace gfx {
35 class ImageSkia;
38 // This class populates and maintains the given |model| with information from
39 // |profile|.
40 class ExtensionAppModelBuilder : public extensions::InstallObserver,
41 public extensions::ExtensionRegistryObserver,
42 public app_list::AppListItemListObserver {
43 public:
44 explicit ExtensionAppModelBuilder(AppListControllerDelegate* controller);
45 ~ExtensionAppModelBuilder() override;
47 // Initialize to use app-list sync and sets |service_| to |service|.
48 void InitializeWithService(app_list::AppListSyncableService* service,
49 app_list::AppListModel* model);
51 // Initialize to use extension sync and sets |service_| to NULL. Used in
52 // tests and when AppList sync is not enabled.
53 void InitializeWithProfile(Profile* profile, app_list::AppListModel* model);
55 private:
56 typedef std::vector<ExtensionAppItem*> ExtensionAppList;
58 // Builds the model with the current profile.
59 void BuildModel();
61 // extensions::InstallObserver.
62 void OnBeginExtensionInstall(const ExtensionInstallParams& params) override;
63 void OnDownloadProgress(const std::string& extension_id,
64 int percent_downloaded) override;
65 void OnInstallFailure(const std::string& extension_id) override;
66 void OnDisabledExtensionUpdated(
67 const extensions::Extension* extension) override;
68 void OnShutdown() override;
70 // extensions::ExtensionRegistryObserver.
71 void OnExtensionLoaded(content::BrowserContext* browser_context,
72 const extensions::Extension* extension) override;
73 void OnExtensionUnloaded(
74 content::BrowserContext* browser_context,
75 const extensions::Extension* extension,
76 extensions::UnloadedExtensionInfo::Reason reason) override;
77 void OnExtensionUninstalled(content::BrowserContext* browser_context,
78 const extensions::Extension* extension,
79 extensions::UninstallReason reason) override;
80 void OnShutdown(extensions::ExtensionRegistry* registry) override;
82 // AppListItemListObserver.
83 void OnListItemMoved(size_t from_index,
84 size_t to_index,
85 app_list::AppListItem* item) override;
87 scoped_ptr<ExtensionAppItem> CreateAppItem(
88 const std::string& extension_id,
89 const std::string& extension_name,
90 const gfx::ImageSkia& installing_icon,
91 bool is_platform_app);
93 // Populates the model with apps.
94 void PopulateApps();
96 // Inserts an app based on app ordinal prefs.
97 void InsertApp(scoped_ptr<ExtensionAppItem> app);
99 // Returns app instance matching |extension_id| or NULL.
100 ExtensionAppItem* GetExtensionAppItem(const std::string& extension_id);
102 // Initializes the |profile_pref_change_registrar_| and the
103 // |extension_pref_change_registrar_| to listen for changes to profile and
104 // extension prefs, and call OnProfilePreferenceChanged() or
105 // OnExtensionPreferenceChanged().
106 void InitializePrefChangeRegistrars();
108 // Handles profile prefs changes.
109 void OnProfilePreferenceChanged();
111 // Handles extension prefs changes.
112 void OnExtensionPreferenceChanged();
114 // Unowned pointers to the service that owns this and associated profile.
115 app_list::AppListSyncableService* service_;
116 Profile* profile_;
118 // Registrar used to monitor the profile prefs.
119 PrefChangeRegistrar profile_pref_change_registrar_;
121 // Registrar used to monitor the extension prefs.
122 PrefChangeRegistrar extension_pref_change_registrar_;
124 // Unowned pointer to the app list controller.
125 AppListControllerDelegate* controller_;
127 // Unowned pointer to the app list model.
128 app_list::AppListModel* model_;
130 // We listen to this to show app installing progress.
131 extensions::InstallTracker* tracker_;
133 // Listen extension's load, unload, uninstalled.
134 extensions::ExtensionRegistry* extension_registry_;
136 DISALLOW_COPY_AND_ASSIGN(ExtensionAppModelBuilder);
139 #endif // CHROME_BROWSER_UI_APP_LIST_EXTENSION_APP_MODEL_BUILDER_H_