| 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 #include "chrome/browser/plugin_installer.h" | 5 #include "chrome/browser/plugin_installer.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/process.h" | 10 #include "base/process.h" |
| 11 #include "chrome/browser/download/download_service.h" | 11 #include "chrome/browser/download/download_service.h" |
| 12 #include "chrome/browser/download/download_service_factory.h" | 12 #include "chrome/browser/download/download_service_factory.h" |
| 13 #include "chrome/browser/download/download_util.h" | 13 #include "chrome/browser/download/download_util.h" |
| 14 #include "chrome/browser/platform_util.h" | 14 #include "chrome/browser/platform_util.h" |
| 15 #include "chrome/browser/plugin_installer_observer.h" | 15 #include "chrome/browser/plugin_installer_observer.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 17 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 18 #include "content/public/browser/browser_context.h" | 18 #include "content/public/browser/browser_context.h" |
| 19 #include "content/public/browser/download_id.h" | 19 #include "content/public/browser/download_id.h" |
| 20 #include "content/public/browser/download_item.h" | 20 #include "content/public/browser/download_item.h" |
| 21 #include "content/public/browser/download_manager.h" | 21 #include "content/public/browser/download_manager.h" |
| 22 #include "content/public/browser/download_save_info.h" | 22 #include "content/public/browser/download_save_info.h" |
| 23 #include "content/public/browser/render_process_host.h" | 23 #include "content/public/browser/render_process_host.h" |
| 24 #include "content/public/browser/render_view_host.h" | 24 #include "content/public/browser/render_view_host.h" |
| 25 #include "content/public/browser/resource_dispatcher_host.h" | 25 #include "content/public/browser/resource_dispatcher_host.h" |
| 26 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
| 27 #include "net/url_request/url_request.h" | 27 #include "net/url_request/url_request.h" |
| 28 #include "webkit/plugins/npapi/plugin_group.h" | 28 #include "webkit/plugins/npapi/plugin_group.h" |
| 29 | 29 |
| 30 using content::BrowserContext; |
| 30 using content::BrowserThread; | 31 using content::BrowserThread; |
| 31 using content::DownloadItem; | 32 using content::DownloadItem; |
| 33 using content::DownloadManager; |
| 32 using content::ResourceDispatcherHost; | 34 using content::ResourceDispatcherHost; |
| 33 | 35 |
| 34 namespace { | 36 namespace { |
| 35 | 37 |
| 36 void BeginDownload( | 38 void BeginDownload( |
| 37 const GURL& url, | 39 const GURL& url, |
| 38 content::ResourceContext* resource_context, | 40 content::ResourceContext* resource_context, |
| 39 int render_process_host_id, | 41 int render_process_host_id, |
| 40 int render_view_host_routing_id, | 42 int render_view_host_routing_id, |
| 41 const ResourceDispatcherHost::DownloadStartedCallback& callback) { | 43 const ResourceDispatcherHost::DownloadStartedCallback& callback) { |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 WeakPluginInstallerObserver* observer) { | 188 WeakPluginInstallerObserver* observer) { |
| 187 weak_observers_.RemoveObserver(observer); | 189 weak_observers_.RemoveObserver(observer); |
| 188 } | 190 } |
| 189 | 191 |
| 190 void PluginInstaller::StartInstalling(TabContentsWrapper* wrapper) { | 192 void PluginInstaller::StartInstalling(TabContentsWrapper* wrapper) { |
| 191 DCHECK_EQ(INSTALLER_STATE_IDLE, state_); | 193 DCHECK_EQ(INSTALLER_STATE_IDLE, state_); |
| 192 DCHECK(!url_for_display_); | 194 DCHECK(!url_for_display_); |
| 193 state_ = INSTALLER_STATE_DOWNLOADING; | 195 state_ = INSTALLER_STATE_DOWNLOADING; |
| 194 FOR_EACH_OBSERVER(PluginInstallerObserver, observers_, DownloadStarted()); | 196 FOR_EACH_OBSERVER(PluginInstallerObserver, observers_, DownloadStarted()); |
| 195 content::WebContents* web_contents = wrapper->web_contents(); | 197 content::WebContents* web_contents = wrapper->web_contents(); |
| 196 DownloadService* download_service = | 198 DownloadManager* download_manager = |
| 197 DownloadServiceFactory::GetForProfile(wrapper->profile()); | 199 BrowserContext::GetDownloadManager(wrapper->profile()); |
| 198 download_util::RecordDownloadSource( | 200 download_util::RecordDownloadSource( |
| 199 download_util::INITIATED_BY_PLUGIN_INSTALLER); | 201 download_util::INITIATED_BY_PLUGIN_INSTALLER); |
| 200 BrowserThread::PostTask( | 202 BrowserThread::PostTask( |
| 201 BrowserThread::IO, FROM_HERE, | 203 BrowserThread::IO, FROM_HERE, |
| 202 base::Bind(&BeginDownload, | 204 base::Bind(&BeginDownload, |
| 203 plugin_url_, | 205 plugin_url_, |
| 204 wrapper->profile()->GetResourceContext(), | 206 wrapper->profile()->GetResourceContext(), |
| 205 web_contents->GetRenderProcessHost()->GetID(), | 207 web_contents->GetRenderProcessHost()->GetID(), |
| 206 web_contents->GetRenderViewHost()->GetRoutingID(), | 208 web_contents->GetRenderViewHost()->GetRoutingID(), |
| 207 base::Bind(&PluginInstaller::DownloadStarted, | 209 base::Bind(&PluginInstaller::DownloadStarted, |
| 208 base::Unretained(this), | 210 base::Unretained(this), |
| 209 make_scoped_refptr( | 211 make_scoped_refptr(download_manager)))); |
| 210 download_service->GetDownloadManager())))); | |
| 211 } | 212 } |
| 212 | 213 |
| 213 void PluginInstaller::DownloadStarted( | 214 void PluginInstaller::DownloadStarted( |
| 214 scoped_refptr<content::DownloadManager> dlm, | 215 scoped_refptr<content::DownloadManager> dlm, |
| 215 content::DownloadId download_id, | 216 content::DownloadId download_id, |
| 216 net::Error error) { | 217 net::Error error) { |
| 217 if (error != net::OK) { | 218 if (error != net::OK) { |
| 218 std::string msg = | 219 std::string msg = |
| 219 base::StringPrintf("Error %d: %s", error, net::ErrorToString(error)); | 220 base::StringPrintf("Error %d: %s", error, net::ErrorToString(error)); |
| 220 DownloadError(msg); | 221 DownloadError(msg); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 241 DCHECK_EQ(INSTALLER_STATE_DOWNLOADING, state_); | 242 DCHECK_EQ(INSTALLER_STATE_DOWNLOADING, state_); |
| 242 state_ = INSTALLER_STATE_IDLE; | 243 state_ = INSTALLER_STATE_IDLE; |
| 243 FOR_EACH_OBSERVER(PluginInstallerObserver, observers_, DownloadError(msg)); | 244 FOR_EACH_OBSERVER(PluginInstallerObserver, observers_, DownloadError(msg)); |
| 244 } | 245 } |
| 245 | 246 |
| 246 void PluginInstaller::DownloadCancelled() { | 247 void PluginInstaller::DownloadCancelled() { |
| 247 DCHECK_EQ(INSTALLER_STATE_DOWNLOADING, state_); | 248 DCHECK_EQ(INSTALLER_STATE_DOWNLOADING, state_); |
| 248 state_ = INSTALLER_STATE_IDLE; | 249 state_ = INSTALLER_STATE_IDLE; |
| 249 FOR_EACH_OBSERVER(PluginInstallerObserver, observers_, DownloadCancelled()); | 250 FOR_EACH_OBSERVER(PluginInstallerObserver, observers_, DownloadCancelled()); |
| 250 } | 251 } |
| OLD | NEW |