OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_EXTENSIONS_WEBSTORE_INSTALLER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_WEBSTORE_INSTALLER_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_WEBSTORE_INSTALLER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_WEBSTORE_INSTALLER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "content/public/browser/download_id.h" | |
15 #include "content/public/browser/download_item.h" | |
14 #include "content/public/browser/notification_observer.h" | 16 #include "content/public/browser/notification_observer.h" |
15 #include "content/public/browser/notification_registrar.h" | 17 #include "content/public/browser/notification_registrar.h" |
18 #include "net/base/net_errors.h" | |
16 #include "googleurl/src/gurl.h" | 19 #include "googleurl/src/gurl.h" |
17 | 20 |
18 class FilePath; | 21 class FilePath; |
19 class Profile; | 22 class Profile; |
20 | 23 |
21 namespace content { | 24 namespace content { |
25 class DownloadItem; | |
Randy Smith (Not in Mondays)
2012/03/23 20:57:19
Why is this forward decl needed if you're includin
jstritar
2012/03/23 21:52:53
Done.
| |
22 class NavigationController; | 26 class NavigationController; |
23 } | 27 } |
24 | 28 |
25 // Downloads and installs extensions from the web store. | 29 // Downloads and installs extensions from the web store. |
26 class WebstoreInstaller : public content::NotificationObserver, | 30 class WebstoreInstaller : public content::NotificationObserver, |
31 public content::DownloadItem::Observer, | |
27 public base::RefCounted<WebstoreInstaller> { | 32 public base::RefCounted<WebstoreInstaller> { |
28 public: | 33 public: |
29 enum Flag { | 34 enum Flag { |
30 FLAG_NONE = 0, | 35 FLAG_NONE = 0, |
31 | 36 |
32 // Inline installs trigger slightly different behavior (install source | 37 // Inline installs trigger slightly different behavior (install source |
33 // is different, download referrers are the item's page in the gallery). | 38 // is different, download referrers are the item's page in the gallery). |
34 FLAG_INLINE_INSTALL = 1 << 0 | 39 FLAG_INLINE_INSTALL = 1 << 0 |
35 }; | 40 }; |
36 | 41 |
37 class Delegate { | 42 class Delegate { |
38 public: | 43 public: |
39 virtual void OnExtensionInstallSuccess(const std::string& id) = 0; | 44 virtual void OnExtensionInstallSuccess(const std::string& id) = 0; |
40 virtual void OnExtensionInstallFailure(const std::string& id, | 45 virtual void OnExtensionInstallFailure(const std::string& id, |
41 const std::string& error) = 0; | 46 const std::string& error) = 0; |
42 }; | 47 }; |
43 | 48 |
44 | |
45 // Creates a WebstoreInstaller for downloading and installing the extension | 49 // Creates a WebstoreInstaller for downloading and installing the extension |
46 // with the given |id| from the Chrome Web Store. If |delegate| is not NULL, | 50 // 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 | 51 // it will be notified when the install succeeds or fails. The installer will |
48 // use the specified |controller| to download the extension. Only one | 52 // use the specified |controller| to download the extension. Only one |
49 // WebstoreInstaller can use a specific controller at any given time. | 53 // WebstoreInstaller can use a specific controller at any given time. |
50 // Note: the delegate should stay alive until being called back. | 54 // Note: the delegate should stay alive until being called back. |
51 WebstoreInstaller(Profile* profile, | 55 WebstoreInstaller(Profile* profile, |
52 Delegate* delegate, | 56 Delegate* delegate, |
53 content::NavigationController* controller, | 57 content::NavigationController* controller, |
54 const std::string& id, | 58 const std::string& id, |
55 int flags); | 59 int flags); |
56 virtual ~WebstoreInstaller(); | 60 virtual ~WebstoreInstaller(); |
57 | 61 |
58 // Starts downloading and installing the extension. | 62 // Starts downloading and installing the extension. |
59 void Start(); | 63 void Start(); |
60 | 64 |
61 // content::NotificationObserver | 65 // content::NotificationObserver |
62 virtual void Observe(int type, | 66 virtual void Observe(int type, |
63 const content::NotificationSource& source, | 67 const content::NotificationSource& source, |
64 const content::NotificationDetails& details) OVERRIDE; | 68 const content::NotificationDetails& details) OVERRIDE; |
65 | 69 |
66 // Instead of using the default download directory, use |directory| instead. | 70 // Instead of using the default download directory, use |directory| instead. |
67 // This does *not* transfer ownership of |directory|. | 71 // This does *not* transfer ownership of |directory|. |
68 static void SetDownloadDirectoryForTests(FilePath* directory); | 72 static void SetDownloadDirectoryForTests(FilePath* directory); |
69 | 73 |
70 private: | 74 private: |
75 // DownloadManager::DownloadUrl callback. | |
76 void OnDownloadStarted(content::DownloadId id, net::Error error); | |
77 | |
78 // DownloadItem::Observer implementation: | |
79 virtual void OnDownloadUpdated(content::DownloadItem* download) OVERRIDE; | |
80 virtual void OnDownloadOpened(content::DownloadItem* download) OVERRIDE; | |
81 | |
71 // Starts downloading the extension to |file_path|. | 82 // Starts downloading the extension to |file_path|. |
72 void StartDownload(const FilePath& file_path); | 83 void StartDownload(const FilePath& file_path); |
73 | 84 |
74 // Reports an install |error| to the delegate for the given extension if this | 85 // Reports an install |error| to the delegate for the given extension if this |
75 // managed its installation. This also removes the associated PendingInstall. | 86 // managed its installation. This also removes the associated PendingInstall. |
76 void ReportFailure(const std::string& error); | 87 void ReportFailure(const std::string& error); |
77 | 88 |
78 // Reports a successful install to the delegate for the given extension if | 89 // Reports a successful install to the delegate for the given extension if |
79 // this managed its installation. This also removes the associated | 90 // this managed its installation. This also removes the associated |
80 // PendingInstall. | 91 // PendingInstall. |
81 void ReportSuccess(); | 92 void ReportSuccess(); |
82 | 93 |
83 content::NotificationRegistrar registrar_; | 94 content::NotificationRegistrar registrar_; |
84 Profile* profile_; | 95 Profile* profile_; |
85 Delegate* delegate_; | 96 Delegate* delegate_; |
86 content::NavigationController* controller_; | 97 content::NavigationController* controller_; |
87 std::string id_; | 98 std::string id_; |
99 content::DownloadId download_id_; | |
88 int flags_; | 100 int flags_; |
89 GURL download_url_; | 101 GURL download_url_; |
90 }; | 102 }; |
91 | 103 |
92 #endif // CHROME_BROWSER_EXTENSIONS_WEBSTORE_INSTALLER_H_ | 104 #endif // CHROME_BROWSER_EXTENSIONS_WEBSTORE_INSTALLER_H_ |
OLD | NEW |