ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / chrome / browser / ui / app_list / extension_app_model_builder.h
blob1d85fe0d7eef0f37806d613252bb345d71e5e267
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);
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 void OnBeginExtensionInstall(const ExtensionInstallParams& params) override;
62 void OnDownloadProgress(const std::string& extension_id,
63 int percent_downloaded) override;
64 void OnInstallFailure(const std::string& extension_id) override;
65 void OnDisabledExtensionUpdated(
66 const extensions::Extension* extension) override;
67 void OnShutdown() override;
69 // extensions::ExtensionRegistryObserver.
70 void OnExtensionLoaded(content::BrowserContext* browser_context,
71 const extensions::Extension* extension) override;
72 void OnExtensionUnloaded(
73 content::BrowserContext* browser_context,
74 const extensions::Extension* extension,
75 extensions::UnloadedExtensionInfo::Reason reason) override;
76 void OnExtensionUninstalled(content::BrowserContext* browser_context,
77 const extensions::Extension* extension,
78 extensions::UninstallReason reason) override;
79 void OnShutdown(extensions::ExtensionRegistry* registry) override;
81 // AppListItemListObserver.
82 void OnListItemMoved(size_t from_index,
83 size_t to_index,
84 app_list::AppListItem* item) override;
86 scoped_ptr<ExtensionAppItem> CreateAppItem(
87 const std::string& extension_id,
88 const std::string& extension_name,
89 const gfx::ImageSkia& installing_icon,
90 bool is_platform_app);
92 // Populates the model with apps.
93 void PopulateApps();
95 // Inserts an app based on app ordinal prefs.
96 void InsertApp(scoped_ptr<ExtensionAppItem> app);
98 // Returns app instance matching |extension_id| or NULL.
99 ExtensionAppItem* GetExtensionAppItem(const std::string& extension_id);
101 // Initializes the |profile_pref_change_registrar_| and the
102 // |extension_pref_change_registrar_| to listen for changes to profile and
103 // extension prefs, and call OnProfilePreferenceChanged() or
104 // OnExtensionPreferenceChanged().
105 void InitializePrefChangeRegistrars();
107 // Handles profile prefs changes.
108 void OnProfilePreferenceChanged();
110 // Handles extension prefs changes.
111 void OnExtensionPreferenceChanged();
113 // Unowned pointers to the service that owns this and associated profile.
114 app_list::AppListSyncableService* service_;
115 Profile* profile_;
117 // Registrar used to monitor the profile prefs.
118 PrefChangeRegistrar profile_pref_change_registrar_;
120 // Registrar used to monitor the extension prefs.
121 PrefChangeRegistrar extension_pref_change_registrar_;
123 // Unowned pointer to the app list controller.
124 AppListControllerDelegate* controller_;
126 // Unowned pointer to the app list model.
127 app_list::AppListModel* model_;
129 // We listen to this to show app installing progress.
130 extensions::InstallTracker* tracker_;
132 // Listen extension's load, unload, uninstalled.
133 extensions::ExtensionRegistry* extension_registry_;
135 DISALLOW_COPY_AND_ASSIGN(ExtensionAppModelBuilder);
138 #endif // CHROME_BROWSER_UI_APP_LIST_EXTENSION_APP_MODEL_BUILDER_H_