app_result.h revision 5f1c94371a64b3196d4be9466099bb892df9b88e
1// Copyright 2013 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_SEARCH_APP_RESULT_H_ 6#define CHROME_BROWSER_UI_APP_LIST_SEARCH_APP_RESULT_H_ 7 8#include <string> 9 10#include "base/memory/scoped_ptr.h" 11#include "chrome/browser/ui/app_list/app_context_menu_delegate.h" 12#include "chrome/browser/ui/app_list/search/chrome_search_result.h" 13#include "chrome/browser/ui/extensions/extension_enable_flow_delegate.h" 14#include "extensions/browser/extension_icon_image.h" 15#include "extensions/browser/extension_registry_observer.h" 16 17class AppListControllerDelegate; 18class ExtensionEnableFlow; 19class Profile; 20 21namespace base { 22class Time; 23} 24 25namespace extensions { 26class ExtensionRegistry; 27} 28 29namespace app_list { 30 31class AppContextMenu; 32class TokenizedString; 33class TokenizedStringMatch; 34 35class AppResult : public ChromeSearchResult, 36 public extensions::IconImage::Observer, 37 public AppContextMenuDelegate, 38 public ExtensionEnableFlowDelegate, 39 public extensions::ExtensionRegistryObserver { 40 public: 41 AppResult(Profile* profile, 42 const std::string& app_id, 43 AppListControllerDelegate* controller); 44 virtual ~AppResult(); 45 46 void UpdateFromMatch(const TokenizedString& title, 47 const TokenizedStringMatch& match); 48 49 void UpdateFromLastLaunched(const base::Time& current_time, 50 const base::Time& last_launched); 51 52 // ChromeSearchResult overides: 53 virtual void Open(int event_flags) OVERRIDE; 54 virtual void InvokeAction(int action_index, int event_flags) OVERRIDE; 55 virtual scoped_ptr<ChromeSearchResult> Duplicate() OVERRIDE; 56 virtual ui::MenuModel* GetContextMenuModel() OVERRIDE; 57 virtual ChromeSearchResultType GetType() OVERRIDE; 58 59 private: 60 void StartObservingExtensionRegistry(); 61 void StopObservingExtensionRegistry(); 62 63 // Checks if extension is disabled and if enable flow should be started. 64 // Returns true if extension enable flow is started or there is already one 65 // running. 66 bool RunExtensionEnableFlow(); 67 68 // Updates the app item's icon, if necessary making it gray. 69 void UpdateIcon(); 70 71 // extensions::IconImage::Observer overrides: 72 virtual void OnExtensionIconImageChanged( 73 extensions::IconImage* image) OVERRIDE; 74 75 // AppContextMenuDelegate overrides: 76 virtual void ExecuteLaunchCommand(int event_flags) OVERRIDE; 77 78 // ExtensionEnableFlowDelegate overrides: 79 virtual void ExtensionEnableFlowFinished() OVERRIDE; 80 virtual void ExtensionEnableFlowAborted(bool user_initiated) OVERRIDE; 81 82 // extensions::ExtensionRegistryObserver override: 83 virtual void OnExtensionLoaded( 84 content::BrowserContext* browser_context, 85 const extensions::Extension* extension) OVERRIDE; 86 virtual void OnExtensionUninstalled( 87 content::BrowserContext* browser_context, 88 const extensions::Extension* extension, 89 extensions::UninstallReason reason) OVERRIDE; 90 virtual void OnShutdown(extensions::ExtensionRegistry* registry) OVERRIDE; 91 92 Profile* profile_; 93 const std::string app_id_; 94 AppListControllerDelegate* controller_; 95 96 bool is_platform_app_; 97 scoped_ptr<extensions::IconImage> icon_; 98 scoped_ptr<AppContextMenu> context_menu_; 99 scoped_ptr<ExtensionEnableFlow> extension_enable_flow_; 100 101 extensions::ExtensionRegistry* extension_registry_; 102 103 DISALLOW_COPY_AND_ASSIGN(AppResult); 104}; 105 106} // namespace app_list 107 108#endif // CHROME_BROWSER_UI_APP_LIST_SEARCH_APP_RESULT_H_ 109