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

Unified Diff: net/proxy/mojo_proxy_resolver_impl.cc

Issue 939503004: Add LoadState reporting to the mojo proxy resolver. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@proxy-resolver-mojo
Patch Set: Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: net/proxy/mojo_proxy_resolver_impl.cc
diff --git a/net/proxy/mojo_proxy_resolver_impl.cc b/net/proxy/mojo_proxy_resolver_impl.cc
index 870f5d708db9818f5d9acce014f945ac237de8ff..6e3e60b893e0a0a707c27e28c1279bcb7a21f325 100644
--- a/net/proxy/mojo_proxy_resolver_impl.cc
+++ b/net/proxy/mojo_proxy_resolver_impl.cc
@@ -4,8 +4,11 @@
#include "net/proxy/mojo_proxy_resolver_impl.h"
+#include "base/memory/weak_ptr.h"
+#include "base/message_loop/message_loop.h"
#include "base/stl_util.h"
#include "mojo/common/common_type_converters.h"
+#include "net/base/load_state_change_coalescer.h"
#include "net/base/net_errors.h"
#include "net/base/net_log.h"
#include "net/proxy/mojo_type_converters.h"
@@ -14,6 +17,9 @@
#include "net/proxy/proxy_resolver_script_data.h"
namespace net {
+namespace {
+const int kLoadStateChangeCoalesceTimeoutMilliseconds = 10;
+}
class MojoProxyResolverImpl::Job : public mojo::ErrorHandler {
public:
@@ -24,6 +30,11 @@ class MojoProxyResolverImpl::Job : public mojo::ErrorHandler {
void Start();
+ // Invoked when the LoadState for this job changes.
+ void LoadStateChanged(LoadState load_state);
+
+ net::ProxyResolver::RequestHandle request_handle() { return request_handle_; }
+
private:
// mojo::ErrorHandler override.
// This is invoked in response to the client disconnecting, indicating
@@ -32,12 +43,16 @@ class MojoProxyResolverImpl::Job : public mojo::ErrorHandler {
void GetProxyDone(int error);
+ void SendLoadStateChanged(LoadState load_state);
+
MojoProxyResolverImpl* resolver_;
interfaces::ProxyResolverRequestClientPtr client_;
ProxyInfo result_;
GURL url_;
net::ProxyResolver::RequestHandle request_handle_;
+ bool done_;
+ LoadStateChangeCoalescer load_state_change_coalescer_;
DISALLOW_COPY_AND_ASSIGN(Job);
};
@@ -54,6 +69,14 @@ MojoProxyResolverImpl::~MojoProxyResolverImpl() {
STLDeleteElements(&resolve_jobs_);
}
+void MojoProxyResolverImpl::LoadStateChanged(
+ net::ProxyResolver::RequestHandle handle,
+ LoadState load_state) {
+ auto it = request_handle_to_job_.find(handle);
+ DCHECK(it != request_handle_to_job_.end());
+ it->second->LoadStateChanged(load_state);
+}
+
void MojoProxyResolverImpl::SetPacScript(
const mojo::String& data,
const mojo::Callback<void(int32_t)>& callback) {
@@ -75,6 +98,9 @@ void MojoProxyResolverImpl::GetProxyForUrl(
}
void MojoProxyResolverImpl::DeleteJob(Job* job) {
+ if (job->request_handle())
+ request_handle_to_job_.erase(job->request_handle());
+
size_t num_erased = resolve_jobs_.erase(job);
DCHECK(num_erased);
delete job;
@@ -106,11 +132,18 @@ MojoProxyResolverImpl::Job::Job(
: resolver_(resolver),
client_(client.Pass()),
url_(url),
- request_handle_(nullptr) {
+ request_handle_(nullptr),
+ done_(false),
+ load_state_change_coalescer_(
+ base::Bind(&MojoProxyResolverImpl::Job::SendLoadStateChanged,
+ base::Unretained(this)),
+ base::TimeDelta::FromMilliseconds(
+ kLoadStateChangeCoalesceTimeoutMilliseconds),
+ LOAD_STATE_RESOLVING_PROXY_FOR_URL) {
}
MojoProxyResolverImpl::Job::~Job() {
- if (request_handle_)
+ if (request_handle_ && !done_)
resolver_->resolver_->CancelRequest(request_handle_);
}
@@ -123,10 +156,16 @@ void MojoProxyResolverImpl::Job::Start() {
return;
}
client_.set_error_handler(this);
+ resolver_->request_handle_to_job_.insert(
+ std::make_pair(request_handle_, this));
+}
+
+void MojoProxyResolverImpl::Job::LoadStateChanged(LoadState load_state) {
+ load_state_change_coalescer_.LoadStateChanged(load_state);
}
void MojoProxyResolverImpl::Job::GetProxyDone(int error) {
- request_handle_ = nullptr;
+ done_ = true;
DVLOG(1) << "GetProxyForUrl(" << url_ << ") finished with error " << error
<< ". " << result_.proxy_list().size() << " Proxies returned:";
for (const auto& proxy : result_.proxy_list().GetAll()) {
@@ -145,6 +184,10 @@ void MojoProxyResolverImpl::Job::OnConnectionError() {
resolver_->DeleteJob(this);
}
+void MojoProxyResolverImpl::Job::SendLoadStateChanged(LoadState load_state) {
+ client_->LoadStateChanged(load_state);
+}
+
MojoProxyResolverImpl::SetPacScriptRequest::SetPacScriptRequest(
const scoped_refptr<ProxyResolverScriptData>& script_data,
const mojo::Callback<void(int32_t)>& callback)

Powered by Google App Engine
This is Rietveld 408576698