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

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

Issue 10453039: Debug crash in WebstoreInstaller::StartDownload() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge Created 8 years, 6 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "chrome/browser/extensions/webstore_installer.h" 5 #include "chrome/browser/extensions/webstore_installer.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 if (!Extension::IdIsValid(id_)) { 188 if (!Extension::IdIsValid(id_)) {
189 ReportFailure(kInvalidIdError); 189 ReportFailure(kInvalidIdError);
190 return; 190 return;
191 } 191 }
192 192
193 FilePath download_path = DownloadPrefs::FromDownloadManager( 193 FilePath download_path = DownloadPrefs::FromDownloadManager(
194 profile_->GetDownloadManager())->download_path(); 194 profile_->GetDownloadManager())->download_path();
195 BrowserThread::PostTask( 195 BrowserThread::PostTask(
196 BrowserThread::FILE, FROM_HERE, 196 BrowserThread::FILE, FROM_HERE,
197 base::Bind(&GetDownloadFilePath, download_path, id_, 197 base::Bind(&GetDownloadFilePath, download_path, id_,
198 base::Bind(&WebstoreInstaller::StartDownload, 198 base::Bind(&WebstoreInstaller::StartDownload, this)));
199 base::Unretained(this))));
200
201 } 199 }
202 200
203 void WebstoreInstaller::Observe(int type, 201 void WebstoreInstaller::Observe(int type,
204 const content::NotificationSource& source, 202 const content::NotificationSource& source,
205 const content::NotificationDetails& details) { 203 const content::NotificationDetails& details) {
206 switch (type) { 204 switch (type) {
207 case chrome::NOTIFICATION_CRX_INSTALLER_DONE: { 205 case chrome::NOTIFICATION_CRX_INSTALLER_DONE: {
208 const Extension* extension = 206 const Extension* extension =
209 content::Details<const Extension>(details).ptr(); 207 content::Details<const Extension>(details).ptr();
210 CrxInstaller* installer = content::Source<CrxInstaller>(source).ptr(); 208 CrxInstaller* installer = content::Source<CrxInstaller>(source).ptr();
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 } 294 }
297 } 295 }
298 296
299 void WebstoreInstaller::OnDownloadOpened(DownloadItem* download) { 297 void WebstoreInstaller::OnDownloadOpened(DownloadItem* download) {
300 CHECK_EQ(download_item_, download); 298 CHECK_EQ(download_item_, download);
301 } 299 }
302 300
303 void WebstoreInstaller::StartDownload(const FilePath& file) { 301 void WebstoreInstaller::StartDownload(const FilePath& file) {
304 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 302 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
305 303
306 if (file.empty()) { 304 if (file.empty() || !controller_ || !controller_->GetWebContents()) {
Aaron Boodman 2012/06/11 21:53:42 How can controller_ be NULL?
benjhayden 2012/06/12 17:51:53 Changed the c-tor to validate it. PTAL.
307 ReportFailure(kDownloadDirectoryError); 305 ReportFailure(kDownloadDirectoryError);
308 return; 306 return;
309 } 307 }
310 308
311 content::DownloadSaveInfo save_info; 309 content::DownloadSaveInfo save_info;
312 save_info.file_path = file; 310 save_info.file_path = file;
313 311
314 // The download url for the given extension is contained in |download_url_|. 312 // The download url for the given extension is contained in |download_url_|.
315 // We will navigate the current tab to this url to start the download. The 313 // We will navigate the current tab to this url to start the download. The
316 // download system will then pass the crx to the CrxInstaller. 314 // download system will then pass the crx to the CrxInstaller.
317 download_util::RecordDownloadSource( 315 download_util::RecordDownloadSource(
318 download_util::INITIATED_BY_WEBSTORE_INSTALLER); 316 download_util::INITIATED_BY_WEBSTORE_INSTALLER);
319 scoped_ptr<DownloadUrlParameters> params( 317 scoped_ptr<DownloadUrlParameters> params(
320 DownloadUrlParameters::FromWebContents( 318 DownloadUrlParameters::FromWebContents(
321 controller_->GetWebContents(), download_url_, save_info)); 319 controller_->GetWebContents(), download_url_, save_info));
322 params->set_referrer( 320 if (controller_->GetActiveEntry())
323 content::Referrer(controller_->GetActiveEntry()->GetURL(), 321 params->set_referrer(
324 WebKit::WebReferrerPolicyDefault)); 322 content::Referrer(controller_->GetActiveEntry()->GetURL(),
323 WebKit::WebReferrerPolicyDefault));
325 params->set_callback(base::Bind(&WebstoreInstaller::OnDownloadStarted, this)); 324 params->set_callback(base::Bind(&WebstoreInstaller::OnDownloadStarted, this));
326 profile_->GetDownloadManager()->DownloadUrl(params.Pass()); 325 profile_->GetDownloadManager()->DownloadUrl(params.Pass());
327 } 326 }
328 327
329 void WebstoreInstaller::ReportFailure(const std::string& error) { 328 void WebstoreInstaller::ReportFailure(const std::string& error) {
330 if (delegate_) { 329 if (delegate_) {
331 delegate_->OnExtensionInstallFailure(id_, error); 330 delegate_->OnExtensionInstallFailure(id_, error);
332 delegate_ = NULL; 331 delegate_ = NULL;
333 } 332 }
334 333
335 Release(); // Balanced in Start(). 334 Release(); // Balanced in Start().
336 } 335 }
337 336
338 void WebstoreInstaller::ReportSuccess() { 337 void WebstoreInstaller::ReportSuccess() {
339 if (delegate_) { 338 if (delegate_) {
340 delegate_->OnExtensionInstallSuccess(id_); 339 delegate_->OnExtensionInstallSuccess(id_);
341 delegate_ = NULL; 340 delegate_ = NULL;
342 } 341 }
343 342
344 Release(); // Balanced in Start(). 343 Release(); // Balanced in Start().
345 } 344 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698