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

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

Issue 8571023: Implemented ExternalData interface on DownloadItem and used it for SafeBrowsing. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleaned up a bit. Created 9 years, 1 month 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "content/browser/download/download_item.h" 5 #include "content/browser/download/download_item.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/file_util.h" 11 #include "base/file_util.h"
12 #include "base/format_macros.h" 12 #include "base/format_macros.h"
13 #include "base/i18n/case_conversion.h" 13 #include "base/i18n/case_conversion.h"
14 #include "base/i18n/string_search.h" 14 #include "base/i18n/string_search.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/metrics/histogram.h" 16 #include "base/metrics/histogram.h"
17 #include "base/stl_util.h"
17 #include "base/stringprintf.h" 18 #include "base/stringprintf.h"
18 #include "base/utf_string_conversions.h" 19 #include "base/utf_string_conversions.h"
19 #include "content/browser/download/download_create_info.h" 20 #include "content/browser/download/download_create_info.h"
20 #include "content/browser/download/download_file.h" 21 #include "content/browser/download/download_file.h"
21 #include "content/browser/download/download_file_manager.h" 22 #include "content/browser/download/download_file_manager.h"
22 #include "content/browser/download/download_id.h" 23 #include "content/browser/download/download_id.h"
23 #include "content/browser/download/download_manager.h" 24 #include "content/browser/download/download_manager.h"
24 #include "content/browser/download/download_persistent_store_info.h" 25 #include "content/browser/download/download_persistent_store_info.h"
25 #include "content/browser/download/download_request_handle.h" 26 #include "content/browser/download/download_request_handle.h"
26 #include "content/browser/download/download_stats.h" 27 #include "content/browser/download/download_stats.h"
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 delegate_delayed_complete_(false) { 227 delegate_delayed_complete_(false) {
227 Init(true /* actively downloading */); 228 Init(true /* actively downloading */);
228 } 229 }
229 230
230 DownloadItem::~DownloadItem() { 231 DownloadItem::~DownloadItem() {
231 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. 232 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved.
232 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 233 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
233 234
234 TransitionTo(REMOVING); 235 TransitionTo(REMOVING);
235 download_manager_->AssertQueueStateConsistent(this); 236 download_manager_->AssertQueueStateConsistent(this);
237 STLDeleteContainerPairSecondPointers(
238 external_data_map_.begin(), external_data_map_.end());
236 } 239 }
237 240
238 void DownloadItem::AddObserver(Observer* observer) { 241 void DownloadItem::AddObserver(Observer* observer) {
239 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. 242 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved.
240 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 243 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
241 244
242 observers_.AddObserver(observer); 245 observers_.AddObserver(observer);
243 } 246 }
244 247
245 void DownloadItem::RemoveObserver(Observer* observer) { 248 void DownloadItem::RemoveObserver(Observer* observer) {
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 712
710 void DownloadItem::OffThreadCancel(DownloadFileManager* file_manager) { 713 void DownloadItem::OffThreadCancel(DownloadFileManager* file_manager) {
711 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 714 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
712 request_handle_->CancelRequest(); 715 request_handle_->CancelRequest();
713 716
714 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 717 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
715 base::Bind(&DownloadFileManager::CancelDownload, 718 base::Bind(&DownloadFileManager::CancelDownload,
716 file_manager, global_id())); 719 file_manager, global_id()));
717 } 720 }
718 721
722 DownloadItem::ExternalData*
723 DownloadItem::GetExternalData(void* key) {
724 if (external_data_map_.count(key) == 0)
725 return NULL;
726 return external_data_map_[key];
727 }
728
729 void DownloadItem::SetExternalData(
730 void* key, DownloadItem::ExternalData* data) {
731 if (external_data_map_.count(key) != 0) {
noelutz 2011/11/16 02:59:38 How about this to avoid all these lookups? std::m
Randy Smith (Not in Mondays) 2011/11/18 02:02:57 Yes, noticeably better. Thanks for the nudge. Do
732 if (external_data_map_[key] == data)
733 return; // Nothing to do.
734 delete external_data_map_[key];
735 }
736 external_data_map_[key] = data;
737 }
738
719 void DownloadItem::Init(bool active) { 739 void DownloadItem::Init(bool active) {
720 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. 740 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved.
721 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 741 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
722 742
723 UpdateTarget(); 743 UpdateTarget();
724 if (active) { 744 if (active) {
725 download_stats::RecordDownloadCount(download_stats::START_COUNT); 745 download_stats::RecordDownloadCount(download_stats::START_COUNT);
726 } 746 }
727 VLOG(20) << __FUNCTION__ << "() " << DebugString(true); 747 VLOG(20) << __FUNCTION__ << "() " << DebugString(true);
728 } 748 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 state_info_.target_name.value().c_str(), 817 state_info_.target_name.value().c_str(),
798 full_path().value().c_str()); 818 full_path().value().c_str());
799 } else { 819 } else {
800 description += base::StringPrintf(" url = \"%s\"", url_list.c_str()); 820 description += base::StringPrintf(" url = \"%s\"", url_list.c_str());
801 } 821 }
802 822
803 description += " }"; 823 description += " }";
804 824
805 return description; 825 return description;
806 } 826 }
OLDNEW
« content/browser/download/download_item.h ('K') | « content/browser/download/download_item.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698