| 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 tab_contents->profile()->GetResourceContext(), | 146 tab_contents->profile()->GetResourceContext(), |
| 147 web_contents->GetRenderProcessHost()->GetID(), | 147 web_contents->GetRenderProcessHost()->GetID(), |
| 148 web_contents->GetRenderViewHost()->GetRoutingID(), | 148 web_contents->GetRenderViewHost()->GetRoutingID(), |
| 149 base::Bind(&PluginInstaller::DownloadStarted, | 149 base::Bind(&PluginInstaller::DownloadStarted, |
| 150 base::Unretained(this), | 150 base::Unretained(this), |
| 151 make_scoped_refptr(download_manager)))); | 151 make_scoped_refptr(download_manager)))); |
| 152 } | 152 } |
| 153 | 153 |
| 154 void PluginInstaller::DownloadStarted( | 154 void PluginInstaller::DownloadStarted( |
| 155 scoped_refptr<content::DownloadManager> dlm, | 155 scoped_refptr<content::DownloadManager> dlm, |
| 156 content::DownloadId download_id, | 156 content::DownloadItem* item, |
| 157 net::Error error) { | 157 net::Error error) { |
| 158 if (error != net::OK) { | 158 if (!item) { |
| 159 DCHECK_NE(net::OK, error); |
| 159 std::string msg = | 160 std::string msg = |
| 160 base::StringPrintf("Error %d: %s", error, net::ErrorToString(error)); | 161 base::StringPrintf("Error %d: %s", error, net::ErrorToString(error)); |
| 161 DownloadError(msg); | 162 DownloadError(msg); |
| 162 return; | 163 return; |
| 163 } | 164 } |
| 164 DownloadItem* download_item = dlm->GetDownload(download_id.local()); | 165 DCHECK_EQ(net::OK, error); |
| 165 // TODO(benjhayden): DCHECK(item && item->IsInProgress()) after figuring out | 166 item->SetOpenWhenComplete(true); |
| 166 // why DownloadStarted may get net:OK but an invalid id. | 167 item->AddObserver(this); |
| 167 if (!download_item) { | |
| 168 DownloadError("Download not found"); | |
| 169 return; | |
| 170 } | |
| 171 download_item->SetOpenWhenComplete(true); | |
| 172 download_item->AddObserver(this); | |
| 173 } | 168 } |
| 174 | 169 |
| 175 void PluginInstaller::OpenDownloadURL(const GURL& plugin_url, | 170 void PluginInstaller::OpenDownloadURL(const GURL& plugin_url, |
| 176 content::WebContents* web_contents) { | 171 content::WebContents* web_contents) { |
| 177 DCHECK_EQ(INSTALLER_STATE_IDLE, state_); | 172 DCHECK_EQ(INSTALLER_STATE_IDLE, state_); |
| 178 web_contents->OpenURL(content::OpenURLParams( | 173 web_contents->OpenURL(content::OpenURLParams( |
| 179 plugin_url, | 174 plugin_url, |
| 180 content::Referrer(web_contents->GetURL(), | 175 content::Referrer(web_contents->GetURL(), |
| 181 WebKit::WebReferrerPolicyDefault), | 176 WebKit::WebReferrerPolicyDefault), |
| 182 NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_TYPED, false)); | 177 NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_TYPED, false)); |
| 183 FOR_EACH_OBSERVER(PluginInstallerObserver, observers_, DownloadFinished()); | 178 FOR_EACH_OBSERVER(PluginInstallerObserver, observers_, DownloadFinished()); |
| 184 } | 179 } |
| 185 | 180 |
| 186 void PluginInstaller::DownloadError(const std::string& msg) { | 181 void PluginInstaller::DownloadError(const std::string& msg) { |
| 187 DCHECK_EQ(INSTALLER_STATE_DOWNLOADING, state_); | 182 DCHECK_EQ(INSTALLER_STATE_DOWNLOADING, state_); |
| 188 state_ = INSTALLER_STATE_IDLE; | 183 state_ = INSTALLER_STATE_IDLE; |
| 189 FOR_EACH_OBSERVER(PluginInstallerObserver, observers_, DownloadError(msg)); | 184 FOR_EACH_OBSERVER(PluginInstallerObserver, observers_, DownloadError(msg)); |
| 190 } | 185 } |
| 191 | 186 |
| 192 void PluginInstaller::DownloadCancelled() { | 187 void PluginInstaller::DownloadCancelled() { |
| 193 DCHECK_EQ(INSTALLER_STATE_DOWNLOADING, state_); | 188 DCHECK_EQ(INSTALLER_STATE_DOWNLOADING, state_); |
| 194 state_ = INSTALLER_STATE_IDLE; | 189 state_ = INSTALLER_STATE_IDLE; |
| 195 FOR_EACH_OBSERVER(PluginInstallerObserver, observers_, DownloadCancelled()); | 190 FOR_EACH_OBSERVER(PluginInstallerObserver, observers_, DownloadCancelled()); |
| 196 } | 191 } |
| OLD | NEW |