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

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

Issue 2416483002: Use std::string instead of mojo::String in //net. (Closed)
Patch Set: Created 4 years, 2 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
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/proxy_resolver_factory_mojo.h" 5 #include "net/proxy/proxy_resolver_factory_mojo.h"
6 6
7 #include <set> 7 #include <set>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/stl_util.h" 14 #include "base/stl_util.h"
15 #include "base/strings/utf_string_conversions.h"
15 #include "base/threading/thread_checker.h" 16 #include "base/threading/thread_checker.h"
16 #include "base/values.h" 17 #include "base/values.h"
17 #include "mojo/common/common_type_converters.h"
18 #include "mojo/public/cpp/bindings/binding.h" 18 #include "mojo/public/cpp/bindings/binding.h"
19 #include "net/base/load_states.h" 19 #include "net/base/load_states.h"
20 #include "net/base/net_errors.h" 20 #include "net/base/net_errors.h"
21 #include "net/dns/mojo_host_resolver_impl.h" 21 #include "net/dns/mojo_host_resolver_impl.h"
22 #include "net/interfaces/host_resolver_service.mojom.h" 22 #include "net/interfaces/host_resolver_service.mojom.h"
23 #include "net/interfaces/proxy_resolver_service.mojom.h" 23 #include "net/interfaces/proxy_resolver_service.mojom.h"
24 #include "net/log/net_log.h" 24 #include "net/log/net_log.h"
25 #include "net/log/net_log_capture_mode.h" 25 #include "net/log/net_log_capture_mode.h"
26 #include "net/log/net_log_event_type.h" 26 #include "net/log/net_log_event_type.h"
27 #include "net/log/net_log_with_source.h" 27 #include "net/log/net_log_with_source.h"
28 #include "net/proxy/mojo_proxy_resolver_factory.h" 28 #include "net/proxy/mojo_proxy_resolver_factory.h"
29 #include "net/proxy/proxy_info.h" 29 #include "net/proxy/proxy_info.h"
30 #include "net/proxy/proxy_resolver.h" 30 #include "net/proxy/proxy_resolver.h"
31 #include "net/proxy/proxy_resolver_error_observer.h" 31 #include "net/proxy/proxy_resolver_error_observer.h"
32 #include "net/proxy/proxy_resolver_script_data.h" 32 #include "net/proxy/proxy_resolver_script_data.h"
33 33
34 namespace net { 34 namespace net {
35 35
36 namespace { 36 namespace {
37 37
38 std::unique_ptr<base::Value> NetLogErrorCallback( 38 std::unique_ptr<base::Value> NetLogErrorCallback(
39 int line_number, 39 int line_number,
40 const base::string16* message, 40 const std::string* message,
41 NetLogCaptureMode /* capture_mode */) { 41 NetLogCaptureMode /* capture_mode */) {
42 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); 42 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
43 dict->SetInteger("line_number", line_number); 43 dict->SetInteger("line_number", line_number);
44 dict->SetString("message", *message); 44 dict->SetString("message", *message);
45 return std::move(dict); 45 return std::move(dict);
46 } 46 }
47 47
48 // A mixin that forwards logging to (Bound)NetLog and ProxyResolverErrorObserver 48 // A mixin that forwards logging to (Bound)NetLog and ProxyResolverErrorObserver
49 // and DNS requests to a MojoHostResolverImpl, which is implemented in terms of 49 // and DNS requests to a MojoHostResolverImpl, which is implemented in terms of
50 // a HostResolver. 50 // a HostResolver.
51 template <typename ClientInterface> 51 template <typename ClientInterface>
52 class ClientMixin : public ClientInterface { 52 class ClientMixin : public ClientInterface {
53 public: 53 public:
54 ClientMixin(HostResolver* host_resolver, 54 ClientMixin(HostResolver* host_resolver,
55 ProxyResolverErrorObserver* error_observer, 55 ProxyResolverErrorObserver* error_observer,
56 NetLog* net_log, 56 NetLog* net_log,
57 const NetLogWithSource& net_log_with_source) 57 const NetLogWithSource& net_log_with_source)
58 : host_resolver_(host_resolver, net_log_with_source), 58 : host_resolver_(host_resolver, net_log_with_source),
59 error_observer_(error_observer), 59 error_observer_(error_observer),
60 net_log_(net_log), 60 net_log_(net_log),
61 net_log_with_source_(net_log_with_source) {} 61 net_log_with_source_(net_log_with_source) {}
62 62
63 // Overridden from ClientInterface: 63 // Overridden from ClientInterface:
64 void Alert(const mojo::String& message) override { 64 void Alert(const std::string& message) override {
65 base::string16 message_str = message.To<base::string16>(); 65 auto callback = NetLog::StringCallback("message", &message);
66 auto callback = NetLog::StringCallback("message", &message_str);
67 net_log_with_source_.AddEvent(NetLogEventType::PAC_JAVASCRIPT_ALERT, 66 net_log_with_source_.AddEvent(NetLogEventType::PAC_JAVASCRIPT_ALERT,
68 callback); 67 callback);
69 if (net_log_) 68 if (net_log_)
70 net_log_->AddGlobalEntry(NetLogEventType::PAC_JAVASCRIPT_ALERT, callback); 69 net_log_->AddGlobalEntry(NetLogEventType::PAC_JAVASCRIPT_ALERT, callback);
71 } 70 }
72 71
73 void OnError(int32_t line_number, const mojo::String& message) override { 72 void OnError(int32_t line_number, const std::string& message) override {
74 base::string16 message_str = message.To<base::string16>(); 73 auto callback = base::Bind(&NetLogErrorCallback, line_number, &message);
75 auto callback = base::Bind(&NetLogErrorCallback, line_number, &message_str);
76 net_log_with_source_.AddEvent(NetLogEventType::PAC_JAVASCRIPT_ERROR, 74 net_log_with_source_.AddEvent(NetLogEventType::PAC_JAVASCRIPT_ERROR,
77 callback); 75 callback);
78 if (net_log_) 76 if (net_log_)
79 net_log_->AddGlobalEntry(NetLogEventType::PAC_JAVASCRIPT_ERROR, callback); 77 net_log_->AddGlobalEntry(NetLogEventType::PAC_JAVASCRIPT_ERROR, callback);
80 if (error_observer_) 78 if (error_observer_) {
81 error_observer_->OnPACScriptError(line_number, message_str); 79 error_observer_->OnPACScriptError(line_number,
80 base::UTF8ToUTF16(message));
81 }
82 } 82 }
83 83
84 void ResolveDns(std::unique_ptr<HostResolver::RequestInfo> request_info, 84 void ResolveDns(std::unique_ptr<HostResolver::RequestInfo> request_info,
85 interfaces::HostResolverRequestClientPtr client) override { 85 interfaces::HostResolverRequestClientPtr client) override {
86 host_resolver_.Resolve(std::move(request_info), std::move(client)); 86 host_resolver_.Resolve(std::move(request_info), std::move(client));
87 } 87 }
88 88
89 protected: 89 protected:
90 bool dns_request_in_progress() { 90 bool dns_request_in_progress() {
91 return host_resolver_.request_in_progress(); 91 return host_resolver_.request_in_progress();
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 factory->host_resolver_, 335 factory->host_resolver_,
336 error_observer.get(), 336 error_observer.get(),
337 factory->net_log_, 337 factory->net_log_,
338 NetLogWithSource()), 338 NetLogWithSource()),
339 factory_(factory), 339 factory_(factory),
340 resolver_(resolver), 340 resolver_(resolver),
341 callback_(callback), 341 callback_(callback),
342 binding_(this), 342 binding_(this),
343 error_observer_(std::move(error_observer)) { 343 error_observer_(std::move(error_observer)) {
344 on_delete_callback_runner_ = factory_->mojo_proxy_factory_->CreateResolver( 344 on_delete_callback_runner_ = factory_->mojo_proxy_factory_->CreateResolver(
345 mojo::String::From(pac_script->utf16()), mojo::GetProxy(&resolver_ptr_), 345 base::UTF16ToUTF8(pac_script->utf16()), mojo::GetProxy(&resolver_ptr_),
346 binding_.CreateInterfacePtrAndBind()); 346 binding_.CreateInterfacePtrAndBind());
347 resolver_ptr_.set_connection_error_handler( 347 resolver_ptr_.set_connection_error_handler(
348 base::Bind(&ProxyResolverFactoryMojo::Job::OnConnectionError, 348 base::Bind(&ProxyResolverFactoryMojo::Job::OnConnectionError,
349 base::Unretained(this))); 349 base::Unretained(this)));
350 binding_.set_connection_error_handler( 350 binding_.set_connection_error_handler(
351 base::Bind(&ProxyResolverFactoryMojo::Job::OnConnectionError, 351 base::Bind(&ProxyResolverFactoryMojo::Job::OnConnectionError,
352 base::Unretained(this))); 352 base::Unretained(this)));
353 } 353 }
354 354
355 void OnConnectionError() { ReportResult(ERR_PAC_SCRIPT_TERMINATED); } 355 void OnConnectionError() { ReportResult(ERR_PAC_SCRIPT_TERMINATED); }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 return ERR_PAC_SCRIPT_FAILED; 403 return ERR_PAC_SCRIPT_FAILED;
404 } 404 }
405 request->reset(new Job(this, pac_script, resolver, callback, 405 request->reset(new Job(this, pac_script, resolver, callback,
406 error_observer_factory_.is_null() 406 error_observer_factory_.is_null()
407 ? nullptr 407 ? nullptr
408 : error_observer_factory_.Run())); 408 : error_observer_factory_.Run()));
409 return ERR_IO_PENDING; 409 return ERR_IO_PENDING;
410 } 410 }
411 411
412 } // namespace net 412 } // namespace net
OLDNEW
« no previous file with comments | « net/proxy/mojo_proxy_resolver_v8_tracing_bindings_unittest.cc ('k') | net/proxy/proxy_resolver_factory_mojo_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698