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