| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_UI_APP_LIST_EXTENSION_APP_MODEL_BUILDER_H_ | 5 #ifndef CHROME_BROWSER_UI_APP_LIST_EXTENSION_APP_MODEL_BUILDER_H_ |
| 6 #define CHROME_BROWSER_UI_APP_LIST_EXTENSION_APP_MODEL_BUILDER_H_ | 6 #define CHROME_BROWSER_UI_APP_LIST_EXTENSION_APP_MODEL_BUILDER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
| 12 #include "base/prefs/pref_change_registrar.h" | 12 #include "base/prefs/pref_change_registrar.h" |
| 13 #include "base/scoped_observer.h" |
| 13 #include "chrome/browser/extensions/install_observer.h" | 14 #include "chrome/browser/extensions/install_observer.h" |
| 15 #include "extensions/browser/extension_registry_observer.h" |
| 14 #include "ui/app_list/app_list_model.h" | 16 #include "ui/app_list/app_list_model.h" |
| 15 #include "ui/base/models/list_model_observer.h" | 17 #include "ui/base/models/list_model_observer.h" |
| 16 | 18 |
| 17 class AppListControllerDelegate; | 19 class AppListControllerDelegate; |
| 18 class ExtensionAppItem; | 20 class ExtensionAppItem; |
| 19 class Profile; | 21 class Profile; |
| 20 | 22 |
| 21 namespace app_list { | 23 namespace app_list { |
| 22 class AppListSyncableService; | 24 class AppListSyncableService; |
| 23 } | 25 } |
| 24 | 26 |
| 25 namespace extensions { | 27 namespace extensions { |
| 26 class Extension; | 28 class Extension; |
| 29 class ExtensionRegistry; |
| 27 class ExtensionSet; | 30 class ExtensionSet; |
| 28 class InstallTracker; | 31 class InstallTracker; |
| 29 } | 32 } |
| 30 | 33 |
| 31 namespace gfx { | 34 namespace gfx { |
| 32 class ImageSkia; | 35 class ImageSkia; |
| 33 } | 36 } |
| 34 | 37 |
| 35 // This class populates and maintains the given |model| with information from | 38 // This class populates and maintains the given |model| with information from |
| 36 // |profile|. | 39 // |profile|. |
| 37 class ExtensionAppModelBuilder : public extensions::InstallObserver, | 40 class ExtensionAppModelBuilder : public extensions::InstallObserver, |
| 41 public extensions::ExtensionRegistryObserver, |
| 38 public app_list::AppListItemListObserver { | 42 public app_list::AppListItemListObserver { |
| 39 public: | 43 public: |
| 40 explicit ExtensionAppModelBuilder(AppListControllerDelegate* controller); | 44 explicit ExtensionAppModelBuilder(AppListControllerDelegate* controller); |
| 41 virtual ~ExtensionAppModelBuilder(); | 45 virtual ~ExtensionAppModelBuilder(); |
| 42 | 46 |
| 43 // Initialize to use app-list sync and sets |service_| to |service|. | 47 // Initialize to use app-list sync and sets |service_| to |service|. |
| 44 void InitializeWithService(app_list::AppListSyncableService* service); | 48 void InitializeWithService(app_list::AppListSyncableService* service); |
| 45 | 49 |
| 46 // Initialize to use extension sync and sets |service_| to NULL. Used in | 50 // Initialize to use extension sync and sets |service_| to NULL. Used in |
| 47 // tests and when AppList sync is not enabled. | 51 // tests and when AppList sync is not enabled. |
| 48 void InitializeWithProfile(Profile* profile, app_list::AppListModel* model); | 52 void InitializeWithProfile(Profile* profile, app_list::AppListModel* model); |
| 49 | 53 |
| 50 private: | 54 private: |
| 51 typedef std::vector<ExtensionAppItem*> ExtensionAppList; | 55 typedef std::vector<ExtensionAppItem*> ExtensionAppList; |
| 52 | 56 |
| 53 // Builds the model with the current profile. | 57 // Builds the model with the current profile. |
| 54 void BuildModel(); | 58 void BuildModel(); |
| 55 | 59 |
| 56 // extensions::InstallObserver | 60 // extensions::InstallObserver. |
| 57 virtual void OnBeginExtensionInstall( | 61 virtual void OnBeginExtensionInstall( |
| 58 const ExtensionInstallParams& params) OVERRIDE; | 62 const ExtensionInstallParams& params) OVERRIDE; |
| 59 virtual void OnDownloadProgress(const std::string& extension_id, | 63 virtual void OnDownloadProgress(const std::string& extension_id, |
| 60 int percent_downloaded) OVERRIDE; | 64 int percent_downloaded) OVERRIDE; |
| 61 virtual void OnInstallFailure(const std::string& extension_id) OVERRIDE; | 65 virtual void OnInstallFailure(const std::string& extension_id) OVERRIDE; |
| 62 virtual void OnExtensionLoaded( | |
| 63 const extensions::Extension* extension) OVERRIDE; | |
| 64 virtual void OnExtensionUnloaded( | |
| 65 const extensions::Extension* extension) OVERRIDE; | |
| 66 virtual void OnExtensionUninstalled( | |
| 67 const extensions::Extension* extension) OVERRIDE; | |
| 68 virtual void OnDisabledExtensionUpdated( | 66 virtual void OnDisabledExtensionUpdated( |
| 69 const extensions::Extension* extension) OVERRIDE; | 67 const extensions::Extension* extension) OVERRIDE; |
| 70 virtual void OnAppInstalledToAppList( | 68 virtual void OnAppInstalledToAppList( |
| 71 const std::string& extension_id) OVERRIDE; | 69 const std::string& extension_id) OVERRIDE; |
| 70 |
| 71 // extensions::ExtensionRegistryObserver. |
| 72 virtual void OnExtensionLoaded( |
| 73 content::BrowserContext* browser_context, |
| 74 const extensions::Extension* extension) OVERRIDE; |
| 75 virtual void OnExtensionUnloaded( |
| 76 content::BrowserContext* browser_context, |
| 77 const extensions::Extension* extension, |
| 78 extensions::UnloadedExtensionInfo::Reason reason) OVERRIDE; |
| 79 virtual void OnExtensionUninstalled( |
| 80 content::BrowserContext* browser_context, |
| 81 const extensions::Extension* extension) OVERRIDE; |
| 82 |
| 72 virtual void OnShutdown() OVERRIDE; | 83 virtual void OnShutdown() OVERRIDE; |
| 73 | 84 |
| 74 // AppListItemListObserver | 85 // AppListItemListObserver. |
| 75 virtual void OnListItemMoved(size_t from_index, | 86 virtual void OnListItemMoved(size_t from_index, |
| 76 size_t to_index, | 87 size_t to_index, |
| 77 app_list::AppListItem* item) OVERRIDE; | 88 app_list::AppListItem* item) OVERRIDE; |
| 78 | 89 |
| 79 scoped_ptr<ExtensionAppItem> CreateAppItem( | 90 scoped_ptr<ExtensionAppItem> CreateAppItem( |
| 80 const std::string& extension_id, | 91 const std::string& extension_id, |
| 81 const std::string& extension_name, | 92 const std::string& extension_name, |
| 82 const gfx::ImageSkia& installing_icon, | 93 const gfx::ImageSkia& installing_icon, |
| 83 bool is_platform_app); | 94 bool is_platform_app); |
| 84 | 95 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 | 138 |
| 128 std::string highlight_app_id_; | 139 std::string highlight_app_id_; |
| 129 | 140 |
| 130 // True if we haven't set |highlight_app_id_| to be highlighted. This happens | 141 // True if we haven't set |highlight_app_id_| to be highlighted. This happens |
| 131 // if we try to highlight an app that doesn't exist in the list yet. | 142 // if we try to highlight an app that doesn't exist in the list yet. |
| 132 bool highlighted_app_pending_; | 143 bool highlighted_app_pending_; |
| 133 | 144 |
| 134 // We listen to this to show app installing progress. | 145 // We listen to this to show app installing progress. |
| 135 extensions::InstallTracker* tracker_; | 146 extensions::InstallTracker* tracker_; |
| 136 | 147 |
| 148 // Listen extension's load, unload, uninstalled. |
| 149 extensions::ExtensionRegistry* extension_registry_; |
| 150 |
| 137 DISALLOW_COPY_AND_ASSIGN(ExtensionAppModelBuilder); | 151 DISALLOW_COPY_AND_ASSIGN(ExtensionAppModelBuilder); |
| 138 }; | 152 }; |
| 139 | 153 |
| 140 #endif // CHROME_BROWSER_UI_APP_LIST_EXTENSION_APP_MODEL_BUILDER_H_ | 154 #endif // CHROME_BROWSER_UI_APP_LIST_EXTENSION_APP_MODEL_BUILDER_H_ |
| OLD | NEW |