webstore_result.h revision 6e8cce623b6e4fe0c9e4af605d675dd9d0338c38
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                 bool is_paid,
38                 extensions::Manifest::Type item_type,
39                 AppListControllerDelegate* controller);
40  virtual ~WebstoreResult();
41
42  const std::string& app_id() const { return app_id_; }
43  const GURL& icon_url() const { return icon_url_; }
44  extensions::Manifest::Type item_type() const { return item_type_; }
45  bool is_paid() const { return is_paid_; }
46
47  // ChromeSearchResult overides:
48  virtual void Open(int event_flags) OVERRIDE;
49  virtual void InvokeAction(int action_index, int event_flags) OVERRIDE;
50  virtual scoped_ptr<ChromeSearchResult> Duplicate() OVERRIDE;
51  virtual ChromeSearchResultType GetType() OVERRIDE;
52
53 private:
54  // Set the initial state and start observing both InstallObserver and
55  // ExtensionRegistryObserver.
56  void InitAndStartObserving();
57
58  void UpdateActions();
59  void SetDefaultDetails();
60  void OnIconLoaded();
61
62  void StartInstall(bool launch_ephemeral_app);
63  void InstallCallback(bool success,
64                       const std::string& error,
65                       extensions::webstore_install::Result result);
66  void LaunchCallback(extensions::webstore_install::Result result,
67                      const std::string& error);
68
69  void StopObservingInstall();
70  void StopObservingRegistry();
71
72  // extensions::InstallObserver overrides:
73  virtual void OnDownloadProgress(const std::string& extension_id,
74                                  int percent_downloaded) OVERRIDE;
75  virtual void OnShutdown() OVERRIDE;
76
77  // extensions::ExtensionRegistryObserver overides:
78  virtual void OnExtensionInstalled(
79      content::BrowserContext* browser_context,
80      const extensions::Extension* extension,
81      bool is_update) OVERRIDE;
82  virtual void OnShutdown(extensions::ExtensionRegistry* registry) OVERRIDE;
83
84  Profile* profile_;
85  const std::string app_id_;
86  const std::string localized_name_;
87  const GURL icon_url_;
88  const bool is_paid_;
89  extensions::Manifest::Type item_type_;
90
91  gfx::ImageSkia icon_;
92
93  AppListControllerDelegate* controller_;
94  extensions::InstallTracker* install_tracker_;  // Not owned.
95  extensions::ExtensionRegistry* extension_registry_;  // Not owned.
96
97  base::WeakPtrFactory<WebstoreResult> weak_factory_;
98
99  DISALLOW_COPY_AND_ASSIGN(WebstoreResult);
100};
101
102}  // namespace app_list
103
104#endif  // CHROME_BROWSER_UI_APP_LIST_SEARCH_WEBSTORE_WEBSTORE_RESULT_H_
105