extension_app_model_builder.h revision a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7
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 private: 41 typedef std::vector<ExtensionAppItem*> ExtensionAppList; 42 43 // Builds the model with the current profile. 44 void BuildModel(); 45 46 // extensions::InstallObserver 47 virtual void OnBeginExtensionInstall( 48 const ExtensionInstallParams& params) OVERRIDE; 49 virtual void OnDownloadProgress(const std::string& extension_id, 50 int percent_downloaded) OVERRIDE; 51 virtual void OnInstallFailure(const std::string& extension_id) OVERRIDE; 52 virtual void OnExtensionInstalled( 53 const extensions::Extension* extension) OVERRIDE {} 54 virtual void OnExtensionLoaded( 55 const extensions::Extension* extension) OVERRIDE; 56 virtual void OnExtensionUnloaded( 57 const extensions::Extension* extension) OVERRIDE; 58 virtual void OnExtensionUninstalled( 59 const extensions::Extension* extension) OVERRIDE; 60 virtual void OnAppsReordered() OVERRIDE; 61 virtual void OnAppInstalledToAppList( 62 const std::string& extension_id) OVERRIDE; 63 virtual void OnShutdown() OVERRIDE; 64 65 // AppListItemListObserver 66 virtual void OnListItemMoved(size_t from_index, 67 size_t to_index, 68 app_list::AppListItemModel* item) OVERRIDE; 69 70 // Adds apps in |extensions| to |apps|. 71 void AddApps(const ExtensionSet* extensions, ExtensionAppList* apps); 72 73 // Populates the model with apps. 74 void PopulateApps(); 75 76 // Re-sort apps in case app ordinal prefs are changed. 77 void ResortApps(); 78 79 // Inserts an app based on app ordinal prefs. 80 void InsertApp(ExtensionAppItem* app); 81 82 // Sets which app is intended to be highlighted. Will remove the highlight 83 // from a currently highlighted app. 84 void SetHighlightedApp(const std::string& extension_id); 85 86 // Sets the application app with |highlight_app_id_| in |model_| as 87 // highlighted if |highlighted_app_pending_| is true. If such an app is found, 88 // reset |highlighted_app_pending_| so that won't be highlighted again until 89 // another call to SetHighlightedApp() is made. 90 void UpdateHighlight(); 91 92 // Returns app instance matching |extension_id| or NULL. 93 ExtensionAppItem* GetExtensionAppItem(const std::string& extension_id); 94 95 Profile* profile_; 96 97 // Unowned pointer to the app list controller. 98 AppListControllerDelegate* controller_; 99 100 // Unowned pointer to the app list model. 101 app_list::AppListModel* model_; 102 103 std::string highlight_app_id_; 104 105 // True if we haven't set |highlight_app_id_| to be highlighted. This happens 106 // if we try to highlight an app that doesn't exist in the list yet. 107 bool highlighted_app_pending_; 108 109 // We listen to this to show app installing progress. 110 extensions::InstallTracker* tracker_; 111 112 DISALLOW_COPY_AND_ASSIGN(ExtensionAppModelBuilder); 113}; 114 115#endif // CHROME_BROWSER_UI_APP_LIST_EXTENSION_APP_MODEL_BUILDER_H_ 116