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

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

Issue 145873003: Fix for 165634 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 10 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
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 <vector> 7 #include <vector>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 56
57 #if defined(OS_CHROMEOS) 57 #if defined(OS_CHROMEOS)
58 #include "chrome/browser/chromeos/drive/file_system_util.h" 58 #include "chrome/browser/chromeos/drive/file_system_util.h"
59 #endif 59 #endif
60 60
61 using chrome::OmahaQueryParams; 61 using chrome::OmahaQueryParams;
62 using content::BrowserContext; 62 using content::BrowserContext;
63 using content::BrowserThread; 63 using content::BrowserThread;
64 using content::DownloadItem; 64 using content::DownloadItem;
65 using content::DownloadManager; 65 using content::DownloadManager;
66 using content::NavigationController; 66 using content::WebContents;
67 using content::WebContentsObserver;
67 using content::DownloadUrlParameters; 68 using content::DownloadUrlParameters;
68 69
69 namespace { 70 namespace {
70 71
71 // Key used to attach the Approval to the DownloadItem. 72 // Key used to attach the Approval to the DownloadItem.
72 const char kApprovalKey[] = "extensions.webstore_installer"; 73 const char kApprovalKey[] = "extensions.webstore_installer";
73 74
74 const char kInvalidIdError[] = "Invalid id"; 75 const char kInvalidIdError[] = "Invalid id";
75 const char kDownloadDirectoryError[] = "Could not create download directory"; 76 const char kDownloadDirectoryError[] = "Could not create download directory";
76 const char kDownloadCanceledError[] = "Download canceled"; 77 const char kDownloadCanceledError[] = "Download canceled";
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 238
238 WebstoreInstaller::Approval::~Approval() {} 239 WebstoreInstaller::Approval::~Approval() {}
239 240
240 const WebstoreInstaller::Approval* WebstoreInstaller::GetAssociatedApproval( 241 const WebstoreInstaller::Approval* WebstoreInstaller::GetAssociatedApproval(
241 const DownloadItem& download) { 242 const DownloadItem& download) {
242 return static_cast<const Approval*>(download.GetUserData(kApprovalKey)); 243 return static_cast<const Approval*>(download.GetUserData(kApprovalKey));
243 } 244 }
244 245
245 WebstoreInstaller::WebstoreInstaller(Profile* profile, 246 WebstoreInstaller::WebstoreInstaller(Profile* profile,
246 Delegate* delegate, 247 Delegate* delegate,
247 NavigationController* controller, 248 WebContents* web_contents,
248 const std::string& id, 249 const std::string& id,
249 scoped_ptr<Approval> approval, 250 scoped_ptr<Approval> approval,
250 InstallSource source) 251 InstallSource source)
251 : profile_(profile), 252 : WebContentsObserver(web_contents),
253 profile_(profile),
252 delegate_(delegate), 254 delegate_(delegate),
253 controller_(controller),
254 id_(id), 255 id_(id),
255 install_source_(source), 256 install_source_(source),
256 download_item_(NULL), 257 download_item_(NULL),
257 approval_(approval.release()), 258 approval_(approval.release()),
258 total_modules_(0), 259 total_modules_(0),
259 download_started_(false) { 260 download_started_(false) {
260 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 261 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
261 DCHECK(controller_); 262 DCHECK(web_contents);
262 263
263 registrar_.Add(this, chrome::NOTIFICATION_CRX_INSTALLER_DONE, 264 registrar_.Add(this, chrome::NOTIFICATION_CRX_INSTALLER_DONE,
264 content::NotificationService::AllSources()); 265 content::NotificationService::AllSources());
265 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED, 266 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED,
266 content::Source<Profile>(profile->GetOriginalProfile())); 267 content::Source<Profile>(profile->GetOriginalProfile()));
267 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR, 268 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR,
268 content::Source<CrxInstaller>(NULL)); 269 content::Source<CrxInstaller>(NULL));
269 } 270 }
270 271
271 void WebstoreInstaller::Start() { 272 void WebstoreInstaller::Start() {
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 void WebstoreInstaller::InvalidateDelegate() { 400 void WebstoreInstaller::InvalidateDelegate() {
400 delegate_ = NULL; 401 delegate_ = NULL;
401 } 402 }
402 403
403 void WebstoreInstaller::SetDownloadDirectoryForTests( 404 void WebstoreInstaller::SetDownloadDirectoryForTests(
404 base::FilePath* directory) { 405 base::FilePath* directory) {
405 g_download_directory_for_tests = directory; 406 g_download_directory_for_tests = directory;
406 } 407 }
407 408
408 WebstoreInstaller::~WebstoreInstaller() { 409 WebstoreInstaller::~WebstoreInstaller() {
409 controller_ = NULL;
410 if (download_item_) { 410 if (download_item_) {
411 download_item_->RemoveObserver(this); 411 download_item_->RemoveObserver(this);
412 download_item_ = NULL; 412 download_item_ = NULL;
413 } 413 }
414 } 414 }
415 415
416 void WebstoreInstaller::OnDownloadStarted( 416 void WebstoreInstaller::OnDownloadStarted(
417 DownloadItem* item, 417 DownloadItem* item,
418 content::DownloadInterruptReason interrupt_reason) { 418 content::DownloadInterruptReason interrupt_reason) {
419 if (!item) { 419 if (!item) {
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 // http://crbug.com/126013 551 // http://crbug.com/126013
552 // The current working theory is that one of the many pointers dereferenced in 552 // The current working theory is that one of the many pointers dereferenced in
553 // here is occasionally deleted before all of its referers are nullified, 553 // here is occasionally deleted before all of its referers are nullified,
554 // probably in a callback race. After this comment is released, the crash 554 // probably in a callback race. After this comment is released, the crash
555 // reports should narrow down exactly which pointer it is. Collapsing all the 555 // reports should narrow down exactly which pointer it is. Collapsing all the
556 // early-returns into a single branch makes it hard to see exactly which pointer 556 // early-returns into a single branch makes it hard to see exactly which pointer
557 // it is. 557 // it is.
558 void WebstoreInstaller::StartDownload(const base::FilePath& file) { 558 void WebstoreInstaller::StartDownload(const base::FilePath& file) {
559 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 559 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
560 560
561 if (!web_contents()) {
562 ReportFailure(kDownloadDirectoryError, FAILURE_REASON_OTHER);
563 return;
564 }
565
561 DownloadManager* download_manager = 566 DownloadManager* download_manager =
562 BrowserContext::GetDownloadManager(profile_); 567 BrowserContext::GetDownloadManager(profile_);
568 if (!download_manager) {
569 ReportFailure(kDownloadDirectoryError, FAILURE_REASON_OTHER);
570 return;
571 }
563 if (file.empty()) { 572 if (file.empty()) {
564 ReportFailure(kDownloadDirectoryError, FAILURE_REASON_OTHER); 573 ReportFailure(kDownloadDirectoryError, FAILURE_REASON_OTHER);
565 return; 574 return;
566 } 575 }
567 if (!download_manager) {
568 ReportFailure(kDownloadDirectoryError, FAILURE_REASON_OTHER);
569 return;
570 }
571 if (!controller_) {
572 ReportFailure(kDownloadDirectoryError, FAILURE_REASON_OTHER);
573 return;
574 }
575 if (!controller_->GetWebContents()) {
576 ReportFailure(kDownloadDirectoryError, FAILURE_REASON_OTHER);
577 return;
578 }
579 if (!controller_->GetWebContents()->GetRenderProcessHost()) {
580 ReportFailure(kDownloadDirectoryError, FAILURE_REASON_OTHER);
581 return;
582 }
583 if (!controller_->GetWebContents()->GetRenderViewHost()) {
584 ReportFailure(kDownloadDirectoryError, FAILURE_REASON_OTHER);
585 return;
586 }
587 if (!controller_->GetBrowserContext()) {
588 ReportFailure(kDownloadDirectoryError, FAILURE_REASON_OTHER);
589 return;
590 }
591 if (!controller_->GetBrowserContext()->GetResourceContext()) {
592 ReportFailure(kDownloadDirectoryError, FAILURE_REASON_OTHER);
593 return;
594 }
595 576
596 // The download url for the given extension is contained in |download_url_|. 577 // The download url for the given extension is contained in |download_url_|.
597 // We will navigate the current tab to this url to start the download. The 578 // We will navigate the current tab to this url to start the download. The
598 // download system will then pass the crx to the CrxInstaller. 579 // download system will then pass the crx to the CrxInstaller.
599 RecordDownloadSource(DOWNLOAD_INITIATED_BY_WEBSTORE_INSTALLER); 580 RecordDownloadSource(DOWNLOAD_INITIATED_BY_WEBSTORE_INSTALLER);
600 int render_process_host_id = 581 int render_process_host_id = web_contents()->GetRenderProcessHost()->GetID();
601 controller_->GetWebContents()->GetRenderProcessHost()->GetID();
602 int render_view_host_routing_id = 582 int render_view_host_routing_id =
603 controller_->GetWebContents()->GetRenderViewHost()->GetRoutingID(); 583 web_contents()->GetRenderViewHost()->GetRoutingID();
584 content::NavigationController& controller = web_contents()->GetController();
604 content::ResourceContext* resource_context = 585 content::ResourceContext* resource_context =
605 controller_->GetBrowserContext()->GetResourceContext(); 586 controller.GetBrowserContext()->GetResourceContext();
606 scoped_ptr<DownloadUrlParameters> params(new DownloadUrlParameters( 587 scoped_ptr<DownloadUrlParameters> params(new DownloadUrlParameters(
607 download_url_, 588 download_url_,
608 render_process_host_id, 589 render_process_host_id,
609 render_view_host_routing_id , 590 render_view_host_routing_id ,
610 resource_context)); 591 resource_context));
611 params->set_file_path(file); 592 params->set_file_path(file);
612 if (controller_->GetVisibleEntry()) 593 if (controller.GetVisibleEntry())
613 params->set_referrer( 594 params->set_referrer(
614 content::Referrer(controller_->GetVisibleEntry()->GetURL(), 595 content::Referrer(controller.GetVisibleEntry()->GetURL(),
615 blink::WebReferrerPolicyDefault)); 596 blink::WebReferrerPolicyDefault));
616 params->set_callback(base::Bind(&WebstoreInstaller::OnDownloadStarted, this)); 597 params->set_callback(base::Bind(&WebstoreInstaller::OnDownloadStarted, this));
617 download_manager->DownloadUrl(params.Pass()); 598 download_manager->DownloadUrl(params.Pass());
618 } 599 }
619 600
620 void WebstoreInstaller::ReportFailure(const std::string& error, 601 void WebstoreInstaller::ReportFailure(const std::string& error,
621 FailureReason reason) { 602 FailureReason reason) {
622 if (delegate_) { 603 if (delegate_) {
623 delegate_->OnExtensionInstallFailure(id_, error, reason); 604 delegate_->OnExtensionInstallFailure(id_, error, reason);
624 delegate_ = NULL; 605 delegate_ = NULL;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 1, 642 1,
662 kMaxSizeKb, 643 kMaxSizeKb,
663 kNumBuckets); 644 kNumBuckets);
664 } 645 }
665 UMA_HISTOGRAM_BOOLEAN( 646 UMA_HISTOGRAM_BOOLEAN(
666 "Extensions.WebstoreDownload.InterruptTotalSizeUnknown", 647 "Extensions.WebstoreDownload.InterruptTotalSizeUnknown",
667 total_bytes <= 0); 648 total_bytes <= 0);
668 } 649 }
669 650
670 } // namespace extensions 651 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698