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

Side by Side Diff: content/browser/download/download_item_impl.cc

Issue 12607011: Fix a crashing call to GURL::spec() in downloads_api.cc:DownloadItemToJSON() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: @r188114 Created 7 years, 9 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
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 // File method ordering: Methods in this file are in the same order as 5 // File method ordering: Methods in this file are in the same order as
6 // in download_item_impl.h, with the following exception: The public 6 // in download_item_impl.h, with the following exception: The public
7 // interface Start is placed in chronological order with the other 7 // interface Start is placed in chronological order with the other
8 // (private) routines that together define a DownloadItem's state 8 // (private) routines that together define a DownloadItem's state
9 // transitions as the download progresses. See "Download progression 9 // transitions as the download progresses. See "Download progression
10 // cascade" later in this file. 10 // cascade" later in this file.
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 467
468 bool DownloadItemImpl::IsInterrupted() const { 468 bool DownloadItemImpl::IsInterrupted() const {
469 return InternalToExternalState(state_) == INTERRUPTED; 469 return InternalToExternalState(state_) == INTERRUPTED;
470 } 470 }
471 471
472 bool DownloadItemImpl::IsComplete() const { 472 bool DownloadItemImpl::IsComplete() const {
473 return InternalToExternalState(state_) == COMPLETE; 473 return InternalToExternalState(state_) == COMPLETE;
474 } 474 }
475 475
476 const GURL& DownloadItemImpl::GetURL() const { 476 const GURL& DownloadItemImpl::GetURL() const {
477 return url_chain_.empty() ? 477 return url_chain_.empty() ? GURL::EmptyGURL() : url_chain_.back();
478 GURL::EmptyGURL() : url_chain_.back();
479 } 478 }
480 479
481 const std::vector<GURL>& DownloadItemImpl::GetUrlChain() const { 480 const std::vector<GURL>& DownloadItemImpl::GetUrlChain() const {
482 return url_chain_; 481 return url_chain_;
483 } 482 }
484 483
485 const GURL& DownloadItemImpl::GetOriginalUrl() const { 484 const GURL& DownloadItemImpl::GetOriginalUrl() const {
486 return url_chain_.front(); 485 // Be careful about taking the front() of possibly-empty vectors!
486 // http://crbug.com/190096
487 return url_chain_.empty() ? GURL::EmptyGURL() : url_chain_.front();
487 } 488 }
488 489
489 const GURL& DownloadItemImpl::GetReferrerUrl() const { 490 const GURL& DownloadItemImpl::GetReferrerUrl() const {
490 return referrer_url_; 491 return referrer_url_;
491 } 492 }
492 493
493 std::string DownloadItemImpl::GetSuggestedFilename() const { 494 std::string DownloadItemImpl::GetSuggestedFilename() const {
494 return suggested_filename_; 495 return suggested_filename_;
495 } 496 }
496 497
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
714 base::StringPrintf("{ id = %d" 715 base::StringPrintf("{ id = %d"
715 " state = %s", 716 " state = %s",
716 download_id_.local(), 717 download_id_.local(),
717 DebugDownloadStateString(state_)); 718 DebugDownloadStateString(state_));
718 719
719 // Construct a string of the URL chain. 720 // Construct a string of the URL chain.
720 std::string url_list("<none>"); 721 std::string url_list("<none>");
721 if (!url_chain_.empty()) { 722 if (!url_chain_.empty()) {
722 std::vector<GURL>::const_iterator iter = url_chain_.begin(); 723 std::vector<GURL>::const_iterator iter = url_chain_.begin();
723 std::vector<GURL>::const_iterator last = url_chain_.end(); 724 std::vector<GURL>::const_iterator last = url_chain_.end();
724 url_list = (*iter).spec(); 725 url_list = (*iter).is_valid() ? (*iter).spec() : "<invalid>";
725 ++iter; 726 ++iter;
726 for ( ; verbose && (iter != last); ++iter) { 727 for ( ; verbose && (iter != last); ++iter) {
727 url_list += " ->\n\t"; 728 url_list += " ->\n\t";
728 const GURL& next_url = *iter; 729 const GURL& next_url = *iter;
729 url_list += next_url.spec(); 730 url_list += next_url.is_valid() ? next_url.spec() : "<invalid>";
730 } 731 }
731 } 732 }
732 733
733 if (verbose) { 734 if (verbose) {
734 description += base::StringPrintf( 735 description += base::StringPrintf(
735 " total = %" PRId64 736 " total = %" PRId64
736 " received = %" PRId64 737 " received = %" PRId64
737 " reason = %s" 738 " reason = %s"
738 " paused = %c" 739 " paused = %c"
739 " resume_mode = %s" 740 " resume_mode = %s"
(...skipping 868 matching lines...) Expand 10 before | Expand all | Expand 10 after
1608 case RESUME_MODE_USER_CONTINUE: 1609 case RESUME_MODE_USER_CONTINUE:
1609 return "USER_CONTINUE"; 1610 return "USER_CONTINUE";
1610 case RESUME_MODE_USER_RESTART: 1611 case RESUME_MODE_USER_RESTART:
1611 return "USER_RESTART"; 1612 return "USER_RESTART";
1612 } 1613 }
1613 NOTREACHED() << "Unknown resume mode " << mode; 1614 NOTREACHED() << "Unknown resume mode " << mode;
1614 return "unknown"; 1615 return "unknown";
1615 } 1616 }
1616 1617
1617 } // namespace content 1618 } // namespace content
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/downloads/downloads_api.cc ('k') | content/browser/download/download_manager_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698