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
3 // found in the LICENSE file.
5 #ifndef NET_PROXY_MOJO_PROXY_RESOLVER_V8_TRACING_BINDINGS_H_
6 #define NET_PROXY_MOJO_PROXY_RESOLVER_V8_TRACING_BINDINGS_H_
8 #include "base/threading/thread_checker.h"
9 #include "mojo/common/common_type_converters.h"
10 #include "net/dns/host_resolver_mojo.h"
11 #include "net/interfaces/proxy_resolver_service.mojom.h"
12 #include "net/proxy/proxy_resolver_v8_tracing.h"
16 // An implementation of ProxyResolverV8Tracing::Bindings that forwards requests
17 // onto a Client mojo interface. Alert() and OnError() may be called from any
18 // thread; when they are called from another thread, the calls are proxied to
19 // the origin task runner. GetHostResolver() and GetBoundNetLog() may only be
20 // called from the origin task runner.
21 template <typename Client
>
22 class MojoProxyResolverV8TracingBindings
23 : public ProxyResolverV8Tracing::Bindings
,
24 public HostResolverMojo::Impl
{
26 explicit MojoProxyResolverV8TracingBindings(Client
* client
)
27 : client_(client
), host_resolver_(this) {
31 // ProxyResolverV8Tracing::Bindings overrides.
32 void Alert(const base::string16
& message
) override
{
33 DCHECK(thread_checker_
.CalledOnValidThread());
34 client_
->Alert(mojo::String::From(message
));
37 void OnError(int line_number
, const base::string16
& message
) override
{
38 DCHECK(thread_checker_
.CalledOnValidThread());
39 client_
->OnError(line_number
, mojo::String::From(message
));
42 HostResolver
* GetHostResolver() override
{
43 DCHECK(thread_checker_
.CalledOnValidThread());
44 return &host_resolver_
;
47 BoundNetLog
GetBoundNetLog() override
{
48 DCHECK(thread_checker_
.CalledOnValidThread());
53 // HostResolverMojo::Impl override.
54 void ResolveDns(interfaces::HostResolverRequestInfoPtr request_info
,
55 interfaces::HostResolverRequestClientPtr client
) {
56 DCHECK(thread_checker_
.CalledOnValidThread());
57 client_
->ResolveDns(request_info
.Pass(), client
.Pass());
60 base::ThreadChecker thread_checker_
;
62 HostResolverMojo host_resolver_
;
67 #endif // NET_PROXY_MOJO_PROXY_RESOLVER_V8_TRACING_BINDINGS_H_