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

Side by Side Diff: net/proxy/proxy_resolver_v8_tracing.cc

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/proxy/proxy_resolver_v8_tracing.h" 5 #include "net/proxy/proxy_resolver_v8_tracing.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop/message_loop_proxy.h" 8 #include "base/message_loop/message_loop_proxy.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 HostResolver* host_resolver(); 138 HostResolver* host_resolver();
139 ProxyResolverErrorObserver* error_observer(); 139 ProxyResolverErrorObserver* error_observer();
140 NetLog* net_log(); 140 NetLog* net_log();
141 141
142 // Invokes the user's callback. 142 // Invokes the user's callback.
143 void NotifyCaller(int result); 143 void NotifyCaller(int result);
144 void NotifyCallerOnOriginLoop(int result); 144 void NotifyCallerOnOriginLoop(int result);
145 145
146 void RecordMetrics() const; 146 void RecordMetrics() const;
147 147
148 void Start(Operation op, bool blocking_dns, 148 void Start(Operation op,
149 bool blocking_dns,
149 const CompletionCallback& callback); 150 const CompletionCallback& callback);
150 151
151 void ExecuteBlocking(); 152 void ExecuteBlocking();
152 void ExecuteNonBlocking(); 153 void ExecuteNonBlocking();
153 int ExecuteProxyResolver(); 154 int ExecuteProxyResolver();
154 155
155 // Implementation of ProxyResolverv8::JSBindings 156 // Implementation of ProxyResolverv8::JSBindings
156 virtual bool ResolveDns(const std::string& host, 157 virtual bool ResolveDns(const std::string& host,
157 ResolveDnsOperation op, 158 ResolveDnsOperation op,
158 std::string* output, 159 std::string* output,
159 bool* terminate) OVERRIDE; 160 bool* terminate) OVERRIDE;
160 virtual void Alert(const base::string16& message) OVERRIDE; 161 virtual void Alert(const base::string16& message) OVERRIDE;
161 virtual void OnError(int line_number, const base::string16& error) OVERRIDE; 162 virtual void OnError(int line_number, const base::string16& error) OVERRIDE;
162 163
163 bool ResolveDnsBlocking(const std::string& host, 164 bool ResolveDnsBlocking(const std::string& host,
164 ResolveDnsOperation op, 165 ResolveDnsOperation op,
165 std::string* output); 166 std::string* output);
166 167
167 bool ResolveDnsNonBlocking(const std::string& host, 168 bool ResolveDnsNonBlocking(const std::string& host,
168 ResolveDnsOperation op, 169 ResolveDnsOperation op,
169 std::string* output, 170 std::string* output,
170 bool* terminate); 171 bool* terminate);
171 172
172 bool PostDnsOperationAndWait(const std::string& host, 173 bool PostDnsOperationAndWait(const std::string& host,
173 ResolveDnsOperation op, 174 ResolveDnsOperation op,
174 bool* completed_synchronously) 175 bool* completed_synchronously)
175 WARN_UNUSED_RESULT; 176 WARN_UNUSED_RESULT;
176 177
177 void DoDnsOperation(); 178 void DoDnsOperation();
178 void OnDnsOperationComplete(int result); 179 void OnDnsOperationComplete(int result);
179 180
180 void ScheduleRestartWithBlockingDns(); 181 void ScheduleRestartWithBlockingDns();
181 182
182 bool GetDnsFromLocalCache(const std::string& host, ResolveDnsOperation op, 183 bool GetDnsFromLocalCache(const std::string& host,
183 std::string* output, bool* return_value); 184 ResolveDnsOperation op,
185 std::string* output,
186 bool* return_value);
184 187
185 void SaveDnsToLocalCache(const std::string& host, ResolveDnsOperation op, 188 void SaveDnsToLocalCache(const std::string& host,
186 int net_error, const net::AddressList& addresses); 189 ResolveDnsOperation op,
190 int net_error,
191 const net::AddressList& addresses);
187 192
188 // Builds a RequestInfo to service the specified PAC DNS operation. 193 // Builds a RequestInfo to service the specified PAC DNS operation.
189 static HostResolver::RequestInfo MakeDnsRequestInfo(const std::string& host, 194 static HostResolver::RequestInfo MakeDnsRequestInfo(const std::string& host,
190 ResolveDnsOperation op); 195 ResolveDnsOperation op);
191 196
192 // Makes a key for looking up |host, op| in |dns_cache_|. Strings are used for 197 // Makes a key for looking up |host, op| in |dns_cache_|. Strings are used for
193 // convenience, to avoid defining custom comparators. 198 // convenience, to avoid defining custom comparators.
194 static std::string MakeDnsCacheKey(const std::string& host, 199 static std::string MakeDnsCacheKey(const std::string& host,
195 ResolveDnsOperation op); 200 ResolveDnsOperation op);
196 201
197 void HandleAlertOrError(bool is_alert, int line_number, 202 void HandleAlertOrError(bool is_alert,
203 int line_number,
198 const base::string16& message); 204 const base::string16& message);
199 void DispatchBufferedAlertsAndErrors(); 205 void DispatchBufferedAlertsAndErrors();
200 void DispatchAlertOrError(bool is_alert, int line_number, 206 void DispatchAlertOrError(bool is_alert,
207 int line_number,
201 const base::string16& message); 208 const base::string16& message);
202 209
203 void LogEventToCurrentRequestAndGlobally( 210 void LogEventToCurrentRequestAndGlobally(
204 NetLog::EventType type, 211 NetLog::EventType type,
205 const NetLog::ParametersCallback& parameters_callback); 212 const NetLog::ParametersCallback& parameters_callback);
206 213
207 // The thread which called into ProxyResolverV8Tracing, and on which the 214 // The thread which called into ProxyResolverV8Tracing, and on which the
208 // completion callback is expected to run. 215 // completion callback is expected to run.
209 scoped_refptr<base::MessageLoopProxy> origin_loop_; 216 scoped_refptr<base::MessageLoopProxy> origin_loop_;
210 217
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 NetLog* ProxyResolverV8Tracing::Job::net_log() { 493 NetLog* ProxyResolverV8Tracing::Job::net_log() {
487 return parent_->net_log_; 494 return parent_->net_log_;
488 } 495 }
489 496
490 void ProxyResolverV8Tracing::Job::NotifyCaller(int result) { 497 void ProxyResolverV8Tracing::Job::NotifyCaller(int result) {
491 CheckIsOnWorkerThread(); 498 CheckIsOnWorkerThread();
492 499
493 metrics_end_time_ = base::TimeTicks::Now(); 500 metrics_end_time_ = base::TimeTicks::Now();
494 501
495 origin_loop_->PostTask( 502 origin_loop_->PostTask(
496 FROM_HERE, 503 FROM_HERE, base::Bind(&Job::NotifyCallerOnOriginLoop, this, result));
497 base::Bind(&Job::NotifyCallerOnOriginLoop, this, result));
498 } 504 }
499 505
500 void ProxyResolverV8Tracing::Job::NotifyCallerOnOriginLoop(int result) { 506 void ProxyResolverV8Tracing::Job::NotifyCallerOnOriginLoop(int result) {
501 CheckIsOnOriginThread(); 507 CheckIsOnOriginThread();
502 508
503 if (cancelled_.IsSet()) 509 if (cancelled_.IsSet())
504 return; 510 return;
505 511
506 DCHECK(!callback_.is_null()); 512 DCHECK(!callback_.is_null());
507 DCHECK(!pending_dns_); 513 DCHECK(!pending_dns_);
(...skipping 16 matching lines...) Expand all
524 530
525 owned_self_reference_ = NULL; 531 owned_self_reference_ = NULL;
526 } 532 }
527 533
528 void ProxyResolverV8Tracing::Job::RecordMetrics() const { 534 void ProxyResolverV8Tracing::Job::RecordMetrics() const {
529 CheckIsOnOriginThread(); 535 CheckIsOnOriginThread();
530 DCHECK_EQ(GET_PROXY_FOR_URL, operation_); 536 DCHECK_EQ(GET_PROXY_FOR_URL, operation_);
531 537
532 base::TimeTicks now = base::TimeTicks::Now(); 538 base::TimeTicks now = base::TimeTicks::Now();
533 539
534 // Metrics are output for each completed request to GetProxyForURL()). 540 // Metrics are output for each completed request to GetProxyForURL()).
535 // 541 //
536 // Note that a different set of histograms is used to record the metrics for 542 // Note that a different set of histograms is used to record the metrics for
537 // requests that completed in non-blocking mode versus blocking mode. The 543 // requests that completed in non-blocking mode versus blocking mode. The
538 // expectation is for requests to complete in non-blocking mode each time. 544 // expectation is for requests to complete in non-blocking mode each time.
539 // If they don't then something strange is happening, and the purpose of the 545 // If they don't then something strange is happening, and the purpose of the
540 // seprate statistics is to better understand that trend. 546 // seprate statistics is to better understand that trend.
541 #define UPDATE_HISTOGRAMS(base_name) \ 547 #define UPDATE_HISTOGRAMS(base_name) \
542 do {\ 548 do { \
543 UMA_HISTOGRAM_MEDIUM_TIMES(base_name "TotalTime", now - metrics_start_time_);\ 549 UMA_HISTOGRAM_MEDIUM_TIMES(base_name "TotalTime", \
544 UMA_HISTOGRAM_MEDIUM_TIMES(base_name "TotalTimeWorkerThread",\ 550 now - metrics_start_time_); \
545 metrics_end_time_ - metrics_start_time_);\ 551 UMA_HISTOGRAM_MEDIUM_TIMES(base_name "TotalTimeWorkerThread", \
546 UMA_HISTOGRAM_TIMES(base_name "OriginThreadLatency",\ 552 metrics_end_time_ - metrics_start_time_); \
547 now - metrics_end_time_);\ 553 UMA_HISTOGRAM_TIMES(base_name "OriginThreadLatency", \
548 UMA_HISTOGRAM_MEDIUM_TIMES(base_name "TotalTimeDNS",\ 554 now - metrics_end_time_); \
549 metrics_dns_total_time_);\ 555 UMA_HISTOGRAM_MEDIUM_TIMES(base_name "TotalTimeDNS", \
550 UMA_HISTOGRAM_MEDIUM_TIMES(base_name "ExecutionTime",\ 556 metrics_dns_total_time_); \
551 metrics_execution_time_);\ 557 UMA_HISTOGRAM_MEDIUM_TIMES(base_name "ExecutionTime", \
552 UMA_HISTOGRAM_MEDIUM_TIMES(base_name "AbandonedExecutionTotalTime",\ 558 metrics_execution_time_); \
553 metrics_abandoned_execution_total_time_);\ 559 UMA_HISTOGRAM_MEDIUM_TIMES(base_name "AbandonedExecutionTotalTime", \
554 UMA_HISTOGRAM_MEDIUM_TIMES(base_name "DnsWaitTotalTime",\ 560 metrics_abandoned_execution_total_time_); \
555 metrics_nonblocking_dns_wait_total_time_);\ 561 UMA_HISTOGRAM_MEDIUM_TIMES(base_name "DnsWaitTotalTime", \
556 UMA_HISTOGRAM_CUSTOM_COUNTS(\ 562 metrics_nonblocking_dns_wait_total_time_); \
557 base_name "NumRestarts", metrics_num_executions_ - 1,\ 563 UMA_HISTOGRAM_CUSTOM_COUNTS(base_name "NumRestarts", \
558 1, kMaxUniqueResolveDnsPerExec, kMaxUniqueResolveDnsPerExec);\ 564 metrics_num_executions_ - 1, \
559 UMA_HISTOGRAM_CUSTOM_COUNTS(\ 565 1, \
560 base_name "UniqueDNS", metrics_num_unique_dns_,\ 566 kMaxUniqueResolveDnsPerExec, \
561 1, kMaxUniqueResolveDnsPerExec, kMaxUniqueResolveDnsPerExec);\ 567 kMaxUniqueResolveDnsPerExec); \
562 UMA_HISTOGRAM_COUNTS_100(base_name "NumAlerts", metrics_num_alerts_);\ 568 UMA_HISTOGRAM_CUSTOM_COUNTS(base_name "UniqueDNS", \
563 UMA_HISTOGRAM_CUSTOM_COUNTS(\ 569 metrics_num_unique_dns_, \
564 base_name "NumErrors", metrics_num_errors_, 1, 10, 10);\ 570 1, \
571 kMaxUniqueResolveDnsPerExec, \
572 kMaxUniqueResolveDnsPerExec); \
573 UMA_HISTOGRAM_COUNTS_100(base_name "NumAlerts", metrics_num_alerts_); \
574 UMA_HISTOGRAM_CUSTOM_COUNTS( \
575 base_name "NumErrors", metrics_num_errors_, 1, 10, 10); \
565 } while (false) 576 } while (false)
566 577
567 if (!blocking_dns_) 578 if (!blocking_dns_)
568 UPDATE_HISTOGRAMS("Net.ProxyResolver."); 579 UPDATE_HISTOGRAMS("Net.ProxyResolver.");
569 else 580 else
570 UPDATE_HISTOGRAMS("Net.ProxyResolver.BlockingDNSMode."); 581 UPDATE_HISTOGRAMS("Net.ProxyResolver.BlockingDNSMode.");
571 582
572 #undef UPDATE_HISTOGRAMS 583 #undef UPDATE_HISTOGRAMS
573 584
574 // Histograms to better understand http://crbug.com/240536 -- long 585 // Histograms to better understand http://crbug.com/240536 -- long
(...skipping 20 matching lines...) Expand all
595 metrics_execution_time_); 606 metrics_execution_time_);
596 } 607 }
597 608
598 if (url_size > 131072) { 609 if (url_size > 131072) {
599 UMA_HISTOGRAM_MEDIUM_TIMES("Net.ProxyResolver.ExecutionTime_UrlOver128K", 610 UMA_HISTOGRAM_MEDIUM_TIMES("Net.ProxyResolver.ExecutionTime_UrlOver128K",
600 metrics_execution_time_); 611 metrics_execution_time_);
601 } 612 }
602 } 613 }
603 } 614 }
604 615
605 616 void ProxyResolverV8Tracing::Job::Start(Operation op,
606 void ProxyResolverV8Tracing::Job::Start(Operation op, bool blocking_dns, 617 bool blocking_dns,
607 const CompletionCallback& callback) { 618 const CompletionCallback& callback) {
608 CheckIsOnOriginThread(); 619 CheckIsOnOriginThread();
609 620
610 metrics_start_time_ = base::TimeTicks::Now(); 621 metrics_start_time_ = base::TimeTicks::Now();
611 operation_ = op; 622 operation_ = op;
612 blocking_dns_ = blocking_dns; 623 blocking_dns_ = blocking_dns;
613 SetCallback(callback); 624 SetCallback(callback);
614 625
615 owned_self_reference_ = this; 626 owned_self_reference_ = this;
616 627
617 worker_loop()->PostTask(FROM_HERE, 628 worker_loop()->PostTask(FROM_HERE,
618 blocking_dns_ ? base::Bind(&Job::ExecuteBlocking, this) : 629 blocking_dns_
619 base::Bind(&Job::ExecuteNonBlocking, this)); 630 ? base::Bind(&Job::ExecuteBlocking, this)
631 : base::Bind(&Job::ExecuteNonBlocking, this));
620 } 632 }
621 633
622 void ProxyResolverV8Tracing::Job::ExecuteBlocking() { 634 void ProxyResolverV8Tracing::Job::ExecuteBlocking() {
623 CheckIsOnWorkerThread(); 635 CheckIsOnWorkerThread();
624 DCHECK(blocking_dns_); 636 DCHECK(blocking_dns_);
625 637
626 if (cancelled_.IsSet()) 638 if (cancelled_.IsSet())
627 return; 639 return;
628 640
629 NotifyCaller(ExecuteProxyResolver()); 641 NotifyCaller(ExecuteProxyResolver());
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 680
669 base::TimeTicks start = base::TimeTicks::Now(); 681 base::TimeTicks start = base::TimeTicks::Now();
670 682
671 JSBindings* prev_bindings = v8_resolver()->js_bindings(); 683 JSBindings* prev_bindings = v8_resolver()->js_bindings();
672 v8_resolver()->set_js_bindings(this); 684 v8_resolver()->set_js_bindings(this);
673 685
674 int result = ERR_UNEXPECTED; // Initialized to silence warnings. 686 int result = ERR_UNEXPECTED; // Initialized to silence warnings.
675 687
676 switch (operation_) { 688 switch (operation_) {
677 case SET_PAC_SCRIPT: 689 case SET_PAC_SCRIPT:
678 result = v8_resolver()->SetPacScript( 690 result = v8_resolver()->SetPacScript(script_data_, CompletionCallback());
679 script_data_, CompletionCallback());
680 break; 691 break;
681 case GET_PROXY_FOR_URL: 692 case GET_PROXY_FOR_URL:
682 result = v8_resolver()->GetProxyForURL( 693 result = v8_resolver()->GetProxyForURL(
683 url_, 694 url_,
684 // Important: Do not write directly into |user_results_|, since if the 695 // Important: Do not write directly into |user_results_|, since if the
685 // request were to be cancelled from the origin thread, must guarantee 696 // request were to be cancelled from the origin thread, must guarantee
686 // that |user_results_| is not accessed anymore. 697 // that |user_results_| is not accessed anymore.
687 &results_, 698 &results_,
688 CompletionCallback(), 699 CompletionCallback(),
689 NULL, 700 NULL,
690 bound_net_log_); 701 bound_net_log_);
691 break; 702 break;
692 } 703 }
693 704
694 v8_resolver()->set_js_bindings(prev_bindings); 705 v8_resolver()->set_js_bindings(prev_bindings);
695 706
696 metrics_execution_time_ = base::TimeTicks::Now() - start; 707 metrics_execution_time_ = base::TimeTicks::Now() - start;
697 708
698 return result; 709 return result;
699 } 710 }
700 711
701 bool ProxyResolverV8Tracing::Job::ResolveDns(const std::string& host, 712 bool ProxyResolverV8Tracing::Job::ResolveDns(const std::string& host,
702 ResolveDnsOperation op, 713 ResolveDnsOperation op,
703 std::string* output, 714 std::string* output,
704 bool* terminate) { 715 bool* terminate) {
705 if (cancelled_.IsSet()) { 716 if (cancelled_.IsSet()) {
706 *terminate = true; 717 *terminate = true;
707 return false; 718 return false;
708 } 719 }
709 720
710 if ((op == DNS_RESOLVE || op == DNS_RESOLVE_EX) && host.empty()) { 721 if ((op == DNS_RESOLVE || op == DNS_RESOLVE_EX) && host.empty()) {
711 // a DNS resolve with an empty hostname is considered an error. 722 // a DNS resolve with an empty hostname is considered an error.
712 return false; 723 return false;
713 } 724 }
714 725
715 return blocking_dns_ ? 726 return blocking_dns_ ? ResolveDnsBlocking(host, op, output)
716 ResolveDnsBlocking(host, op, output) : 727 : ResolveDnsNonBlocking(host, op, output, terminate);
717 ResolveDnsNonBlocking(host, op, output, terminate);
718 } 728 }
719 729
720 void ProxyResolverV8Tracing::Job::Alert(const base::string16& message) { 730 void ProxyResolverV8Tracing::Job::Alert(const base::string16& message) {
721 HandleAlertOrError(true, -1, message); 731 HandleAlertOrError(true, -1, message);
722 } 732 }
723 733
724 void ProxyResolverV8Tracing::Job::OnError(int line_number, 734 void ProxyResolverV8Tracing::Job::OnError(int line_number,
725 const base::string16& error) { 735 const base::string16& error) {
726 HandleAlertOrError(false, line_number, error); 736 HandleAlertOrError(false, line_number, error);
727 } 737 }
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
805 // Otherwise if the result was not in the cache, then a DNS request has 815 // Otherwise if the result was not in the cache, then a DNS request has
806 // been started. Abandon this invocation of FindProxyForURL(), it will be 816 // been started. Abandon this invocation of FindProxyForURL(), it will be
807 // restarted once the DNS request completes. 817 // restarted once the DNS request completes.
808 abandoned_ = true; 818 abandoned_ = true;
809 *terminate = true; 819 *terminate = true;
810 last_num_dns_ = num_dns_; 820 last_num_dns_ = num_dns_;
811 return false; 821 return false;
812 } 822 }
813 823
814 bool ProxyResolverV8Tracing::Job::PostDnsOperationAndWait( 824 bool ProxyResolverV8Tracing::Job::PostDnsOperationAndWait(
815 const std::string& host, ResolveDnsOperation op, 825 const std::string& host,
826 ResolveDnsOperation op,
816 bool* completed_synchronously) { 827 bool* completed_synchronously) {
817
818 base::TimeTicks start = base::TimeTicks::Now(); 828 base::TimeTicks start = base::TimeTicks::Now();
819 829
820 // Post the DNS request to the origin thread. 830 // Post the DNS request to the origin thread.
821 DCHECK(!pending_dns_); 831 DCHECK(!pending_dns_);
822 metrics_pending_dns_start_ = base::TimeTicks::Now(); 832 metrics_pending_dns_start_ = base::TimeTicks::Now();
823 pending_dns_host_ = host; 833 pending_dns_host_ = host;
824 pending_dns_op_ = op; 834 pending_dns_op_ = op;
825 origin_loop_->PostTask(FROM_HERE, base::Bind(&Job::DoDnsOperation, this)); 835 origin_loop_->PostTask(FROM_HERE, base::Bind(&Job::DoDnsOperation, this));
826 836
827 event_.Wait(); 837 event_.Wait();
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
880 event_.Signal(); 890 event_.Signal();
881 } 891 }
882 } 892 }
883 893
884 void ProxyResolverV8Tracing::Job::OnDnsOperationComplete(int result) { 894 void ProxyResolverV8Tracing::Job::OnDnsOperationComplete(int result) {
885 CheckIsOnOriginThread(); 895 CheckIsOnOriginThread();
886 896
887 DCHECK(!cancelled_.IsSet()); 897 DCHECK(!cancelled_.IsSet());
888 DCHECK(pending_dns_completed_synchronously_ == (pending_dns_ == NULL)); 898 DCHECK(pending_dns_completed_synchronously_ == (pending_dns_ == NULL));
889 899
890 SaveDnsToLocalCache(pending_dns_host_, pending_dns_op_, result, 900 SaveDnsToLocalCache(
891 pending_dns_addresses_); 901 pending_dns_host_, pending_dns_op_, result, pending_dns_addresses_);
892 pending_dns_ = NULL; 902 pending_dns_ = NULL;
893 903
894 metrics_dns_total_time_ += 904 metrics_dns_total_time_ +=
895 base::TimeTicks::Now() - metrics_pending_dns_start_; 905 base::TimeTicks::Now() - metrics_pending_dns_start_;
896 906
897 if (blocking_dns_) { 907 if (blocking_dns_) {
898 event_.Signal(); 908 event_.Signal();
899 return; 909 return;
900 } 910 }
901 911
(...skipping 11 matching lines...) Expand all
913 DCHECK(!should_restart_with_blocking_dns_); 923 DCHECK(!should_restart_with_blocking_dns_);
914 DCHECK(!abandoned_); 924 DCHECK(!abandoned_);
915 DCHECK(!blocking_dns_); 925 DCHECK(!blocking_dns_);
916 926
917 abandoned_ = true; 927 abandoned_ = true;
918 928
919 // The restart will happen after ExecuteNonBlocking() finishes. 929 // The restart will happen after ExecuteNonBlocking() finishes.
920 should_restart_with_blocking_dns_ = true; 930 should_restart_with_blocking_dns_ = true;
921 } 931 }
922 932
923 bool ProxyResolverV8Tracing::Job::GetDnsFromLocalCache( 933 bool ProxyResolverV8Tracing::Job::GetDnsFromLocalCache(const std::string& host,
924 const std::string& host, 934 ResolveDnsOperation op,
925 ResolveDnsOperation op, 935 std::string* output,
926 std::string* output, 936 bool* return_value) {
927 bool* return_value) {
928 CheckIsOnWorkerThread(); 937 CheckIsOnWorkerThread();
929 938
930 DnsCache::const_iterator it = dns_cache_.find(MakeDnsCacheKey(host, op)); 939 DnsCache::const_iterator it = dns_cache_.find(MakeDnsCacheKey(host, op));
931 if (it == dns_cache_.end()) 940 if (it == dns_cache_.end())
932 return false; 941 return false;
933 942
934 *output = it->second; 943 *output = it->second;
935 *return_value = !it->second.empty(); 944 *return_value = !it->second.empty();
936 return true; 945 return true;
937 } 946 }
938 947
939 void ProxyResolverV8Tracing::Job::SaveDnsToLocalCache( 948 void ProxyResolverV8Tracing::Job::SaveDnsToLocalCache(
940 const std::string& host, 949 const std::string& host,
941 ResolveDnsOperation op, 950 ResolveDnsOperation op,
942 int net_error, 951 int net_error,
943 const net::AddressList& addresses) { 952 const net::AddressList& addresses) {
944 CheckIsOnOriginThread(); 953 CheckIsOnOriginThread();
945 954
946 // Serialize the result into a string to save to the cache. 955 // Serialize the result into a string to save to the cache.
947 std::string cache_value; 956 std::string cache_value;
948 if (net_error != OK) { 957 if (net_error != OK) {
949 cache_value = std::string(); 958 cache_value = std::string();
950 } else if (op == DNS_RESOLVE || op == MY_IP_ADDRESS) { 959 } else if (op == DNS_RESOLVE || op == MY_IP_ADDRESS) {
951 // dnsResolve() and myIpAddress() are expected to return a single IP 960 // dnsResolve() and myIpAddress() are expected to return a single IP
952 // address. 961 // address.
953 cache_value = addresses.front().ToStringWithoutPort(); 962 cache_value = addresses.front().ToStringWithoutPort();
954 } else { 963 } else {
955 // The *Ex versions are expected to return a semi-colon separated list. 964 // The *Ex versions are expected to return a semi-colon separated list.
956 for (AddressList::const_iterator iter = addresses.begin(); 965 for (AddressList::const_iterator iter = addresses.begin();
957 iter != addresses.end(); ++iter) { 966 iter != addresses.end();
967 ++iter) {
958 if (!cache_value.empty()) 968 if (!cache_value.empty())
959 cache_value += ";"; 969 cache_value += ";";
960 cache_value += iter->ToStringWithoutPort(); 970 cache_value += iter->ToStringWithoutPort();
961 } 971 }
962 } 972 }
963 973
964 dns_cache_[MakeDnsCacheKey(host, op)] = cache_value; 974 dns_cache_[MakeDnsCacheKey(host, op)] = cache_value;
965 } 975 }
966 976
967 // static 977 // static
968 HostResolver::RequestInfo ProxyResolverV8Tracing::Job::MakeDnsRequestInfo( 978 HostResolver::RequestInfo ProxyResolverV8Tracing::Job::MakeDnsRequestInfo(
969 const std::string& host, ResolveDnsOperation op) { 979 const std::string& host,
980 ResolveDnsOperation op) {
970 HostPortPair host_port = HostPortPair(host, 80); 981 HostPortPair host_port = HostPortPair(host, 80);
971 if (op == MY_IP_ADDRESS || op == MY_IP_ADDRESS_EX) { 982 if (op == MY_IP_ADDRESS || op == MY_IP_ADDRESS_EX) {
972 host_port.set_host(GetHostName()); 983 host_port.set_host(GetHostName());
973 } 984 }
974 985
975 HostResolver::RequestInfo info(host_port); 986 HostResolver::RequestInfo info(host_port);
976 987
977 // The non-ex flavors are limited to IPv4 results. 988 // The non-ex flavors are limited to IPv4 results.
978 if (op == MY_IP_ADDRESS || op == DNS_RESOLVE) { 989 if (op == MY_IP_ADDRESS || op == DNS_RESOLVE) {
979 info.set_address_family(ADDRESS_FAMILY_IPV4); 990 info.set_address_family(ADDRESS_FAMILY_IPV4);
980 } 991 }
981 992
982 return info; 993 return info;
983 } 994 }
984 995
985 std::string ProxyResolverV8Tracing::Job::MakeDnsCacheKey( 996 std::string ProxyResolverV8Tracing::Job::MakeDnsCacheKey(
986 const std::string& host, ResolveDnsOperation op) { 997 const std::string& host,
998 ResolveDnsOperation op) {
987 return base::StringPrintf("%d:%s", op, host.c_str()); 999 return base::StringPrintf("%d:%s", op, host.c_str());
988 } 1000 }
989 1001
990 void ProxyResolverV8Tracing::Job::HandleAlertOrError( 1002 void ProxyResolverV8Tracing::Job::HandleAlertOrError(
991 bool is_alert, 1003 bool is_alert,
992 int line_number, 1004 int line_number,
993 const base::string16& message) { 1005 const base::string16& message) {
994 CheckIsOnWorkerThread(); 1006 CheckIsOnWorkerThread();
995 1007
996 if (cancelled_.IsSet()) 1008 if (cancelled_.IsSet())
(...skipping 30 matching lines...) Expand all
1027 DCHECK(!blocking_dns_); 1039 DCHECK(!blocking_dns_);
1028 DCHECK(!abandoned_); 1040 DCHECK(!abandoned_);
1029 1041
1030 for (size_t i = 0; i < alerts_and_errors_.size(); ++i) { 1042 for (size_t i = 0; i < alerts_and_errors_.size(); ++i) {
1031 const AlertOrError& x = alerts_and_errors_[i]; 1043 const AlertOrError& x = alerts_and_errors_[i];
1032 DispatchAlertOrError(x.is_alert, x.line_number, x.message); 1044 DispatchAlertOrError(x.is_alert, x.line_number, x.message);
1033 } 1045 }
1034 } 1046 }
1035 1047
1036 void ProxyResolverV8Tracing::Job::DispatchAlertOrError( 1048 void ProxyResolverV8Tracing::Job::DispatchAlertOrError(
1037 bool is_alert, int line_number, const base::string16& message) { 1049 bool is_alert,
1050 int line_number,
1051 const base::string16& message) {
1038 CheckIsOnWorkerThread(); 1052 CheckIsOnWorkerThread();
1039 1053
1040 // Note that the handling of cancellation is racy with regard to 1054 // Note that the handling of cancellation is racy with regard to
1041 // alerts/errors. The request might get cancelled shortly after this 1055 // alerts/errors. The request might get cancelled shortly after this
1042 // check! (There is no lock being held to guarantee otherwise). 1056 // check! (There is no lock being held to guarantee otherwise).
1043 // 1057 //
1044 // If this happens, then some information will get written to the NetLog 1058 // If this happens, then some information will get written to the NetLog
1045 // needlessly, however the NetLog will still be alive so it shouldn't cause 1059 // needlessly, however the NetLog will still be alive so it shouldn't cause
1046 // problems. 1060 // problems.
1047 if (cancelled_.IsSet()) 1061 if (cancelled_.IsSet())
(...skipping 11 matching lines...) Expand all
1059 NetLog::TYPE_PAC_JAVASCRIPT_ALERT, 1073 NetLog::TYPE_PAC_JAVASCRIPT_ALERT,
1060 NetLog::StringCallback("message", &message)); 1074 NetLog::StringCallback("message", &message));
1061 } else { 1075 } else {
1062 // ------------------- 1076 // -------------------
1063 // error 1077 // error
1064 // ------------------- 1078 // -------------------
1065 IncrementWithoutOverflow(&metrics_num_errors_); 1079 IncrementWithoutOverflow(&metrics_num_errors_);
1066 if (line_number == -1) 1080 if (line_number == -1)
1067 VLOG(1) << "PAC-error: " << message; 1081 VLOG(1) << "PAC-error: " << message;
1068 else 1082 else
1069 VLOG(1) << "PAC-error: " << "line: " << line_number << ": " << message; 1083 VLOG(1) << "PAC-error: "
1084 << "line: " << line_number << ": " << message;
1070 1085
1071 // Send the error to the NetLog. 1086 // Send the error to the NetLog.
1072 LogEventToCurrentRequestAndGlobally( 1087 LogEventToCurrentRequestAndGlobally(
1073 NetLog::TYPE_PAC_JAVASCRIPT_ERROR, 1088 NetLog::TYPE_PAC_JAVASCRIPT_ERROR,
1074 base::Bind(&NetLogErrorCallback, line_number, &message)); 1089 base::Bind(&NetLogErrorCallback, line_number, &message));
1075 1090
1076 if (error_observer()) 1091 if (error_observer())
1077 error_observer()->OnPACScriptError(line_number, message); 1092 error_observer()->OnPACScriptError(line_number, message);
1078 } 1093 }
1079 } 1094 }
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1164 DCHECK(!set_pac_script_job_.get()); 1179 DCHECK(!set_pac_script_job_.get());
1165 CHECK_EQ(0, num_outstanding_callbacks_); 1180 CHECK_EQ(0, num_outstanding_callbacks_);
1166 1181
1167 set_pac_script_job_ = new Job(this); 1182 set_pac_script_job_ = new Job(this);
1168 set_pac_script_job_->StartSetPacScript(script_data, callback); 1183 set_pac_script_job_->StartSetPacScript(script_data, callback);
1169 1184
1170 return ERR_IO_PENDING; 1185 return ERR_IO_PENDING;
1171 } 1186 }
1172 1187
1173 } // namespace net 1188 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698