Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(538)

Side by Side Diff: chrome/browser/extensions/webstore_installer.h

Issue 9837054: Improve WebstoreInstaller error handling. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 {
22 class NavigationController; 25 class NavigationController;
23 } 26 }
24 27
25 // Downloads and installs extensions from the web store. 28 // Downloads and installs extensions from the web store.
26 class WebstoreInstaller : public content::NotificationObserver, 29 class WebstoreInstaller : public content::NotificationObserver,
30 public content::DownloadItem::Observer,
27 public base::RefCounted<WebstoreInstaller> { 31 public base::RefCounted<WebstoreInstaller> {
28 public: 32 public:
29 enum Flag { 33 enum Flag {
30 FLAG_NONE = 0, 34 FLAG_NONE = 0,
31 35
32 // Inline installs trigger slightly different behavior (install source 36 // Inline installs trigger slightly different behavior (install source
33 // is different, download referrers are the item's page in the gallery). 37 // is different, download referrers are the item's page in the gallery).
34 FLAG_INLINE_INSTALL = 1 << 0 38 FLAG_INLINE_INSTALL = 1 << 0
35 }; 39 };
36 40
37 class Delegate { 41 class Delegate {
38 public: 42 public:
39 virtual void OnExtensionInstallSuccess(const std::string& id) = 0; 43 virtual void OnExtensionInstallSuccess(const std::string& id) = 0;
40 virtual void OnExtensionInstallFailure(const std::string& id, 44 virtual void OnExtensionInstallFailure(const std::string& id,
41 const std::string& error) = 0; 45 const std::string& error) = 0;
42 }; 46 };
43 47
44
45 // Creates a WebstoreInstaller for downloading and installing the extension 48 // Creates a WebstoreInstaller for downloading and installing the extension
46 // with the given |id| from the Chrome Web Store. If |delegate| is not NULL, 49 // 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 50 // it will be notified when the install succeeds or fails. The installer will
48 // use the specified |controller| to download the extension. Only one 51 // use the specified |controller| to download the extension. Only one
49 // WebstoreInstaller can use a specific controller at any given time. 52 // WebstoreInstaller can use a specific controller at any given time.
50 // Note: the delegate should stay alive until being called back. 53 // Note: the delegate should stay alive until being called back.
51 WebstoreInstaller(Profile* profile, 54 WebstoreInstaller(Profile* profile,
52 Delegate* delegate, 55 Delegate* delegate,
53 content::NavigationController* controller, 56 content::NavigationController* controller,
54 const std::string& id, 57 const std::string& id,
55 int flags); 58 int flags);
56 virtual ~WebstoreInstaller(); 59 virtual ~WebstoreInstaller();
57 60
58 // Starts downloading and installing the extension. 61 // Starts downloading and installing the extension.
59 void Start(); 62 void Start();
60 63
61 // content::NotificationObserver 64 // content::NotificationObserver
62 virtual void Observe(int type, 65 virtual void Observe(int type,
63 const content::NotificationSource& source, 66 const content::NotificationSource& source,
64 const content::NotificationDetails& details) OVERRIDE; 67 const content::NotificationDetails& details) OVERRIDE;
65 68
66 // Instead of using the default download directory, use |directory| instead. 69 // Instead of using the default download directory, use |directory| instead.
67 // This does *not* transfer ownership of |directory|. 70 // This does *not* transfer ownership of |directory|.
68 static void SetDownloadDirectoryForTests(FilePath* directory); 71 static void SetDownloadDirectoryForTests(FilePath* directory);
69 72
70 private: 73 private:
74 // DownloadManager::DownloadUrl callback.
75 void OnDownloadStarted(content::DownloadId id, net::Error error);
76
77 // DownloadItem::Observer implementation:
78 virtual void OnDownloadUpdated(content::DownloadItem* download) OVERRIDE;
79 virtual void OnDownloadOpened(content::DownloadItem* download) OVERRIDE;
80
71 // Starts downloading the extension to |file_path|. 81 // Starts downloading the extension to |file_path|.
72 void StartDownload(const FilePath& file_path); 82 void StartDownload(const FilePath& file_path);
73 83
74 // Reports an install |error| to the delegate for the given extension if this 84 // Reports an install |error| to the delegate for the given extension if this
75 // managed its installation. This also removes the associated PendingInstall. 85 // managed its installation. This also removes the associated PendingInstall.
76 void ReportFailure(const std::string& error); 86 void ReportFailure(const std::string& error);
77 87
78 // Reports a successful install to the delegate for the given extension if 88 // Reports a successful install to the delegate for the given extension if
79 // this managed its installation. This also removes the associated 89 // this managed its installation. This also removes the associated
80 // PendingInstall. 90 // PendingInstall.
81 void ReportSuccess(); 91 void ReportSuccess();
82 92
93 // Removes all observers.
94 void RemoveObservers();
95
83 content::NotificationRegistrar registrar_; 96 content::NotificationRegistrar registrar_;
84 Profile* profile_; 97 Profile* profile_;
85 Delegate* delegate_; 98 Delegate* delegate_;
86 content::NavigationController* controller_; 99 content::NavigationController* controller_;
87 std::string id_; 100 std::string id_;
101 content::DownloadItem* download_item_;
Mihai Parparita -not on Chrome 2012/03/26 18:46:49 Add a comment about who owns this instance and wha
jstritar 2012/03/26 19:53:36 Done.
88 int flags_; 102 int flags_;
89 GURL download_url_; 103 GURL download_url_;
90 }; 104 };
91 105
92 #endif // CHROME_BROWSER_EXTENSIONS_WEBSTORE_INSTALLER_H_ 106 #endif // CHROME_BROWSER_EXTENSIONS_WEBSTORE_INSTALLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698