blob: 70ebe3c49837134afe009e07c94cc81e9d9c09a2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef NET_PROXY_MOJO_PROXY_RESOLVER_V8_TRACING_BINDINGS_H_
#define NET_PROXY_MOJO_PROXY_RESOLVER_V8_TRACING_BINDINGS_H_
#include "base/threading/thread_checker.h"
#include "mojo/common/common_type_converters.h"
#include "net/dns/host_resolver_mojo.h"
#include "net/interfaces/proxy_resolver_service.mojom.h"
#include "net/proxy/proxy_resolver_v8_tracing.h"
namespace net {
// An implementation of ProxyResolverV8Tracing::Bindings that forwards requests
// onto a Client mojo interface. Alert() and OnError() may be called from any
// thread; when they are called from another thread, the calls are proxied to
// the origin task runner. GetHostResolver() and GetBoundNetLog() may only be
// called from the origin task runner.
template <typename Client>
class MojoProxyResolverV8TracingBindings
: public ProxyResolverV8Tracing::Bindings,
public HostResolverMojo::Impl {
public:
explicit MojoProxyResolverV8TracingBindings(Client* client)
: client_(client), host_resolver_(this) {
DCHECK(client_);
}
// ProxyResolverV8Tracing::Bindings overrides.
void Alert(const base::string16& message) override {
DCHECK(thread_checker_.CalledOnValidThread());
client_->Alert(mojo::String::From(message));
}
void OnError(int line_number, const base::string16& message) override {
DCHECK(thread_checker_.CalledOnValidThread());
client_->OnError(line_number, mojo::String::From(message));
}
HostResolver* GetHostResolver() override {
DCHECK(thread_checker_.CalledOnValidThread());
return &host_resolver_;
}
BoundNetLog GetBoundNetLog() override {
DCHECK(thread_checker_.CalledOnValidThread());
return BoundNetLog();
}
private:
// HostResolverMojo::Impl override.
void ResolveDns(interfaces::HostResolverRequestInfoPtr request_info,
interfaces::HostResolverRequestClientPtr client) {
DCHECK(thread_checker_.CalledOnValidThread());
client_->ResolveDns(request_info.Pass(), client.Pass());
}
base::ThreadChecker thread_checker_;
Client* client_;
HostResolverMojo host_resolver_;
};
} // namespace net
#endif // NET_PROXY_MOJO_PROXY_RESOLVER_V8_TRACING_BINDINGS_H_
|