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