| 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/plugins/plugin_installer.h" | 5 #include "chrome/browser/plugins/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" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 resource_context, | 53 resource_context, |
| 54 render_process_host_id, | 54 render_process_host_id, |
| 55 render_view_host_routing_id, | 55 render_view_host_routing_id, |
| 56 true, // prefer_cache | 56 true, // prefer_cache |
| 57 content::DownloadSaveInfo(), | 57 content::DownloadSaveInfo(), |
| 58 callback); | 58 callback); |
| 59 | 59 |
| 60 if (error != net::OK) { | 60 if (error != net::OK) { |
| 61 BrowserThread::PostTask( | 61 BrowserThread::PostTask( |
| 62 BrowserThread::UI, FROM_HERE, | 62 BrowserThread::UI, FROM_HERE, |
| 63 base::Bind(callback, content::DownloadId::Invalid(), error)); | 63 base::Bind(callback, static_cast<DownloadItem*>(NULL), error)); |
| 64 } | 64 } |
| 65 } | 65 } |
| 66 | 66 |
| 67 } // namespace | 67 } // namespace |
| 68 | 68 |
| 69 PluginInstaller::PluginInstaller() | 69 PluginInstaller::PluginInstaller() |
| 70 : state_(INSTALLER_STATE_IDLE) { | 70 : state_(INSTALLER_STATE_IDLE) { |
| 71 } | 71 } |
| 72 | 72 |
| 73 PluginInstaller::~PluginInstaller() { | 73 PluginInstaller::~PluginInstaller() { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 tab_contents->profile()->GetResourceContext(), | 148 tab_contents->profile()->GetResourceContext(), |
| 149 web_contents->GetRenderProcessHost()->GetID(), | 149 web_contents->GetRenderProcessHost()->GetID(), |
| 150 web_contents->GetRenderViewHost()->GetRoutingID(), | 150 web_contents->GetRenderViewHost()->GetRoutingID(), |
| 151 base::Bind(&PluginInstaller::DownloadStarted, | 151 base::Bind(&PluginInstaller::DownloadStarted, |
| 152 base::Unretained(this), | 152 base::Unretained(this), |
| 153 make_scoped_refptr(download_manager)))); | 153 make_scoped_refptr(download_manager)))); |
| 154 } | 154 } |
| 155 | 155 |
| 156 void PluginInstaller::DownloadStarted( | 156 void PluginInstaller::DownloadStarted( |
| 157 scoped_refptr<content::DownloadManager> dlm, | 157 scoped_refptr<content::DownloadManager> dlm, |
| 158 content::DownloadId download_id, | 158 content::DownloadItem* item, |
| 159 net::Error error) { | 159 net::Error error) { |
| 160 if (error != net::OK) { | 160 if (!item) { |
| 161 DCHECK_NE(net::OK, error); |
| 161 std::string msg = | 162 std::string msg = |
| 162 base::StringPrintf("Error %d: %s", error, net::ErrorToString(error)); | 163 base::StringPrintf("Error %d: %s", error, net::ErrorToString(error)); |
| 163 DownloadError(msg); | 164 DownloadError(msg); |
| 164 return; | 165 return; |
| 165 } | 166 } |
| 166 DownloadItem* download_item = dlm->GetDownload(download_id.local()); | 167 DCHECK_EQ(net::OK, error); |
| 167 // TODO(benjhayden): DCHECK(item && item->IsInProgress()) after figuring out | 168 item->SetOpenWhenComplete(true); |
| 168 // why DownloadStarted may get net:OK but an invalid id. | 169 item->AddObserver(this); |
| 169 if (!download_item) { | |
| 170 DownloadError("Download not found"); | |
| 171 return; | |
| 172 } | |
| 173 download_item->SetOpenWhenComplete(true); | |
| 174 download_item->AddObserver(this); | |
| 175 } | 170 } |
| 176 | 171 |
| 177 void PluginInstaller::OpenDownloadURL(bool url_for_display, | 172 void PluginInstaller::OpenDownloadURL(bool url_for_display, |
| 178 const GURL& plugin_url, | 173 const GURL& plugin_url, |
| 179 content::WebContents* web_contents) { | 174 content::WebContents* web_contents) { |
| 180 DCHECK_EQ(INSTALLER_STATE_IDLE, state_); | 175 DCHECK_EQ(INSTALLER_STATE_IDLE, state_); |
| 181 DCHECK(url_for_display); | 176 DCHECK(url_for_display); |
| 182 web_contents->OpenURL(content::OpenURLParams( | 177 web_contents->OpenURL(content::OpenURLParams( |
| 183 plugin_url, | 178 plugin_url, |
| 184 content::Referrer(web_contents->GetURL(), | 179 content::Referrer(web_contents->GetURL(), |
| 185 WebKit::WebReferrerPolicyDefault), | 180 WebKit::WebReferrerPolicyDefault), |
| 186 NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_TYPED, false)); | 181 NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_TYPED, false)); |
| 187 FOR_EACH_OBSERVER(PluginInstallerObserver, observers_, DownloadFinished()); | 182 FOR_EACH_OBSERVER(PluginInstallerObserver, observers_, DownloadFinished()); |
| 188 } | 183 } |
| 189 | 184 |
| 190 void PluginInstaller::DownloadError(const std::string& msg) { | 185 void PluginInstaller::DownloadError(const std::string& msg) { |
| 191 DCHECK_EQ(INSTALLER_STATE_DOWNLOADING, state_); | 186 DCHECK_EQ(INSTALLER_STATE_DOWNLOADING, state_); |
| 192 state_ = INSTALLER_STATE_IDLE; | 187 state_ = INSTALLER_STATE_IDLE; |
| 193 FOR_EACH_OBSERVER(PluginInstallerObserver, observers_, DownloadError(msg)); | 188 FOR_EACH_OBSERVER(PluginInstallerObserver, observers_, DownloadError(msg)); |
| 194 } | 189 } |
| 195 | 190 |
| 196 void PluginInstaller::DownloadCancelled() { | 191 void PluginInstaller::DownloadCancelled() { |
| 197 DCHECK_EQ(INSTALLER_STATE_DOWNLOADING, state_); | 192 DCHECK_EQ(INSTALLER_STATE_DOWNLOADING, state_); |
| 198 state_ = INSTALLER_STATE_IDLE; | 193 state_ = INSTALLER_STATE_IDLE; |
| 199 FOR_EACH_OBSERVER(PluginInstallerObserver, observers_, DownloadCancelled()); | 194 FOR_EACH_OBSERVER(PluginInstallerObserver, observers_, DownloadCancelled()); |
| 200 } | 195 } |
| OLD | NEW |