| 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 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/supports_user_data.h" | 14 #include "base/supports_user_data.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "chrome/browser/extensions/extension_install_prompt.h" | 16 #include "chrome/browser/extensions/extension_install_prompt.h" |
| 17 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 18 #include "content/public/browser/download_item.h" | 18 #include "content/public/browser/download_item.h" |
| 19 #include "content/public/browser/notification_observer.h" | 19 #include "content/public/browser/notification_observer.h" |
| 20 #include "content/public/browser/notification_registrar.h" | 20 #include "content/public/browser/notification_registrar.h" |
| 21 #include "googleurl/src/gurl.h" | 21 #include "googleurl/src/gurl.h" |
| 22 #include "net/base/net_errors.h" | 22 #include "net/base/net_errors.h" |
| 23 | 23 |
| 24 class Profile; |
| 25 |
| 26 namespace base { |
| 24 class FilePath; | 27 class FilePath; |
| 25 class Profile; | 28 } |
| 26 | 29 |
| 27 namespace content { | 30 namespace content { |
| 28 class NavigationController; | 31 class NavigationController; |
| 29 } | 32 } |
| 30 | 33 |
| 31 namespace extensions { | 34 namespace extensions { |
| 32 | 35 |
| 33 // Downloads and installs extensions from the web store. | 36 // Downloads and installs extensions from the web store. |
| 34 class WebstoreInstaller :public content::NotificationObserver, | 37 class WebstoreInstaller :public content::NotificationObserver, |
| 35 public content::DownloadItem::Observer, | 38 public content::DownloadItem::Observer, |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 virtual void Observe(int type, | 138 virtual void Observe(int type, |
| 136 const content::NotificationSource& source, | 139 const content::NotificationSource& source, |
| 137 const content::NotificationDetails& details) OVERRIDE; | 140 const content::NotificationDetails& details) OVERRIDE; |
| 138 | 141 |
| 139 // Removes the reference to the delegate passed in the constructor. Used when | 142 // Removes the reference to the delegate passed in the constructor. Used when |
| 140 // the delegate object must be deleted before this object. | 143 // the delegate object must be deleted before this object. |
| 141 void InvalidateDelegate(); | 144 void InvalidateDelegate(); |
| 142 | 145 |
| 143 // Instead of using the default download directory, use |directory| instead. | 146 // Instead of using the default download directory, use |directory| instead. |
| 144 // This does *not* transfer ownership of |directory|. | 147 // This does *not* transfer ownership of |directory|. |
| 145 static void SetDownloadDirectoryForTests(FilePath* directory); | 148 static void SetDownloadDirectoryForTests(base::FilePath* directory); |
| 146 | 149 |
| 147 private: | 150 private: |
| 148 friend struct content::BrowserThread::DeleteOnThread< | 151 friend struct content::BrowserThread::DeleteOnThread< |
| 149 content::BrowserThread::UI>; | 152 content::BrowserThread::UI>; |
| 150 friend class base::DeleteHelper<WebstoreInstaller>; | 153 friend class base::DeleteHelper<WebstoreInstaller>; |
| 151 virtual ~WebstoreInstaller(); | 154 virtual ~WebstoreInstaller(); |
| 152 | 155 |
| 153 // DownloadManager::DownloadUrl callback. | 156 // DownloadManager::DownloadUrl callback. |
| 154 void OnDownloadStarted(content::DownloadItem* item, net::Error error); | 157 void OnDownloadStarted(content::DownloadItem* item, net::Error error); |
| 155 | 158 |
| 156 // DownloadItem::Observer implementation: | 159 // DownloadItem::Observer implementation: |
| 157 virtual void OnDownloadUpdated(content::DownloadItem* download) OVERRIDE; | 160 virtual void OnDownloadUpdated(content::DownloadItem* download) OVERRIDE; |
| 158 virtual void OnDownloadDestroyed(content::DownloadItem* download) OVERRIDE; | 161 virtual void OnDownloadDestroyed(content::DownloadItem* download) OVERRIDE; |
| 159 | 162 |
| 160 // Starts downloading the extension to |file_path|. | 163 // Starts downloading the extension to |file_path|. |
| 161 void StartDownload(const FilePath& file_path); | 164 void StartDownload(const base::FilePath& file_path); |
| 162 | 165 |
| 163 // Reports an install |error| to the delegate for the given extension if this | 166 // Reports an install |error| to the delegate for the given extension if this |
| 164 // managed its installation. This also removes the associated PendingInstall. | 167 // managed its installation. This also removes the associated PendingInstall. |
| 165 void ReportFailure(const std::string& error, FailureReason reason); | 168 void ReportFailure(const std::string& error, FailureReason reason); |
| 166 | 169 |
| 167 // Reports a successful install to the delegate for the given extension if | 170 // Reports a successful install to the delegate for the given extension if |
| 168 // this managed its installation. This also removes the associated | 171 // this managed its installation. This also removes the associated |
| 169 // PendingInstall. | 172 // PendingInstall. |
| 170 void ReportSuccess(); | 173 void ReportSuccess(); |
| 171 | 174 |
| 172 content::NotificationRegistrar registrar_; | 175 content::NotificationRegistrar registrar_; |
| 173 Profile* profile_; | 176 Profile* profile_; |
| 174 Delegate* delegate_; | 177 Delegate* delegate_; |
| 175 content::NavigationController* controller_; | 178 content::NavigationController* controller_; |
| 176 std::string id_; | 179 std::string id_; |
| 177 // The DownloadItem is owned by the DownloadManager and is valid from when | 180 // The DownloadItem is owned by the DownloadManager and is valid from when |
| 178 // OnDownloadStarted is called (with no error) until OnDownloadDestroyed(). | 181 // OnDownloadStarted is called (with no error) until OnDownloadDestroyed(). |
| 179 content::DownloadItem* download_item_; | 182 content::DownloadItem* download_item_; |
| 180 scoped_ptr<Approval> approval_; | 183 scoped_ptr<Approval> approval_; |
| 181 GURL download_url_; | 184 GURL download_url_; |
| 182 }; | 185 }; |
| 183 | 186 |
| 184 } // namespace extensions | 187 } // namespace extensions |
| 185 | 188 |
| 186 #endif // CHROME_BROWSER_EXTENSIONS_WEBSTORE_INSTALLER_H_ | 189 #endif // CHROME_BROWSER_EXTENSIONS_WEBSTORE_INSTALLER_H_ |
| OLD | NEW |