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

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

Issue 10542153: NetLogEventParameter to Callback refactoring 11. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Response to comments 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
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 "content/browser/download/download_item_impl.h" 5 #include "content/browser/download/download_item_impl.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 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 delegate_delayed_complete_(false), 252 delegate_delayed_complete_(false),
253 bound_net_log_(bound_net_log), 253 bound_net_log_(bound_net_log),
254 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { 254 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
255 delegate_->Attach(); 255 delegate_->Attach();
256 Init(true /* actively downloading */, 256 Init(true /* actively downloading */,
257 download_net_logs::SRC_NEW_DOWNLOAD); 257 download_net_logs::SRC_NEW_DOWNLOAD);
258 258
259 // Link the event sources. 259 // Link the event sources.
260 bound_net_log_.AddEvent( 260 bound_net_log_.AddEvent(
261 net::NetLog::TYPE_DOWNLOAD_URL_REQUEST, 261 net::NetLog::TYPE_DOWNLOAD_URL_REQUEST,
262 make_scoped_refptr(new net::NetLogSourceParameter( 262 info.request_bound_net_log.source().ToEventParametersCallback());
263 "source_dependency",
264 info.request_bound_net_log.source())));
265 263
266 info.request_bound_net_log.AddEvent( 264 info.request_bound_net_log.AddEvent(
267 net::NetLog::TYPE_DOWNLOAD_STARTED, 265 net::NetLog::TYPE_DOWNLOAD_STARTED,
268 make_scoped_refptr(new net::NetLogSourceParameter( 266 bound_net_log_.source().ToEventParametersCallback());
269 "source_dependency",
270 bound_net_log_.source())));
271 } 267 }
272 268
273 // Constructing for the "Save Page As..." feature: 269 // Constructing for the "Save Page As..." feature:
274 DownloadItemImpl::DownloadItemImpl(Delegate* delegate, 270 DownloadItemImpl::DownloadItemImpl(Delegate* delegate,
275 const FilePath& path, 271 const FilePath& path,
276 const GURL& url, 272 const GURL& url,
277 bool is_otr, 273 bool is_otr,
278 DownloadId download_id, 274 DownloadId download_id,
279 const std::string& mime_type, 275 const std::string& mime_type,
280 const net::BoundNetLog& bound_net_log) 276 const net::BoundNetLog& bound_net_log)
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 DCHECK_EQ(DANGEROUS, GetSafetyState()); 397 DCHECK_EQ(DANGEROUS, GetSafetyState());
402 398
403 UMA_HISTOGRAM_ENUMERATION("Download.DangerousDownloadValidated", 399 UMA_HISTOGRAM_ENUMERATION("Download.DangerousDownloadValidated",
404 GetDangerType(), 400 GetDangerType(),
405 content::DOWNLOAD_DANGER_TYPE_MAX); 401 content::DOWNLOAD_DANGER_TYPE_MAX);
406 402
407 safety_state_ = DANGEROUS_BUT_VALIDATED; 403 safety_state_ = DANGEROUS_BUT_VALIDATED;
408 404
409 bound_net_log_.AddEvent( 405 bound_net_log_.AddEvent(
410 net::NetLog::TYPE_DOWNLOAD_ITEM_SAFETY_STATE_UPDATED, 406 net::NetLog::TYPE_DOWNLOAD_ITEM_SAFETY_STATE_UPDATED,
411 make_scoped_refptr(new download_net_logs::ItemCheckedParameters( 407 base::Bind(&download_net_logs::ItemCheckedCallback,
412 GetDangerType(), GetSafetyState()))); 408 GetDangerType(), GetSafetyState()));
413 409
414 UpdateObservers(); 410 UpdateObservers();
415 411
416 delegate_->MaybeCompleteDownload(this); 412 delegate_->MaybeCompleteDownload(this);
417 } 413 }
418 414
419 void DownloadItemImpl::ProgressComplete(int64 bytes_so_far, 415 void DownloadItemImpl::ProgressComplete(int64 bytes_so_far,
420 const std::string& final_hash) { 416 const std::string& final_hash) {
421 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 417 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
422 418
(...skipping 15 matching lines...) Expand all
438 received_bytes_ = bytes_so_far; 434 received_bytes_ = bytes_so_far;
439 435
440 // If we've received more data than we were expecting (bad server info?), 436 // If we've received more data than we were expecting (bad server info?),
441 // revert to 'unknown size mode'. 437 // revert to 'unknown size mode'.
442 if (received_bytes_ > total_bytes_) 438 if (received_bytes_ > total_bytes_)
443 total_bytes_ = 0; 439 total_bytes_ = 0;
444 440
445 if (bound_net_log_.IsLoggingAllEvents()) { 441 if (bound_net_log_.IsLoggingAllEvents()) {
446 bound_net_log_.AddEvent( 442 bound_net_log_.AddEvent(
447 net::NetLog::TYPE_DOWNLOAD_ITEM_UPDATED, 443 net::NetLog::TYPE_DOWNLOAD_ITEM_UPDATED,
448 make_scoped_refptr( 444 net::NetLog::Int64Callback("bytes_so_far", received_bytes_));
449 new download_net_logs::ItemUpdatedParameters(received_bytes_)));
450 } 445 }
451 } 446 }
452 447
453 // Updates from the download thread may have been posted while this download 448 // Updates from the download thread may have been posted while this download
454 // was being cancelled in the UI thread, so we'll accept them unless we're 449 // was being cancelled in the UI thread, so we'll accept them unless we're
455 // complete. 450 // complete.
456 void DownloadItemImpl::UpdateProgress(int64 bytes_so_far, 451 void DownloadItemImpl::UpdateProgress(int64 bytes_so_far,
457 int64 bytes_per_sec, 452 int64 bytes_per_sec,
458 const std::string& hash_state) { 453 const std::string& hash_state) {
459 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 454 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 if (state_ == new_state) 548 if (state_ == new_state)
554 return; 549 return;
555 550
556 DownloadState old_state = state_; 551 DownloadState old_state = state_;
557 state_ = new_state; 552 state_ = new_state;
558 553
559 switch (state_) { 554 switch (state_) {
560 case COMPLETE: 555 case COMPLETE:
561 bound_net_log_.AddEvent( 556 bound_net_log_.AddEvent(
562 net::NetLog::TYPE_DOWNLOAD_ITEM_FINISHED, 557 net::NetLog::TYPE_DOWNLOAD_ITEM_FINISHED,
563 make_scoped_refptr( 558 base::Bind(&download_net_logs::ItemFinishedCallback,
564 new download_net_logs::ItemFinishedParameters(received_bytes_, 559 received_bytes_, &hash_));
565 hash_)));
566 break; 560 break;
567 case INTERRUPTED: 561 case INTERRUPTED:
568 bound_net_log_.AddEvent( 562 bound_net_log_.AddEvent(
569 net::NetLog::TYPE_DOWNLOAD_ITEM_INTERRUPTED, 563 net::NetLog::TYPE_DOWNLOAD_ITEM_INTERRUPTED,
570 make_scoped_refptr( 564 base::Bind(&download_net_logs::ItemInterruptedCallback,
571 new download_net_logs::ItemInterruptedParameters(last_reason_, 565 last_reason_, received_bytes_, &hash_state_));
572 received_bytes_,
573 hash_state_)));
574 break; 566 break;
575 case CANCELLED: 567 case CANCELLED:
576 bound_net_log_.AddEvent( 568 bound_net_log_.AddEvent(
577 net::NetLog::TYPE_DOWNLOAD_ITEM_CANCELED, 569 net::NetLog::TYPE_DOWNLOAD_ITEM_CANCELED,
578 make_scoped_refptr( 570 base::Bind(&download_net_logs::ItemCanceledCallback,
579 new download_net_logs::ItemCanceledParameters(received_bytes_, 571 received_bytes_, &hash_state_));
580 hash_state_)));
581 break; 572 break;
582 default: 573 default:
583 break; 574 break;
584 } 575 }
585 576
586 VLOG(20) << " " << __FUNCTION__ << "()" << " this = " << DebugString(true); 577 VLOG(20) << " " << __FUNCTION__ << "()" << " this = " << DebugString(true);
587 578
588 UpdateObservers(); 579 UpdateObservers();
589 580
590 bool is_done = (state_ != IN_PROGRESS); 581 bool is_done = (state_ != IN_PROGRESS);
591 bool was_done = (old_state != IN_PROGRESS); 582 bool was_done = (old_state != IN_PROGRESS);
592 if (is_done && !was_done) 583 if (is_done && !was_done)
593 bound_net_log_.EndEvent(net::NetLog::TYPE_DOWNLOAD_ITEM_ACTIVE, NULL); 584 bound_net_log_.EndEvent(net::NetLog::TYPE_DOWNLOAD_ITEM_ACTIVE);
594 } 585 }
595 586
596 void DownloadItemImpl::SetDangerType(content::DownloadDangerType danger_type) { 587 void DownloadItemImpl::SetDangerType(content::DownloadDangerType danger_type) {
597 danger_type_ = danger_type; 588 danger_type_ = danger_type;
598 // Notify observers if the safety state has changed as a result of the new 589 // Notify observers if the safety state has changed as a result of the new
599 // danger type. 590 // danger type.
600 SafetyState updated_value = IsDangerous() ? 591 SafetyState updated_value = IsDangerous() ?
601 DownloadItem::DANGEROUS : DownloadItem::SAFE; 592 DownloadItem::DANGEROUS : DownloadItem::SAFE;
602 if (updated_value != safety_state_) { 593 if (updated_value != safety_state_) {
603 safety_state_ = updated_value; 594 safety_state_ = updated_value;
604 bound_net_log_.AddEvent( 595 bound_net_log_.AddEvent(
605 net::NetLog::TYPE_DOWNLOAD_ITEM_SAFETY_STATE_UPDATED, 596 net::NetLog::TYPE_DOWNLOAD_ITEM_SAFETY_STATE_UPDATED,
606 make_scoped_refptr(new download_net_logs::ItemCheckedParameters( 597 base::Bind(&download_net_logs::ItemCheckedCallback,
607 GetDangerType(), GetSafetyState()))); 598 GetDangerType(), GetSafetyState()));
608 UpdateObservers(); 599 UpdateObservers();
609 } 600 }
610 } 601 }
611 602
612 void DownloadItemImpl::SetFullPath(const FilePath& new_path) { 603 void DownloadItemImpl::SetFullPath(const FilePath& new_path) {
613 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 604 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
614 VLOG(20) << __FUNCTION__ << "()" 605 VLOG(20) << __FUNCTION__ << "()"
615 << " new_path = \"" << new_path.value() << "\"" 606 << " new_path = \"" << new_path.value() << "\""
616 << " " << DebugString(true); 607 << " " << DebugString(true);
617 DCHECK(!new_path.empty()); 608 DCHECK(!new_path.empty());
618 current_path_ = new_path; 609 current_path_ = new_path;
619 610
620 bound_net_log_.AddEvent( 611 bound_net_log_.AddEvent(
621 net::NetLog::TYPE_DOWNLOAD_ITEM_RENAMED, 612 net::NetLog::TYPE_DOWNLOAD_ITEM_RENAMED,
622 make_scoped_refptr( 613 base::Bind(&download_net_logs::ItemRenamedCallback,
623 new download_net_logs::ItemRenamedParameters( 614 &current_path_, &new_path));
624 current_path_.AsUTF8Unsafe(), new_path.AsUTF8Unsafe())));
625 } 615 }
626 616
627 void DownloadItemImpl::Interrupted(int64 size, 617 void DownloadItemImpl::Interrupted(int64 size,
628 const std::string& hash_state, 618 const std::string& hash_state,
629 content::DownloadInterruptReason reason) { 619 content::DownloadInterruptReason reason) {
630 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 620 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
631 621
632 if (!IsInProgress()) 622 if (!IsInProgress())
633 return; 623 return;
634 624
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
960 // Possibly has a 'download' attribute for the anchor. 950 // Possibly has a 'download' attribute for the anchor.
961 if (file_name.empty()) 951 if (file_name.empty())
962 file_name = suggested_filename_; 952 file_name = suggested_filename_;
963 // From the URL file name. 953 // From the URL file name.
964 if (file_name.empty()) 954 if (file_name.empty())
965 file_name = GetURL().ExtractFileName(); 955 file_name = GetURL().ExtractFileName();
966 } 956 }
967 957
968 bound_net_log_.BeginEvent( 958 bound_net_log_.BeginEvent(
969 net::NetLog::TYPE_DOWNLOAD_ITEM_ACTIVE, 959 net::NetLog::TYPE_DOWNLOAD_ITEM_ACTIVE,
970 make_scoped_refptr(new download_net_logs::ItemActivatedParameters( 960 base::Bind(&download_net_logs::ItemActivatedCallback,
971 download_type, 961 this, download_type, &file_name));
972 download_id_.local(),
973 GetOriginalUrl().spec(),
974 GetURL().spec(),
975 file_name,
976 GetDangerType(),
977 GetSafetyState(),
978 received_bytes_)));
979 962
980 // If this is not an active download, end the ACTIVE event now. 963 // If this is not an active download, end the ACTIVE event now.
981 if (!active) { 964 if (!active) {
982 bound_net_log_.AddEvent( 965 bound_net_log_.AddEvent(
983 net::NetLog::TYPE_DOWNLOAD_ITEM_IN_HISTORY, 966 net::NetLog::TYPE_DOWNLOAD_ITEM_IN_HISTORY,
984 make_scoped_refptr( 967 net::NetLog::Int64Callback("db_handle", db_handle_));
985 new download_net_logs::ItemInHistoryParameters(db_handle_)));
986 968
987 bound_net_log_.EndEvent(net::NetLog::TYPE_DOWNLOAD_ITEM_ACTIVE, NULL); 969 bound_net_log_.EndEvent(net::NetLog::TYPE_DOWNLOAD_ITEM_ACTIVE);
988 } 970 }
989 971
990 VLOG(20) << __FUNCTION__ << "() " << DebugString(true); 972 VLOG(20) << __FUNCTION__ << "() " << DebugString(true);
991 } 973 }
992 974
993 bool DownloadItemImpl::NeedsRename() const { 975 bool DownloadItemImpl::NeedsRename() const {
994 DCHECK(target_path_.DirName() == current_path_.DirName()); 976 DCHECK(target_path_.DirName() == current_path_.DirName());
995 return target_path_ != current_path_; 977 return target_path_ != current_path_;
996 } 978 }
997 979
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
1126 1108
1127 bool DownloadItemImpl::IsPersisted() const { 1109 bool DownloadItemImpl::IsPersisted() const {
1128 return is_persisted_; 1110 return is_persisted_;
1129 } 1111 }
1130 1112
1131 void DownloadItemImpl::SetDbHandle(int64 handle) { 1113 void DownloadItemImpl::SetDbHandle(int64 handle) {
1132 db_handle_ = handle; 1114 db_handle_ = handle;
1133 1115
1134 bound_net_log_.AddEvent( 1116 bound_net_log_.AddEvent(
1135 net::NetLog::TYPE_DOWNLOAD_ITEM_IN_HISTORY, 1117 net::NetLog::TYPE_DOWNLOAD_ITEM_IN_HISTORY,
1136 make_scoped_refptr( 1118 net::NetLog::Int64Callback("db_handle", db_handle_));
1137 new download_net_logs::ItemInHistoryParameters(db_handle_)));
1138 } 1119 }
1139 1120
1140 int64 DownloadItemImpl::GetDbHandle() const { return db_handle_; } 1121 int64 DownloadItemImpl::GetDbHandle() const { return db_handle_; }
1141 bool DownloadItemImpl::IsPaused() const { return is_paused_; } 1122 bool DownloadItemImpl::IsPaused() const { return is_paused_; }
1142 bool DownloadItemImpl::GetOpenWhenComplete() const { 1123 bool DownloadItemImpl::GetOpenWhenComplete() const {
1143 return open_when_complete_; 1124 return open_when_complete_;
1144 } 1125 }
1145 void DownloadItemImpl::SetOpenWhenComplete(bool open) { 1126 void DownloadItemImpl::SetOpenWhenComplete(bool open) {
1146 open_when_complete_ = open; 1127 open_when_complete_ = open;
1147 } 1128 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1202 std::map<const void*, ExternalData*>::iterator it = 1183 std::map<const void*, ExternalData*>::iterator it =
1203 external_data_map_.find(key); 1184 external_data_map_.find(key);
1204 1185
1205 if (it == external_data_map_.end()) { 1186 if (it == external_data_map_.end()) {
1206 external_data_map_[key] = data; 1187 external_data_map_[key] = data;
1207 } else if (it->second != data) { 1188 } else if (it->second != data) {
1208 delete it->second; 1189 delete it->second;
1209 it->second = data; 1190 it->second = data;
1210 } 1191 }
1211 } 1192 }
OLDNEW
« no previous file with comments | « content/browser/download/download_item_impl.h ('k') | content/browser/download/download_net_log_parameters.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698