extension_app_model_builder.h revision 1e9bf3e0803691d0a228da41fc608347b6db4340
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. 4 5#ifndef CHROME_BROWSER_UI_APP_LIST_EXTENSION_APP_MODEL_BUILDER_H_ 6#define CHROME_BROWSER_UI_APP_LIST_EXTENSION_APP_MODEL_BUILDER_H_ 7 8#include <string> 9#include <vector> 10 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" 15 16class AppListControllerDelegate; 17class ExtensionAppItem; 18class ExtensionSet; 19class Profile; 20 21namespace extensions { 22class Extension; 23class InstallTracker; 24} 25 26namespace gfx { 27class ImageSkia; 28} 29 30// This class populates and maintains the given |model| with information from 31// |profile|. 32class ExtensionAppModelBuilder : public extensions::InstallObserver, 33 public app_list::AppListItemListObserver { 34 public: 35 ExtensionAppModelBuilder(Profile* profile, 36 app_list::AppListModel* model, 37 AppListControllerDelegate* controller); 38 virtual ~ExtensionAppModelBuilder(); 39 40 // Rebuilds the model with the given profile. 41 void SwitchProfile(Profile* profile); 42 43 private: 44 typedef std::vector<ExtensionAppItem*> ExtensionAppList; 45 46 // extensions::InstallObserver 47 virtual void OnBeginExtensionInstall(const std::string& extension_id, 48 const std::string& extension_name, 49 const gfx::ImageSkia& installing_icon, 50 bool is_app, 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; 67 68 // AppListItemListObserver 69 virtual void OnListItemMoved(size_t from_index, 70 size_t to_index, 71 app_list::AppListItemModel* item) OVERRIDE; 72 73 // Adds apps in |extensions| to |apps|. 74 void AddApps(const ExtensionSet* extensions, ExtensionAppList* apps); 75 76 // Populates the model with apps. 77 void PopulateApps(); 78 79 // Re-sort apps in case app ordinal prefs are changed. 80 void ResortApps(); 81 82 // Inserts an app based on app ordinal prefs. 83 void InsertApp(ExtensionAppItem* app); 84 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); 88 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(); 94 95 // Returns app instance matching |extension_id| or NULL. 96 ExtensionAppItem* GetExtensionAppItem(const std::string& extension_id); 97 98 Profile* profile_; 99 100 // Unowned pointer to the app list controller (passed to created items). 101 AppListControllerDelegate* controller_; 102 103 // Unowned pointer to the app list model. 104 app_list::AppListModel* model_; 105 106 std::string highlight_app_id_; 107 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_; 111 112 // We listen to this to show app installing progress. 113 extensions::InstallTracker* tracker_; 114 115 DISALLOW_COPY_AND_ASSIGN(ExtensionAppModelBuilder); 116}; 117 118#endif // CHROME_BROWSER_UI_APP_LIST_EXTENSION_APP_MODEL_BUILDER_H_ 119