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

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

Issue 1145153004: Split ProxyResolverV8Tracing into an implementation and a wrapper. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 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
« no previous file with comments | « net/proxy/mojo_proxy_resolver_impl.h ('k') | net/proxy/mojo_proxy_resolver_impl_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/mojo_proxy_resolver_impl.h" 5 #include "net/proxy/mojo_proxy_resolver_impl.h"
6 6
7 #include "base/stl_util.h" 7 #include "base/stl_util.h"
8 #include "mojo/common/url_type_converters.h" 8 #include "mojo/common/url_type_converters.h"
9 #include "net/base/net_errors.h" 9 #include "net/base/net_errors.h"
10 #include "net/log/net_log.h" 10 #include "net/log/net_log.h"
11 #include "net/proxy/load_state_change_coalescer.h"
12 #include "net/proxy/mojo_proxy_type_converters.h" 11 #include "net/proxy/mojo_proxy_type_converters.h"
13 #include "net/proxy/proxy_info.h" 12 #include "net/proxy/proxy_info.h"
14 #include "net/proxy/proxy_resolver_script_data.h" 13 #include "net/proxy/proxy_resolver_script_data.h"
15 14
16 namespace net { 15 namespace net {
17 namespace {
18 const int kLoadStateChangeCoalesceTimeoutMilliseconds = 10;
19 }
20 16
21 class MojoProxyResolverImpl::Job : public mojo::ErrorHandler { 17 class MojoProxyResolverImpl::Job : public mojo::ErrorHandler {
22 public: 18 public:
23 Job(interfaces::ProxyResolverRequestClientPtr client, 19 Job(interfaces::ProxyResolverRequestClientPtr client,
24 MojoProxyResolverImpl* resolver, 20 MojoProxyResolverImpl* resolver,
25 const GURL& url); 21 const GURL& url);
26 ~Job() override; 22 ~Job() override;
27 23
28 void Start(); 24 void Start();
29 25
30 // Invoked when the LoadState for this job changes.
31 void LoadStateChanged(LoadState load_state);
32
33 net::ProxyResolver::RequestHandle request_handle() { return request_handle_; } 26 net::ProxyResolver::RequestHandle request_handle() { return request_handle_; }
34 27
35 private: 28 private:
36 // mojo::ErrorHandler override. 29 // mojo::ErrorHandler override.
37 // This is invoked in response to the client disconnecting, indicating 30 // This is invoked in response to the client disconnecting, indicating
38 // cancellation. 31 // cancellation.
39 void OnConnectionError() override; 32 void OnConnectionError() override;
40 33
41 void GetProxyDone(int error); 34 void GetProxyDone(int error);
42 35
43 void SendLoadStateChanged(LoadState load_state);
44
45 MojoProxyResolverImpl* resolver_; 36 MojoProxyResolverImpl* resolver_;
46 37
47 interfaces::ProxyResolverRequestClientPtr client_; 38 interfaces::ProxyResolverRequestClientPtr client_;
48 ProxyInfo result_; 39 ProxyInfo result_;
49 GURL url_; 40 GURL url_;
50 net::ProxyResolver::RequestHandle request_handle_; 41 net::ProxyResolver::RequestHandle request_handle_;
51 bool done_; 42 bool done_;
52 LoadStateChangeCoalescer load_state_change_coalescer_;
53 43
54 DISALLOW_COPY_AND_ASSIGN(Job); 44 DISALLOW_COPY_AND_ASSIGN(Job);
55 }; 45 };
56 46
57 MojoProxyResolverImpl::MojoProxyResolverImpl( 47 MojoProxyResolverImpl::MojoProxyResolverImpl(
58 scoped_ptr<net::ProxyResolver> resolver, 48 scoped_ptr<net::ProxyResolver> resolver)
59 const base::Callback<
60 void(const net::ProxyResolver::LoadStateChangedCallback&)>&
61 load_state_change_callback_setter)
62 : resolver_(resolver.Pass()) { 49 : resolver_(resolver.Pass()) {
63 load_state_change_callback_setter.Run(base::Bind(
64 &MojoProxyResolverImpl::LoadStateChanged, base::Unretained(this)));
65 } 50 }
66 51
67 MojoProxyResolverImpl::~MojoProxyResolverImpl() { 52 MojoProxyResolverImpl::~MojoProxyResolverImpl() {
68 STLDeleteElements(&resolve_jobs_); 53 STLDeleteElements(&resolve_jobs_);
69 } 54 }
70 55
71 void MojoProxyResolverImpl::LoadStateChanged(
72 net::ProxyResolver::RequestHandle handle,
73 LoadState load_state) {
74 auto it = request_handle_to_job_.find(handle);
75 DCHECK(it != request_handle_to_job_.end());
76 it->second->LoadStateChanged(load_state);
77 }
78
79 void MojoProxyResolverImpl::GetProxyForUrl( 56 void MojoProxyResolverImpl::GetProxyForUrl(
80 const mojo::String& url, 57 const mojo::String& url,
81 interfaces::ProxyResolverRequestClientPtr client) { 58 interfaces::ProxyResolverRequestClientPtr client) {
82 DVLOG(1) << "GetProxyForUrl(" << url << ")"; 59 DVLOG(1) << "GetProxyForUrl(" << url << ")";
83 Job* job = new Job(client.Pass(), this, url.To<GURL>()); 60 Job* job = new Job(client.Pass(), this, url.To<GURL>());
84 bool inserted = resolve_jobs_.insert(job).second; 61 bool inserted = resolve_jobs_.insert(job).second;
85 DCHECK(inserted); 62 DCHECK(inserted);
86 job->Start(); 63 job->Start();
87 } 64 }
88 65
89 void MojoProxyResolverImpl::DeleteJob(Job* job) { 66 void MojoProxyResolverImpl::DeleteJob(Job* job) {
90 if (job->request_handle()) 67 if (job->request_handle())
91 request_handle_to_job_.erase(job->request_handle()); 68 request_handle_to_job_.erase(job->request_handle());
92 69
93 size_t num_erased = resolve_jobs_.erase(job); 70 size_t num_erased = resolve_jobs_.erase(job);
94 DCHECK(num_erased); 71 DCHECK(num_erased);
95 delete job; 72 delete job;
96 } 73 }
97 74
98 MojoProxyResolverImpl::Job::Job( 75 MojoProxyResolverImpl::Job::Job(
99 interfaces::ProxyResolverRequestClientPtr client, 76 interfaces::ProxyResolverRequestClientPtr client,
100 MojoProxyResolverImpl* resolver, 77 MojoProxyResolverImpl* resolver,
101 const GURL& url) 78 const GURL& url)
102 : resolver_(resolver), 79 : resolver_(resolver),
103 client_(client.Pass()), 80 client_(client.Pass()),
104 url_(url), 81 url_(url),
105 request_handle_(nullptr), 82 request_handle_(nullptr),
106 done_(false), 83 done_(false) {
107 load_state_change_coalescer_(
108 base::Bind(&MojoProxyResolverImpl::Job::SendLoadStateChanged,
109 base::Unretained(this)),
110 base::TimeDelta::FromMilliseconds(
111 kLoadStateChangeCoalesceTimeoutMilliseconds),
112 LOAD_STATE_RESOLVING_PROXY_FOR_URL) {
113 } 84 }
114 85
115 MojoProxyResolverImpl::Job::~Job() { 86 MojoProxyResolverImpl::Job::~Job() {
116 if (request_handle_ && !done_) 87 if (request_handle_ && !done_)
117 resolver_->resolver_->CancelRequest(request_handle_); 88 resolver_->resolver_->CancelRequest(request_handle_);
118 } 89 }
119 90
120 void MojoProxyResolverImpl::Job::Start() { 91 void MojoProxyResolverImpl::Job::Start() {
121 int result = resolver_->resolver_->GetProxyForURL( 92 int result = resolver_->resolver_->GetProxyForURL(
122 url_, &result_, base::Bind(&Job::GetProxyDone, base::Unretained(this)), 93 url_, &result_, base::Bind(&Job::GetProxyDone, base::Unretained(this)),
123 &request_handle_, BoundNetLog()); 94 &request_handle_, BoundNetLog());
124 if (result != ERR_IO_PENDING) { 95 if (result != ERR_IO_PENDING) {
125 GetProxyDone(result); 96 GetProxyDone(result);
126 return; 97 return;
127 } 98 }
128 client_.set_error_handler(this); 99 client_.set_error_handler(this);
129 resolver_->request_handle_to_job_.insert( 100 resolver_->request_handle_to_job_.insert(
130 std::make_pair(request_handle_, this)); 101 std::make_pair(request_handle_, this));
131 } 102 }
132 103
133 void MojoProxyResolverImpl::Job::LoadStateChanged(LoadState load_state) {
134 load_state_change_coalescer_.LoadStateChanged(load_state);
135 }
136
137 void MojoProxyResolverImpl::Job::GetProxyDone(int error) { 104 void MojoProxyResolverImpl::Job::GetProxyDone(int error) {
138 done_ = true; 105 done_ = true;
139 DVLOG(1) << "GetProxyForUrl(" << url_ << ") finished with error " << error 106 DVLOG(1) << "GetProxyForUrl(" << url_ << ") finished with error " << error
140 << ". " << result_.proxy_list().size() << " Proxies returned:"; 107 << ". " << result_.proxy_list().size() << " Proxies returned:";
141 for (const auto& proxy : result_.proxy_list().GetAll()) { 108 for (const auto& proxy : result_.proxy_list().GetAll()) {
142 DVLOG(1) << proxy.ToURI(); 109 DVLOG(1) << proxy.ToURI();
143 } 110 }
144 mojo::Array<interfaces::ProxyServerPtr> result; 111 mojo::Array<interfaces::ProxyServerPtr> result;
145 if (error == OK) { 112 if (error == OK) {
146 result = mojo::Array<interfaces::ProxyServerPtr>::From( 113 result = mojo::Array<interfaces::ProxyServerPtr>::From(
147 result_.proxy_list().GetAll()); 114 result_.proxy_list().GetAll());
148 } 115 }
149 client_->ReportResult(error, result.Pass()); 116 client_->ReportResult(error, result.Pass());
150 resolver_->DeleteJob(this); 117 resolver_->DeleteJob(this);
151 } 118 }
152 119
153 void MojoProxyResolverImpl::Job::OnConnectionError() { 120 void MojoProxyResolverImpl::Job::OnConnectionError() {
154 resolver_->DeleteJob(this); 121 resolver_->DeleteJob(this);
155 } 122 }
156 123
157 void MojoProxyResolverImpl::Job::SendLoadStateChanged(LoadState load_state) {
158 client_->LoadStateChanged(load_state);
159 }
160
161 } // namespace net 124 } // namespace net
OLDNEW
« no previous file with comments | « net/proxy/mojo_proxy_resolver_impl.h ('k') | net/proxy/mojo_proxy_resolver_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698