webstore_result.h revision f8ee788a64d60abd8f2d742a5fdedde054ecd910
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_WEBSTORE_WEBSTORE_RESULT_H_ 6#define CHROME_BROWSER_UI_APP_LIST_SEARCH_WEBSTORE_WEBSTORE_RESULT_H_ 7 8#include <string> 9 10#include "base/basictypes.h" 11#include "base/memory/weak_ptr.h" 12#include "chrome/browser/extensions/install_observer.h" 13#include "chrome/browser/ui/app_list/search/chrome_search_result.h" 14#include "extensions/browser/extension_registry_observer.h" 15#include "url/gurl.h" 16 17class AppListControllerDelegate; 18class Profile; 19 20namespace extensions { 21class ExtensionRegistry; 22class InstallTracker; 23} 24 25namespace app_list { 26 27class WebstoreResult : public ChromeSearchResult, 28 public extensions::InstallObserver, 29 public extensions::ExtensionRegistryObserver { 30 public: 31 WebstoreResult(Profile* profile, 32 const std::string& app_id, 33 const std::string& localized_name, 34 const GURL& icon_url, 35 AppListControllerDelegate* controller); 36 virtual ~WebstoreResult(); 37 38 // ChromeSearchResult overides: 39 virtual void Open(int event_flags) OVERRIDE; 40 virtual void InvokeAction(int action_index, int event_flags) OVERRIDE; 41 virtual scoped_ptr<ChromeSearchResult> Duplicate() OVERRIDE; 42 virtual ChromeSearchResultType GetType() OVERRIDE; 43 44 private: 45 void UpdateActions(); 46 void SetDefaultDetails(); 47 void OnIconLoaded(); 48 49 void StartInstall(bool launch_ephemeral_app); 50 void InstallCallback(bool success, const std::string& error); 51 52 // Start observing both InstallObserver and ExtensionRegistryObserver. 53 void StartObserving(); 54 55 void StopObservingInstall(); 56 void StopObservingRegistry(); 57 58 // extensions::InstallObserver overrides: 59 virtual void OnDownloadProgress(const std::string& extension_id, 60 int percent_downloaded) OVERRIDE; 61 virtual void OnShutdown() OVERRIDE; 62 63 // extensions::ExtensionRegistryObserver overides: 64 virtual void OnExtensionWillBeInstalled( 65 content::BrowserContext* browser_context, 66 const extensions::Extension* extension, 67 bool is_update, 68 bool from_ephemeral, 69 const std::string& old_name) OVERRIDE; 70 virtual void OnShutdown(extensions::ExtensionRegistry* registry) OVERRIDE; 71 72 Profile* profile_; 73 const std::string app_id_; 74 const std::string localized_name_; 75 const GURL icon_url_; 76 77 gfx::ImageSkia icon_; 78 base::WeakPtrFactory<WebstoreResult> weak_factory_; 79 80 AppListControllerDelegate* controller_; 81 extensions::InstallTracker* install_tracker_; // Not owned. 82 extensions::ExtensionRegistry* extension_registry_; // Not owned. 83 84 DISALLOW_COPY_AND_ASSIGN(WebstoreResult); 85}; 86 87} // namespace app_list 88 89#endif // CHROME_BROWSER_UI_APP_LIST_SEARCH_WEBSTORE_WEBSTORE_RESULT_H_ 90