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

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

Issue 1141573002: [net/proxy] Usage of ThreadTaskRunnerHandle & SingleThreadTaskRunner instead of MLP (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/network_delegate_error_observer.h" 5 #include "net/proxy/network_delegate_error_observer.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/message_loop/message_loop_proxy.h" 9 #include "base/single_thread_task_runner.h"
10 #include "net/base/net_errors.h" 10 #include "net/base/net_errors.h"
11 #include "net/base/network_delegate.h" 11 #include "net/base/network_delegate.h"
12 12
13 namespace net { 13 namespace net {
14 14
15 // NetworkDelegateErrorObserver::Core ----------------------------------------- 15 // NetworkDelegateErrorObserver::Core -----------------------------------------
16 16
17 class NetworkDelegateErrorObserver::Core 17 class NetworkDelegateErrorObserver::Core
18 : public base::RefCountedThreadSafe<NetworkDelegateErrorObserver::Core> { 18 : public base::RefCountedThreadSafe<NetworkDelegateErrorObserver::Core> {
19 public: 19 public:
20 Core(NetworkDelegate* network_delegate, base::MessageLoopProxy* origin_loop); 20 Core(NetworkDelegate* network_delegate,
21 base::SingleThreadTaskRunner* origin_runner);
21 22
22 void NotifyPACScriptError(int line_number, const base::string16& error); 23 void NotifyPACScriptError(int line_number, const base::string16& error);
23 24
24 void Shutdown(); 25 void Shutdown();
25 26
26 private: 27 private:
27 friend class base::RefCountedThreadSafe<NetworkDelegateErrorObserver::Core>; 28 friend class base::RefCountedThreadSafe<NetworkDelegateErrorObserver::Core>;
28 29
29 virtual ~Core(); 30 virtual ~Core();
30 31
31 NetworkDelegate* network_delegate_; 32 NetworkDelegate* network_delegate_;
32 scoped_refptr<base::MessageLoopProxy> origin_loop_; 33 scoped_refptr<base::SingleThreadTaskRunner> origin_runner_;
33 34
34 DISALLOW_COPY_AND_ASSIGN(Core); 35 DISALLOW_COPY_AND_ASSIGN(Core);
35 }; 36 };
36 37
37 NetworkDelegateErrorObserver::Core::Core(NetworkDelegate* network_delegate, 38 NetworkDelegateErrorObserver::Core::Core(
38 base::MessageLoopProxy* origin_loop) 39 NetworkDelegate* network_delegate,
39 : network_delegate_(network_delegate), 40 base::SingleThreadTaskRunner* origin_runner)
40 origin_loop_(origin_loop) { 41 : network_delegate_(network_delegate), origin_runner_(origin_runner) {
41 DCHECK(origin_loop); 42 DCHECK(origin_runner);
42 } 43 }
43 44
44 NetworkDelegateErrorObserver::Core::~Core() {} 45 NetworkDelegateErrorObserver::Core::~Core() {}
45 46
46 47
47 void NetworkDelegateErrorObserver::Core::NotifyPACScriptError( 48 void NetworkDelegateErrorObserver::Core::NotifyPACScriptError(
48 int line_number, 49 int line_number,
49 const base::string16& error) { 50 const base::string16& error) {
50 if (!origin_loop_->BelongsToCurrentThread()) { 51 if (!origin_runner_->BelongsToCurrentThread()) {
51 origin_loop_->PostTask( 52 origin_runner_->PostTask(FROM_HERE, base::Bind(&Core::NotifyPACScriptError,
52 FROM_HERE, 53 this, line_number, error));
53 base::Bind(&Core::NotifyPACScriptError, this, line_number, error));
54 return; 54 return;
55 } 55 }
56 if (network_delegate_) 56 if (network_delegate_)
57 network_delegate_->NotifyPACScriptError(line_number, error); 57 network_delegate_->NotifyPACScriptError(line_number, error);
58 } 58 }
59 59
60 void NetworkDelegateErrorObserver::Core::Shutdown() { 60 void NetworkDelegateErrorObserver::Core::Shutdown() {
61 CHECK(origin_loop_->BelongsToCurrentThread()); 61 CHECK(origin_runner_->BelongsToCurrentThread());
62 network_delegate_ = NULL; 62 network_delegate_ = NULL;
63 } 63 }
64 64
65 // NetworkDelegateErrorObserver ----------------------------------------------- 65 // NetworkDelegateErrorObserver -----------------------------------------------
66 66
67 NetworkDelegateErrorObserver::NetworkDelegateErrorObserver( 67 NetworkDelegateErrorObserver::NetworkDelegateErrorObserver(
68 NetworkDelegate* network_delegate, 68 NetworkDelegate* network_delegate,
69 base::MessageLoopProxy* origin_loop) 69 base::SingleThreadTaskRunner* origin_runner)
70 : core_(new Core(network_delegate, origin_loop)) {} 70 : core_(new Core(network_delegate, origin_runner)) {
71 }
71 72
72 NetworkDelegateErrorObserver::~NetworkDelegateErrorObserver() { 73 NetworkDelegateErrorObserver::~NetworkDelegateErrorObserver() {
73 core_->Shutdown(); 74 core_->Shutdown();
74 } 75 }
75 76
76 void NetworkDelegateErrorObserver::OnPACScriptError( 77 void NetworkDelegateErrorObserver::OnPACScriptError(
77 int line_number, 78 int line_number,
78 const base::string16& error) { 79 const base::string16& error) {
79 core_->NotifyPACScriptError(line_number, error); 80 core_->NotifyPACScriptError(line_number, error);
80 } 81 }
81 82
82 } // namespace net 83 } // namespace net
OLDNEW
« no previous file with comments | « net/proxy/network_delegate_error_observer.h ('k') | net/proxy/network_delegate_error_observer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698