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

Side by Side Diff: net/url_request/url_request_job.cc

Issue 2315613002: Extracted NetLog class's inner enum types into their own enum classes and (Closed)
Patch Set: Ran "git cl format" on code. Much formatting ensued. Created 4 years, 3 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 "net/url_request/url_request_job.h" 5 #include "net/url_request/url_request_job.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
11 #include "base/location.h" 11 #include "base/location.h"
12 #include "base/metrics/histogram_macros.h" 12 #include "base/metrics/histogram_macros.h"
13 #include "base/power_monitor/power_monitor.h" 13 #include "base/power_monitor/power_monitor.h"
14 #include "base/profiler/scoped_tracker.h" 14 #include "base/profiler/scoped_tracker.h"
15 #include "base/single_thread_task_runner.h" 15 #include "base/single_thread_task_runner.h"
16 #include "base/strings/string_number_conversions.h" 16 #include "base/strings/string_number_conversions.h"
17 #include "base/strings/string_split.h" 17 #include "base/strings/string_split.h"
18 #include "base/strings/string_util.h" 18 #include "base/strings/string_util.h"
19 #include "base/threading/thread_task_runner_handle.h" 19 #include "base/threading/thread_task_runner_handle.h"
20 #include "base/values.h" 20 #include "base/values.h"
21 #include "net/base/auth.h" 21 #include "net/base/auth.h"
22 #include "net/base/host_port_pair.h" 22 #include "net/base/host_port_pair.h"
23 #include "net/base/io_buffer.h" 23 #include "net/base/io_buffer.h"
24 #include "net/base/load_flags.h" 24 #include "net/base/load_flags.h"
25 #include "net/base/load_states.h" 25 #include "net/base/load_states.h"
26 #include "net/base/net_errors.h" 26 #include "net/base/net_errors.h"
27 #include "net/base/network_delegate.h" 27 #include "net/base/network_delegate.h"
28 #include "net/filter/filter.h" 28 #include "net/filter/filter.h"
29 #include "net/http/http_response_headers.h" 29 #include "net/http/http_response_headers.h"
30 #include "net/log/net_log_event_type.h"
30 #include "net/nqe/network_quality_estimator.h" 31 #include "net/nqe/network_quality_estimator.h"
31 #include "net/url_request/url_request_context.h" 32 #include "net/url_request/url_request_context.h"
32 33
33 namespace net { 34 namespace net {
34 35
35 namespace { 36 namespace {
36 37
37 // Callback for TYPE_URL_REQUEST_FILTERS_SET net-internals event. 38 // Callback for TYPE_URL_REQUEST_FILTERS_SET net-internals event.
38 std::unique_ptr<base::Value> FiltersSetCallback( 39 std::unique_ptr<base::Value> FiltersSetCallback(
39 Filter* filter, 40 Filter* filter,
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 if (request_->status().is_success()) 495 if (request_->status().is_success())
495 filter_ = SetupFilter(); 496 filter_ = SetupFilter();
496 497
497 if (!filter_.get()) { 498 if (!filter_.get()) {
498 std::string content_length; 499 std::string content_length;
499 request_->GetResponseHeaderByName("content-length", &content_length); 500 request_->GetResponseHeaderByName("content-length", &content_length);
500 if (!content_length.empty()) 501 if (!content_length.empty())
501 base::StringToInt64(content_length, &expected_content_size_); 502 base::StringToInt64(content_length, &expected_content_size_);
502 } else { 503 } else {
503 request_->net_log().AddEvent( 504 request_->net_log().AddEvent(
504 NetLog::TYPE_URL_REQUEST_FILTERS_SET, 505 NetLogEventType::URL_REQUEST_FILTERS_SET,
505 base::Bind(&FiltersSetCallback, base::Unretained(filter_.get()))); 506 base::Bind(&FiltersSetCallback, base::Unretained(filter_.get())));
506 } 507 }
507 508
508 request_->NotifyResponseStarted(URLRequestStatus()); 509 request_->NotifyResponseStarted(URLRequestStatus());
509 510
510 // |this| may be destroyed at this point. 511 // |this| may be destroyed at this point.
511 } 512 }
512 513
513 void URLRequestJob::ConvertResultToError(int result, Error* error, int* count) { 514 void URLRequestJob::ConvertResultToError(int result, Error* error, int* count) {
514 if (result >= 0) { 515 if (result >= 0) {
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 605
605 request_->set_is_pending(false); 606 request_->set_is_pending(false);
606 // With async IO, it's quite possible to have a few outstanding 607 // With async IO, it's quite possible to have a few outstanding
607 // requests. We could receive a request to Cancel, followed shortly 608 // requests. We could receive a request to Cancel, followed shortly
608 // by a successful IO. For tracking the status(), once there is 609 // by a successful IO. For tracking the status(), once there is
609 // an error, we do not change the status back to success. To 610 // an error, we do not change the status back to success. To
610 // enforce this, only set the status if the job is so far 611 // enforce this, only set the status if the job is so far
611 // successful. 612 // successful.
612 if (request_->status().is_success()) { 613 if (request_->status().is_success()) {
613 if (status.status() == URLRequestStatus::FAILED) 614 if (status.status() == URLRequestStatus::FAILED)
614 request_->net_log().AddEventWithNetErrorCode(NetLog::TYPE_FAILED, 615 request_->net_log().AddEventWithNetErrorCode(NetLogEventType::FAILED,
615 status.error()); 616 status.error());
616 request_->set_status(status); 617 request_->set_status(status);
617 } 618 }
618 619
619 // If the request succeeded (And wasn't cancelled) and the response code was 620 // If the request succeeded (And wasn't cancelled) and the response code was
620 // 4xx or 5xx, record whether or not the main frame was blank. This is 621 // 4xx or 5xx, record whether or not the main frame was blank. This is
621 // intended to be a short-lived histogram, used to figure out how important 622 // intended to be a short-lived histogram, used to figure out how important
622 // fixing http://crbug.com/331745 is. 623 // fixing http://crbug.com/331745 is.
623 if (request_->status().is_success()) { 624 if (request_->status().is_success()) {
624 int response_code = GetResponseCode(); 625 int response_code = GetResponseCode();
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 filter_needs_more_output_space_ = false; 784 filter_needs_more_output_space_ = false;
784 error = ERR_FAILED; 785 error = ERR_FAILED;
785 break; 786 break;
786 } 787 }
787 } 788 }
788 789
789 // If logging all bytes is enabled, log the filtered bytes read. 790 // If logging all bytes is enabled, log the filtered bytes read.
790 if (error == OK && filtered_data_len > 0 && 791 if (error == OK && filtered_data_len > 0 &&
791 request()->net_log().IsCapturing()) { 792 request()->net_log().IsCapturing()) {
792 request()->net_log().AddByteTransferEvent( 793 request()->net_log().AddByteTransferEvent(
793 NetLog::TYPE_URL_REQUEST_JOB_FILTERED_BYTES_READ, filtered_data_len, 794 NetLogEventType::URL_REQUEST_JOB_FILTERED_BYTES_READ,
794 filtered_read_buffer_->data()); 795 filtered_data_len, filtered_read_buffer_->data());
795 } 796 }
796 } else { 797 } else {
797 // we are done, or there is no data left. 798 // we are done, or there is no data left.
798 error = OK; 799 error = OK;
799 } 800 }
800 break; 801 break;
801 } 802 }
802 803
803 if (error == OK) { 804 if (error == OK) {
804 // When we successfully finished a read, we no longer need to save the 805 // When we successfully finished a read, we no longer need to save the
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
869 DCHECK_NE(ERR_IO_PENDING, error); 870 DCHECK_NE(ERR_IO_PENDING, error);
870 871
871 if (error != OK) { 872 if (error != OK) {
872 raw_read_buffer_ = nullptr; 873 raw_read_buffer_ = nullptr;
873 return; 874 return;
874 } 875 }
875 // If |filter_| is non-NULL, bytes will be logged after it is applied 876 // If |filter_| is non-NULL, bytes will be logged after it is applied
876 // instead. 877 // instead.
877 if (!filter_.get() && bytes_read > 0 && request()->net_log().IsCapturing()) { 878 if (!filter_.get() && bytes_read > 0 && request()->net_log().IsCapturing()) {
878 request()->net_log().AddByteTransferEvent( 879 request()->net_log().AddByteTransferEvent(
879 NetLog::TYPE_URL_REQUEST_JOB_BYTES_READ, bytes_read, 880 NetLogEventType::URL_REQUEST_JOB_BYTES_READ, bytes_read,
880 raw_read_buffer_->data()); 881 raw_read_buffer_->data());
881 } 882 }
882 883
883 if (bytes_read > 0) { 884 if (bytes_read > 0) {
884 RecordBytesRead(bytes_read); 885 RecordBytesRead(bytes_read);
885 } 886 }
886 raw_read_buffer_ = nullptr; 887 raw_read_buffer_ = nullptr;
887 } 888 }
888 889
889 void URLRequestJob::RecordBytesRead(int bytes_read) { 890 void URLRequestJob::RecordBytesRead(int bytes_read) {
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
1002 int64_t total_sent_bytes = GetTotalSentBytes(); 1003 int64_t total_sent_bytes = GetTotalSentBytes();
1003 DCHECK_GE(total_sent_bytes, last_notified_total_sent_bytes_); 1004 DCHECK_GE(total_sent_bytes, last_notified_total_sent_bytes_);
1004 if (total_sent_bytes > last_notified_total_sent_bytes_) { 1005 if (total_sent_bytes > last_notified_total_sent_bytes_) {
1005 network_delegate_->NotifyNetworkBytesSent( 1006 network_delegate_->NotifyNetworkBytesSent(
1006 request_, total_sent_bytes - last_notified_total_sent_bytes_); 1007 request_, total_sent_bytes - last_notified_total_sent_bytes_);
1007 } 1008 }
1008 last_notified_total_sent_bytes_ = total_sent_bytes; 1009 last_notified_total_sent_bytes_ = total_sent_bytes;
1009 } 1010 }
1010 1011
1011 } // namespace net 1012 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_request_http_job_unittest.cc ('k') | net/url_request/url_request_redirect_job.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698