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

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

Issue 1017453005: Add support for ProxyResolverErrorObserver to ProxyResolverMojo. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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
(Empty)
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.
4
5 #include "net/proxy/proxy_resolver_error_observer_mojo.h"
6
7 #include "base/bind.h"
8 #include "base/location.h"
9 #include "base/message_loop/message_loop_proxy.h"
10 #include "base/single_thread_task_runner.h"
11 #include "base/threading/thread_checker.h"
12 #include "mojo/common/common_type_converters.h"
13
14 namespace net {
15
16 class ProxyResolverErrorObserverMojo::Core
Anand Mistry (off Chromium) 2015/03/20 03:12:32 I think you can simplify this code and eliminate t
Sam McNally 2015/03/20 03:52:41 Done.
17 : public base::RefCountedThreadSafe<ProxyResolverErrorObserverMojo::Core> {
18 public:
19 explicit Core(interfaces::ProxyResolverErrorObserverPtr error_observer);
20 void SendOnPacScriptError(int line_number, const base::string16& error);
21
22 private:
23 friend class base::RefCountedThreadSafe<Core>;
24
25 ~Core();
26
27 interfaces::ProxyResolverErrorObserverPtr error_observer_;
28 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
29 base::ThreadChecker thread_checker_;
30 };
31
32 // static
33 scoped_ptr<ProxyResolverErrorObserver> ProxyResolverErrorObserverMojo::Create(
34 interfaces::ProxyResolverErrorObserverPtr error_observer) {
35 if (!error_observer)
36 return nullptr;
37
38 return scoped_ptr<ProxyResolverErrorObserver>(
39 new ProxyResolverErrorObserverMojo(error_observer.Pass()));
40 }
41
42 void ProxyResolverErrorObserverMojo::OnPACScriptError(
43 int line_number,
44 const base::string16& error) {
45 core_->SendOnPacScriptError(line_number, error);
46 }
47
48 ProxyResolverErrorObserverMojo::ProxyResolverErrorObserverMojo(
49 interfaces::ProxyResolverErrorObserverPtr error_observer)
50 : core_(new Core(error_observer.Pass())) {
51 }
52
53 ProxyResolverErrorObserverMojo::~ProxyResolverErrorObserverMojo() = default;
54
55 ProxyResolverErrorObserverMojo::Core::Core(
56 interfaces::ProxyResolverErrorObserverPtr error_observer)
57 : error_observer_(error_observer.Pass()),
58 task_runner_(base::MessageLoopProxy::current()) {
59 }
60
61 void ProxyResolverErrorObserverMojo::Core::SendOnPacScriptError(
62 int line_number,
63 const base::string16& error) {
64 if (!task_runner_->RunsTasksOnCurrentThread()) {
65 task_runner_->PostTask(
66 FROM_HERE,
67 base::Bind(&ProxyResolverErrorObserverMojo::Core::SendOnPacScriptError,
68 this, line_number, error));
69 return;
70 }
71 DCHECK(thread_checker_.CalledOnValidThread());
72 error_observer_->OnPacScriptError(line_number, mojo::String::From(error));
73 }
74
75 ProxyResolverErrorObserverMojo::Core::~Core() = default;
76
77 } // namespace net
OLDNEW
« no previous file with comments | « net/proxy/proxy_resolver_error_observer_mojo.h ('k') | net/proxy/proxy_resolver_error_observer_mojo_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698