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 class AppListSyncableService
;
24 namespace extensions
{
34 // This class populates and maintains the given |model| with information from
36 class ExtensionAppModelBuilder
: public extensions::InstallObserver
,
37 public app_list::AppListItemListObserver
{
39 explicit ExtensionAppModelBuilder(AppListControllerDelegate
* controller
);
40 virtual ~ExtensionAppModelBuilder();
42 // Initialize to use app-list sync and sets |service_| to |service|.
43 void InitializeWithService(app_list::AppListSyncableService
* service
);
45 // Initialize to use extension sync and sets |service_| to NULL. Used in
46 // tests and when AppList sync is not enabled.
47 void InitializeWithProfile(Profile
* profile
, app_list::AppListModel
* model
);
50 typedef std::vector
<ExtensionAppItem
*> ExtensionAppList
;
52 // Builds the model with the current profile.
55 // extensions::InstallObserver
56 virtual void OnBeginExtensionInstall(
57 const ExtensionInstallParams
& params
) OVERRIDE
;
58 virtual void OnDownloadProgress(const std::string
& extension_id
,
59 int percent_downloaded
) OVERRIDE
;
60 virtual void OnInstallFailure(const std::string
& extension_id
) OVERRIDE
;
61 virtual void OnExtensionInstalled(
62 const extensions::Extension
* extension
) OVERRIDE
{}
63 virtual void OnExtensionLoaded(
64 const extensions::Extension
* extension
) OVERRIDE
;
65 virtual void OnExtensionUnloaded(
66 const extensions::Extension
* extension
) OVERRIDE
;
67 virtual void OnExtensionUninstalled(
68 const extensions::Extension
* extension
) OVERRIDE
;
69 virtual void OnAppsReordered() OVERRIDE
;
70 virtual void OnAppInstalledToAppList(
71 const std::string
& extension_id
) OVERRIDE
;
72 virtual void OnShutdown() OVERRIDE
;
74 // AppListItemListObserver
75 virtual void OnListItemMoved(size_t from_index
,
77 app_list::AppListItem
* item
) OVERRIDE
;
79 ExtensionAppItem
* CreateAppItem(const std::string
& extension_id
,
80 const std::string
& extension_name
,
81 const gfx::ImageSkia
& installing_icon
,
82 bool is_platform_app
);
84 // Adds apps in |extensions| to |apps|.
85 void AddApps(const extensions::ExtensionSet
* extensions
,
86 ExtensionAppList
* apps
);
88 // Populates the model with apps.
91 // Re-sort apps in case app ordinal prefs are changed.
94 // Inserts an app based on app ordinal prefs.
95 void InsertApp(ExtensionAppItem
* app
);
97 // Sets which app is intended to be highlighted. Will remove the highlight
98 // from a currently highlighted app.
99 void SetHighlightedApp(const std::string
& extension_id
);
101 // Sets the application app with |highlight_app_id_| in |model_| as
102 // highlighted if |highlighted_app_pending_| is true. If such an app is found,
103 // reset |highlighted_app_pending_| so that won't be highlighted again until
104 // another call to SetHighlightedApp() is made.
105 void UpdateHighlight();
107 // Returns app instance matching |extension_id| or NULL.
108 ExtensionAppItem
* GetExtensionAppItem(const std::string
& extension_id
);
110 // Unowned pointers to the service that owns this and associated profile.
111 app_list::AppListSyncableService
* service_
;
114 // Unowned pointer to the app list controller.
115 AppListControllerDelegate
* controller_
;
117 // Unowned pointer to the app list model.
118 app_list::AppListModel
* model_
;
120 std::string highlight_app_id_
;
122 // True if we haven't set |highlight_app_id_| to be highlighted. This happens
123 // if we try to highlight an app that doesn't exist in the list yet.
124 bool highlighted_app_pending_
;
126 // We listen to this to show app installing progress.
127 extensions::InstallTracker
* tracker_
;
129 DISALLOW_COPY_AND_ASSIGN(ExtensionAppModelBuilder
);
132 #endif // CHROME_BROWSER_UI_APP_LIST_EXTENSION_APP_MODEL_BUILDER_H_