blob: 33dadf0be71c1e47c017adfa4a7526580c071622 [file] [log] [blame]
[email protected]29679dea2012-03-10 03:20:281// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]655b2b1a2011-10-13 17:13:062// 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]655b2b1a2011-10-13 17:13:0619class Profile;
20
[email protected]cdcb1dee2012-01-04 00:46:2021namespace content {
22class NavigationController;
23}
24
[email protected]655b2b1a2011-10-13 17:13:0625// Downloads and installs extensions from the web store.
[email protected]98e4e522011-10-25 13:00:1626class WebstoreInstaller : public content::NotificationObserver,
27 public base::RefCounted<WebstoreInstaller> {
[email protected]655b2b1a2011-10-13 17:13:0628 public:
29 enum Flag {
30 FLAG_NONE = 0,
31
[email protected]99dfecd2011-10-18 01:11:5032 // Inline installs trigger slightly different behavior (install source
33 // is different, download referrers are the item's page in the gallery).
34 FLAG_INLINE_INSTALL = 1 << 0
[email protected]655b2b1a2011-10-13 17:13:0635 };
36
37 class Delegate {
38 public:
39 virtual void OnExtensionInstallSuccess(const std::string& id) = 0;
40 virtual void OnExtensionInstallFailure(const std::string& id,
41 const std::string& error) = 0;
42 };
43
[email protected]98e4e522011-10-25 13:00:1644
45 // Creates a WebstoreInstaller for downloading and installing the extension
46 // with the given |id| from the Chrome Web Store. If |delegate| is not NULL,
47 // it will be notified when the install succeeds or fails. The installer will
48 // use the specified |controller| to download the extension. Only one
49 // WebstoreInstaller can use a specific controller at any given time.
50 // Note: the delegate should stay alive until being called back.
51 WebstoreInstaller(Profile* profile,
52 Delegate* delegate,
[email protected]cdcb1dee2012-01-04 00:46:2053 content::NavigationController* controller,
[email protected]98e4e522011-10-25 13:00:1654 const std::string& id,
55 int flags);
[email protected]655b2b1a2011-10-13 17:13:0656 virtual ~WebstoreInstaller();
57
[email protected]98e4e522011-10-25 13:00:1658 // Starts downloading and installing the extension.
59 void Start();
[email protected]655b2b1a2011-10-13 17:13:0660
[email protected]6c2381d2011-10-19 02:52:5361 // content::NotificationObserver
[email protected]655b2b1a2011-10-13 17:13:0662 virtual void Observe(int type,
[email protected]6c2381d2011-10-19 02:52:5363 const content::NotificationSource& source,
64 const content::NotificationDetails& details) OVERRIDE;
[email protected]655b2b1a2011-10-13 17:13:0665
[email protected]9c265d02011-12-29 22:13:4366 // Instead of using the default download directory, use |directory| instead.
67 // This does *not* transfer ownership of |directory|.
68 static void SetDownloadDirectoryForTests(FilePath* directory);
69
[email protected]655b2b1a2011-10-13 17:13:0670 private:
[email protected]f66a50a2011-11-02 23:53:4671 // Starts downloading the extension to |file_path|.
[email protected]29679dea2012-03-10 03:20:2872 void StartDownload(const FilePath& file_path);
[email protected]f66a50a2011-11-02 23:53:4673
[email protected]655b2b1a2011-10-13 17:13:0674 // Reports an install |error| to the delegate for the given extension if this
75 // managed its installation. This also removes the associated PendingInstall.
[email protected]98e4e522011-10-25 13:00:1676 void ReportFailure(const std::string& error);
[email protected]655b2b1a2011-10-13 17:13:0677
78 // Reports a successful install to the delegate for the given extension if
79 // this managed its installation. This also removes the associated
80 // PendingInstall.
[email protected]98e4e522011-10-25 13:00:1681 void ReportSuccess();
[email protected]655b2b1a2011-10-13 17:13:0682
[email protected]6c2381d2011-10-19 02:52:5383 content::NotificationRegistrar registrar_;
[email protected]655b2b1a2011-10-13 17:13:0684 Profile* profile_;
[email protected]98e4e522011-10-25 13:00:1685 Delegate* delegate_;
[email protected]cdcb1dee2012-01-04 00:46:2086 content::NavigationController* controller_;
[email protected]98e4e522011-10-25 13:00:1687 std::string id_;
88 int flags_;
89 GURL download_url_;
[email protected]655b2b1a2011-10-13 17:13:0690};
91
92#endif // CHROME_BROWSER_EXTENSIONS_WEBSTORE_INSTALLER_H_