blob: ef2bbbc52c4a4d22390fa5263bf51103a940a50c [file] [log] [blame]
[email protected]655b2b1a2011-10-13 17:13:061// Copyright (c) 2011 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_EXTENSIONS_WEBSTORE_INSTALLER_H_
6#define CHROME_BROWSER_EXTENSIONS_WEBSTORE_INSTALLER_H_
7#pragma once
8
9#include <string>
10#include <vector>
11
12#include "base/compiler_specific.h"
[email protected]98e4e522011-10-25 13:00:1613#include "base/memory/ref_counted.h"
[email protected]6c2381d2011-10-19 02:52:5314#include "content/public/browser/notification_observer.h"
15#include "content/public/browser/notification_registrar.h"
[email protected]98e4e522011-10-25 13:00:1616#include "googleurl/src/gurl.h"
[email protected]655b2b1a2011-10-13 17:13:0617
[email protected]f66a50a2011-11-02 23:53:4618class FilePath;
[email protected]98e4e522011-10-25 13:00:1619class NavigationController;
[email protected]655b2b1a2011-10-13 17:13:0620class Profile;
21
22// Downloads and installs extensions from the web store.
[email protected]98e4e522011-10-25 13:00:1623class WebstoreInstaller : public content::NotificationObserver,
24 public base::RefCounted<WebstoreInstaller> {
[email protected]655b2b1a2011-10-13 17:13:0625 public:
26 enum Flag {
27 FLAG_NONE = 0,
28
[email protected]99dfecd2011-10-18 01:11:5029 // Inline installs trigger slightly different behavior (install source
30 // is different, download referrers are the item's page in the gallery).
31 FLAG_INLINE_INSTALL = 1 << 0
[email protected]655b2b1a2011-10-13 17:13:0632 };
33
34 class Delegate {
35 public:
36 virtual void OnExtensionInstallSuccess(const std::string& id) = 0;
37 virtual void OnExtensionInstallFailure(const std::string& id,
38 const std::string& error) = 0;
39 };
40
[email protected]98e4e522011-10-25 13:00:1641
42 // Creates a WebstoreInstaller for downloading and installing the extension
43 // with the given |id| from the Chrome Web Store. If |delegate| is not NULL,
44 // it will be notified when the install succeeds or fails. The installer will
45 // use the specified |controller| to download the extension. Only one
46 // WebstoreInstaller can use a specific controller at any given time.
47 // Note: the delegate should stay alive until being called back.
48 WebstoreInstaller(Profile* profile,
49 Delegate* delegate,
50 NavigationController* controller,
51 const std::string& id,
52 int flags);
[email protected]655b2b1a2011-10-13 17:13:0653 virtual ~WebstoreInstaller();
54
[email protected]98e4e522011-10-25 13:00:1655 // Starts downloading and installing the extension.
56 void Start();
[email protected]655b2b1a2011-10-13 17:13:0657
[email protected]6c2381d2011-10-19 02:52:5358 // content::NotificationObserver
[email protected]655b2b1a2011-10-13 17:13:0659 virtual void Observe(int type,
[email protected]6c2381d2011-10-19 02:52:5360 const content::NotificationSource& source,
61 const content::NotificationDetails& details) OVERRIDE;
[email protected]655b2b1a2011-10-13 17:13:0662
63 private:
[email protected]f66a50a2011-11-02 23:53:4664 // Starts downloading the extension to |file_path|.
65 void StartDownload(FilePath file_path);
66
[email protected]655b2b1a2011-10-13 17:13:0667 // Reports an install |error| to the delegate for the given extension if this
68 // managed its installation. This also removes the associated PendingInstall.
[email protected]98e4e522011-10-25 13:00:1669 void ReportFailure(const std::string& error);
[email protected]655b2b1a2011-10-13 17:13:0670
71 // Reports a successful install to the delegate for the given extension if
72 // this managed its installation. This also removes the associated
73 // PendingInstall.
[email protected]98e4e522011-10-25 13:00:1674 void ReportSuccess();
[email protected]655b2b1a2011-10-13 17:13:0675
[email protected]6c2381d2011-10-19 02:52:5376 content::NotificationRegistrar registrar_;
[email protected]655b2b1a2011-10-13 17:13:0677 Profile* profile_;
[email protected]98e4e522011-10-25 13:00:1678 Delegate* delegate_;
79 NavigationController* controller_;
80 std::string id_;
81 int flags_;
82 GURL download_url_;
[email protected]655b2b1a2011-10-13 17:13:0683};
84
85#endif // CHROME_BROWSER_EXTENSIONS_WEBSTORE_INSTALLER_H_