blob: 4c81089688b384ba324c012a89e093abaf1d5b5e [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]6c2381d2011-10-19 02:52:5313#include "content/public/browser/notification_observer.h"
14#include "content/public/browser/notification_registrar.h"
[email protected]655b2b1a2011-10-13 17:13:0615
16class GURL;
17class Profile;
18
19// Downloads and installs extensions from the web store.
[email protected]6c2381d2011-10-19 02:52:5320class WebstoreInstaller : public content::NotificationObserver {
[email protected]655b2b1a2011-10-13 17:13:0621 public:
22 enum Flag {
23 FLAG_NONE = 0,
24
[email protected]99dfecd2011-10-18 01:11:5025 // Inline installs trigger slightly different behavior (install source
26 // is different, download referrers are the item's page in the gallery).
27 FLAG_INLINE_INSTALL = 1 << 0
[email protected]655b2b1a2011-10-13 17:13:0628 };
29
30 class Delegate {
31 public:
32 virtual void OnExtensionInstallSuccess(const std::string& id) = 0;
33 virtual void OnExtensionInstallFailure(const std::string& id,
34 const std::string& error) = 0;
35 };
36
37 explicit WebstoreInstaller(Profile* profile);
38 virtual ~WebstoreInstaller();
39
40 // Download and install the extension with the given |id| from the Chrome
41 // Web Store. If |delegate| is not NULL, it will be notified when the
42 // install succeeds or fails.
43 // Note: the delegate should stay alive until being called back.
44 void InstallExtension(const std::string& id, Delegate* delegate, int flags);
45
[email protected]6c2381d2011-10-19 02:52:5346 // content::NotificationObserver
[email protected]655b2b1a2011-10-13 17:13:0647 virtual void Observe(int type,
[email protected]6c2381d2011-10-19 02:52:5348 const content::NotificationSource& source,
49 const content::NotificationDetails& details) OVERRIDE;
[email protected]655b2b1a2011-10-13 17:13:0650
51 private:
52 struct PendingInstall;
53
54 // Removes the PendingIntall data for the given extension, returning true and
55 // setting |install| if there is such data.
56 bool ClearPendingInstall(const std::string& id, PendingInstall* install);
57
58 // Creates the PendingInstall for the specified extension.
59 const PendingInstall& CreatePendingInstall(
[email protected]99dfecd2011-10-18 01:11:5060 const std::string& id, GURL install_url, Delegate* delegate);
[email protected]655b2b1a2011-10-13 17:13:0661
62 // Gets the extension id for the given gallery install |url|.
63 std::string GetPendingInstallId(const GURL& url);
64
65 // Reports an install |error| to the delegate for the given extension if this
66 // managed its installation. This also removes the associated PendingInstall.
67 void ReportFailure(const std::string& id, const std::string& error);
68
69 // Reports a successful install to the delegate for the given extension if
70 // this managed its installation. This also removes the associated
71 // PendingInstall.
72 void ReportSuccess(const std::string& id);
73
[email protected]6c2381d2011-10-19 02:52:5374 content::NotificationRegistrar registrar_;
[email protected]655b2b1a2011-10-13 17:13:0675 Profile* profile_;
76 std::vector<PendingInstall> pending_installs_;
77};
78
79#endif // CHROME_BROWSER_EXTENSIONS_WEBSTORE_INSTALLER_H_