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_
11 #include "base/gtest_prod_util.h"
12 #include "chrome/browser/extensions/install_observer.h"
13 #include "ui/app_list/app_list_model.h"
14 #include "ui/base/models/list_model_observer.h"
16 class AppListControllerDelegate;
17 class ExtensionAppItem;
21 namespace extensions {
30 // This class populates and maintains the given |model| with information from
32 class ExtensionAppModelBuilder : public extensions::InstallObserver,
33 public app_list::AppListItemListObserver {
35 ExtensionAppModelBuilder(Profile* profile,
36 app_list::AppListModel* model,
37 AppListControllerDelegate* controller);
38 virtual ~ExtensionAppModelBuilder();
40 // Rebuilds the model with the given profile.
41 void SwitchProfile(Profile* profile);
44 typedef std::vector<ExtensionAppItem*> ExtensionAppList;
46 // extensions::InstallObserver
47 virtual void OnBeginExtensionInstall(const std::string& extension_id,
48 const std::string& extension_name,
49 const gfx::ImageSkia& installing_icon,
51 bool is_platform_app) OVERRIDE;
52 virtual void OnDownloadProgress(const std::string& extension_id,
53 int percent_downloaded) OVERRIDE;
54 virtual void OnInstallFailure(const std::string& extension_id) OVERRIDE;
55 virtual void OnExtensionInstalled(
56 const extensions::Extension* extension) OVERRIDE {}
57 virtual void OnExtensionLoaded(
58 const extensions::Extension* extension) OVERRIDE;
59 virtual void OnExtensionUnloaded(
60 const extensions::Extension* extension) OVERRIDE;
61 virtual void OnExtensionUninstalled(
62 const extensions::Extension* extension) OVERRIDE;
63 virtual void OnAppsReordered() OVERRIDE;
64 virtual void OnAppInstalledToAppList(
65 const std::string& extension_id) OVERRIDE;
66 virtual void OnShutdown() OVERRIDE;
68 // AppListItemListObserver
69 virtual void OnListItemMoved(size_t from_index,
71 app_list::AppListItemModel* item) OVERRIDE;
73 // Adds apps in |extensions| to |apps|.
74 void AddApps(const ExtensionSet* extensions, ExtensionAppList* apps);
76 // Populates the model with apps.
79 // Re-sort apps in case app ordinal prefs are changed.
82 // Inserts an app based on app ordinal prefs.
83 void InsertApp(ExtensionAppItem* app);
85 // Sets which app is intended to be highlighted. Will remove the highlight
86 // from a currently highlighted app.
87 void SetHighlightedApp(const std::string& extension_id);
89 // Sets the application app with |highlight_app_id_| in |model_| as
90 // highlighted if |highlighted_app_pending_| is true. If such an app is found,
91 // reset |highlighted_app_pending_| so that won't be highlighted again until
92 // another call to SetHighlightedApp() is made.
93 void UpdateHighlight();
95 // Returns app instance matching |extension_id| or NULL.
96 ExtensionAppItem* GetExtensionAppItem(const std::string& extension_id);
100 // Unowned pointer to the app list controller (passed to created items).
101 AppListControllerDelegate* controller_;
103 // Unowned pointer to the app list model.
104 app_list::AppListModel* model_;
106 std::string highlight_app_id_;
108 // True if we haven't set |highlight_app_id_| to be highlighted. This happens
109 // if we try to highlight an app that doesn't exist in the list yet.
110 bool highlighted_app_pending_;
112 // We listen to this to show app installing progress.
113 extensions::InstallTracker* tracker_;
115 DISALLOW_COPY_AND_ASSIGN(ExtensionAppModelBuilder);
118 #endif // CHROME_BROWSER_UI_APP_LIST_EXTENSION_APP_MODEL_BUILDER_H_