Adding instrumentation to locate the source of jankiness
[chromium-blink-merge.git] / chrome / browser / ui / app_list / extension_app_model_builder.h
blob3716fcdedaa3aab2bb7ced0a49e699060fcde471
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 virtual ~ExtensionAppModelBuilder();
47 // Initialize to use app-list sync and sets |service_| to |service|.
48 void InitializeWithService(app_list::AppListSyncableService* service);
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);
54 private:
55 typedef std::vector<ExtensionAppItem*> ExtensionAppList;
57 // Builds the model with the current profile.
58 void BuildModel();
60 // extensions::InstallObserver.
61 virtual void OnBeginExtensionInstall(
62 const ExtensionInstallParams& params) override;
63 virtual void OnDownloadProgress(const std::string& extension_id,
64 int percent_downloaded) override;
65 virtual void OnInstallFailure(const std::string& extension_id) override;
66 virtual void OnDisabledExtensionUpdated(
67 const extensions::Extension* extension) override;
68 virtual void OnShutdown() override;
70 // extensions::ExtensionRegistryObserver.
71 virtual void OnExtensionLoaded(
72 content::BrowserContext* browser_context,
73 const extensions::Extension* extension) override;
74 virtual void OnExtensionUnloaded(
75 content::BrowserContext* browser_context,
76 const extensions::Extension* extension,
77 extensions::UnloadedExtensionInfo::Reason reason) override;
78 virtual void OnExtensionUninstalled(
79 content::BrowserContext* browser_context,
80 const extensions::Extension* extension,
81 extensions::UninstallReason reason) override;
82 virtual void OnShutdown(extensions::ExtensionRegistry* registry) override;
84 // AppListItemListObserver.
85 virtual void OnListItemMoved(size_t from_index,
86 size_t to_index,
87 app_list::AppListItem* item) override;
89 scoped_ptr<ExtensionAppItem> CreateAppItem(
90 const std::string& extension_id,
91 const std::string& extension_name,
92 const gfx::ImageSkia& installing_icon,
93 bool is_platform_app);
95 // Populates the model with apps.
96 void PopulateApps();
98 // Inserts an app based on app ordinal prefs.
99 void InsertApp(scoped_ptr<ExtensionAppItem> app);
101 // Returns app instance matching |extension_id| or NULL.
102 ExtensionAppItem* GetExtensionAppItem(const std::string& extension_id);
104 // Initializes the |profile_pref_change_registrar_| and the
105 // |extension_pref_change_registrar_| to listen for changes to profile and
106 // extension prefs, and call OnProfilePreferenceChanged() or
107 // OnExtensionPreferenceChanged().
108 void InitializePrefChangeRegistrars();
110 // Handles profile prefs changes.
111 void OnProfilePreferenceChanged();
113 // Handles extension prefs changes.
114 void OnExtensionPreferenceChanged();
116 // Unowned pointers to the service that owns this and associated profile.
117 app_list::AppListSyncableService* service_;
118 Profile* profile_;
120 // Registrar used to monitor the profile prefs.
121 PrefChangeRegistrar profile_pref_change_registrar_;
123 // Registrar used to monitor the extension prefs.
124 PrefChangeRegistrar extension_pref_change_registrar_;
126 // Unowned pointer to the app list controller.
127 AppListControllerDelegate* controller_;
129 // Unowned pointer to the app list model.
130 app_list::AppListModel* model_;
132 // We listen to this to show app installing progress.
133 extensions::InstallTracker* tracker_;
135 // Listen extension's load, unload, uninstalled.
136 extensions::ExtensionRegistry* extension_registry_;
138 DISALLOW_COPY_AND_ASSIGN(ExtensionAppModelBuilder);
141 #endif // CHROME_BROWSER_UI_APP_LIST_EXTENSION_APP_MODEL_BUILDER_H_