webstore_result.h revision a1401311d1ab56c4ed0a474bd38c108f75cb0cd9
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 "url/gurl.h"
15
16class AppListControllerDelegate;
17class Profile;
18
19namespace extensions {
20class InstallTracker;
21}
22
23namespace app_list {
24
25class WebstoreResult : public ChromeSearchResult,
26                       public extensions::InstallObserver {
27 public:
28  WebstoreResult(Profile* profile,
29                 const std::string& app_id,
30                 const std::string& localized_name,
31                 const GURL& icon_url,
32                 AppListControllerDelegate* controller);
33  virtual ~WebstoreResult();
34
35  // ChromeSearchResult overides:
36  virtual void Open(int event_flags) OVERRIDE;
37  virtual void InvokeAction(int action_index, int event_flags) OVERRIDE;
38  virtual scoped_ptr<ChromeSearchResult> Duplicate() OVERRIDE;
39  virtual ChromeSearchResultType GetType() OVERRIDE;
40
41 private:
42  void UpdateActions();
43  void SetDefaultDetails();
44  void OnIconLoaded();
45
46  void StartInstall(bool launch_ephemeral_app);
47  void InstallCallback(bool success, const std::string& error);
48
49  void StartObservingInstall();
50  void StopObservingInstall();
51
52  // extensions::InstallObserver overrides:
53  virtual void OnDownloadProgress(const std::string& extension_id,
54                                  int percent_downloaded) OVERRIDE;
55  virtual void OnExtensionInstalled(
56      const extensions::Extension* extension) OVERRIDE;
57  virtual void OnShutdown() OVERRIDE;
58
59  Profile* profile_;
60  const std::string app_id_;
61  const std::string localized_name_;
62  const GURL icon_url_;
63
64  gfx::ImageSkia icon_;
65  base::WeakPtrFactory<WebstoreResult> weak_factory_;
66
67  AppListControllerDelegate* controller_;
68  extensions::InstallTracker* install_tracker_;  // Not owned.
69
70  DISALLOW_COPY_AND_ASSIGN(WebstoreResult);
71};
72
73}  // namespace app_list
74
75#endif  // CHROME_BROWSER_UI_APP_LIST_SEARCH_WEBSTORE_WEBSTORE_RESULT_H_
76