webstore_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_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 "chrome/common/extensions/webstore_install_result.h" 15#include "extensions/browser/extension_registry_observer.h" 16#include "extensions/common/manifest.h" 17#include "url/gurl.h" 18 19class AppListControllerDelegate; 20class Profile; 21 22namespace extensions { 23class ExtensionRegistry; 24class InstallTracker; 25} 26 27namespace app_list { 28 29class WebstoreResult : public ChromeSearchResult, 30 public extensions::InstallObserver, 31 public extensions::ExtensionRegistryObserver { 32 public: 33 WebstoreResult(Profile* profile, 34 const std::string& app_id, 35 const std::string& localized_name, 36 const GURL& icon_url, 37 extensions::Manifest::Type item_type, 38 AppListControllerDelegate* controller); 39 virtual ~WebstoreResult(); 40 41 const std::string& app_id() const { return app_id_; } 42 const GURL& icon_url() const { return icon_url_; } 43 extensions::Manifest::Type item_type() const { return item_type_; } 44 45 // ChromeSearchResult overides: 46 virtual void Open(int event_flags) OVERRIDE; 47 virtual void InvokeAction(int action_index, int event_flags) OVERRIDE; 48 virtual scoped_ptr<ChromeSearchResult> Duplicate() OVERRIDE; 49 virtual ChromeSearchResultType GetType() OVERRIDE; 50 51 private: 52 // Set the initial state and start observing both InstallObserver and 53 // ExtensionRegistryObserver. 54 void InitAndStartObserving(); 55 56 void UpdateActions(); 57 void SetDefaultDetails(); 58 void OnIconLoaded(); 59 60 void StartInstall(bool launch_ephemeral_app); 61 void InstallCallback(bool success, 62 const std::string& error, 63 extensions::webstore_install::Result result); 64 void LaunchCallback(extensions::webstore_install::Result result, 65 const std::string& error); 66 67 void StopObservingInstall(); 68 void StopObservingRegistry(); 69 70 // extensions::InstallObserver overrides: 71 virtual void OnDownloadProgress(const std::string& extension_id, 72 int percent_downloaded) OVERRIDE; 73 virtual void OnShutdown() OVERRIDE; 74 75 // extensions::ExtensionRegistryObserver overides: 76 virtual void OnExtensionInstalled( 77 content::BrowserContext* browser_context, 78 const extensions::Extension* extension, 79 bool is_update) OVERRIDE; 80 virtual void OnShutdown(extensions::ExtensionRegistry* registry) OVERRIDE; 81 82 Profile* profile_; 83 const std::string app_id_; 84 const std::string localized_name_; 85 const GURL icon_url_; 86 extensions::Manifest::Type item_type_; 87 88 gfx::ImageSkia icon_; 89 90 AppListControllerDelegate* controller_; 91 extensions::InstallTracker* install_tracker_; // Not owned. 92 extensions::ExtensionRegistry* extension_registry_; // Not owned. 93 94 base::WeakPtrFactory<WebstoreResult> weak_factory_; 95 96 DISALLOW_COPY_AND_ASSIGN(WebstoreResult); 97}; 98 99} // namespace app_list 100 101#endif // CHROME_BROWSER_UI_APP_LIST_SEARCH_WEBSTORE_WEBSTORE_RESULT_H_ 102