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 "base/prefs/pref_change_registrar.h"
13 #include "chrome/browser/extensions/install_observer.h"
14 #include "ui/app_list/app_list_model.h"
15 #include "ui/base/models/list_model_observer.h"
17 class AppListControllerDelegate
;
18 class ExtensionAppItem
;
22 class AppListSyncableService
;
25 namespace extensions
{
35 // This class populates and maintains the given |model| with information from
37 class ExtensionAppModelBuilder
: public extensions::InstallObserver
,
38 public app_list::AppListItemListObserver
{
40 explicit ExtensionAppModelBuilder(AppListControllerDelegate
* controller
);
41 virtual ~ExtensionAppModelBuilder();
43 // Initialize to use app-list sync and sets |service_| to |service|.
44 void InitializeWithService(app_list::AppListSyncableService
* service
);
46 // Initialize to use extension sync and sets |service_| to NULL. Used in
47 // tests and when AppList sync is not enabled.
48 void InitializeWithProfile(Profile
* profile
, app_list::AppListModel
* model
);
51 typedef std::vector
<ExtensionAppItem
*> ExtensionAppList
;
53 // Builds the model with the current profile.
56 // extensions::InstallObserver
57 virtual void OnBeginExtensionInstall(
58 const ExtensionInstallParams
& params
) OVERRIDE
;
59 virtual void OnDownloadProgress(const std::string
& extension_id
,
60 int percent_downloaded
) OVERRIDE
;
61 virtual void OnInstallFailure(const std::string
& extension_id
) OVERRIDE
;
62 virtual void OnExtensionInstalled(
63 const extensions::Extension
* extension
) OVERRIDE
{}
64 virtual void OnExtensionLoaded(
65 const extensions::Extension
* extension
) OVERRIDE
;
66 virtual void OnExtensionUnloaded(
67 const extensions::Extension
* extension
) OVERRIDE
;
68 virtual void OnExtensionUninstalled(
69 const extensions::Extension
* extension
) OVERRIDE
;
70 virtual void OnAppsReordered() OVERRIDE
;
71 virtual void OnAppInstalledToAppList(
72 const std::string
& extension_id
) OVERRIDE
;
73 virtual void OnShutdown() OVERRIDE
;
75 // AppListItemListObserver
76 virtual void OnListItemMoved(size_t from_index
,
78 app_list::AppListItem
* item
) OVERRIDE
;
80 scoped_ptr
<ExtensionAppItem
> CreateAppItem(
81 const std::string
& extension_id
,
82 const std::string
& extension_name
,
83 const gfx::ImageSkia
& installing_icon
,
84 bool is_platform_app
);
86 // Populates the model with apps.
89 // Re-sort apps in case app ordinal prefs are changed.
92 // Inserts an app based on app ordinal prefs.
93 void InsertApp(scoped_ptr
<ExtensionAppItem
> app
);
95 // Sets which app is intended to be highlighted. Will remove the highlight
96 // from a currently highlighted app.
97 void SetHighlightedApp(const std::string
& extension_id
);
99 // Sets the application app with |highlight_app_id_| in |model_| as
100 // highlighted if |highlighted_app_pending_| is true. If such an app is found,
101 // reset |highlighted_app_pending_| so that won't be highlighted again until
102 // another call to SetHighlightedApp() is made.
103 void UpdateHighlight();
105 // Returns app instance matching |extension_id| or NULL.
106 ExtensionAppItem
* GetExtensionAppItem(const std::string
& extension_id
);
108 // Initializes the |extension_pref_change_registrar| to listen for extension
109 // prefs changes. OnExtensionPreferenceChanged() is called when extension
111 void InitializePrefChangeRegistrar();
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_
;
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 std::string highlight_app_id_
;
131 // True if we haven't set |highlight_app_id_| to be highlighted. This happens
132 // if we try to highlight an app that doesn't exist in the list yet.
133 bool highlighted_app_pending_
;
135 // We listen to this to show app installing progress.
136 extensions::InstallTracker
* tracker_
;
138 DISALLOW_COPY_AND_ASSIGN(ExtensionAppModelBuilder
);
141 #endif // CHROME_BROWSER_UI_APP_LIST_EXTENSION_APP_MODEL_BUILDER_H_