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
3 // found in the LICENSE file.
5 #include "net/proxy/network_delegate_error_observer.h"
8 #include "base/location.h"
9 #include "base/message_loop/message_loop_proxy.h"
10 #include "net/base/net_errors.h"
11 #include "net/base/network_delegate.h"
15 // NetworkDelegateErrorObserver::Core -----------------------------------------
17 class NetworkDelegateErrorObserver::Core
18 : public base::RefCountedThreadSafe
<NetworkDelegateErrorObserver::Core
> {
20 Core(NetworkDelegate
* network_delegate
, base::MessageLoopProxy
* origin_loop
);
22 void NotifyPACScriptError(int line_number
, const base::string16
& error
);
27 friend class base::RefCountedThreadSafe
<NetworkDelegateErrorObserver::Core
>;
31 NetworkDelegate
* network_delegate_
;
32 scoped_refptr
<base::MessageLoopProxy
> origin_loop_
;
34 DISALLOW_COPY_AND_ASSIGN(Core
);
37 NetworkDelegateErrorObserver::Core::Core(NetworkDelegate
* network_delegate
,
38 base::MessageLoopProxy
* origin_loop
)
39 : network_delegate_(network_delegate
),
40 origin_loop_(origin_loop
) {
44 NetworkDelegateErrorObserver::Core::~Core() {}
47 void NetworkDelegateErrorObserver::Core::NotifyPACScriptError(
49 const base::string16
& error
) {
50 if (!origin_loop_
->BelongsToCurrentThread()) {
51 origin_loop_
->PostTask(
53 base::Bind(&Core::NotifyPACScriptError
, this, line_number
, error
));
56 if (network_delegate_
)
57 network_delegate_
->NotifyPACScriptError(line_number
, error
);
60 void NetworkDelegateErrorObserver::Core::Shutdown() {
61 CHECK(origin_loop_
->BelongsToCurrentThread());
62 network_delegate_
= NULL
;
65 // NetworkDelegateErrorObserver -----------------------------------------------
67 NetworkDelegateErrorObserver::NetworkDelegateErrorObserver(
68 NetworkDelegate
* network_delegate
,
69 base::MessageLoopProxy
* origin_loop
)
70 : core_(new Core(network_delegate
, origin_loop
)) {}
72 NetworkDelegateErrorObserver::~NetworkDelegateErrorObserver() {
76 void NetworkDelegateErrorObserver::OnPACScriptError(
78 const base::string16
& error
) {
79 core_
->NotifyPACScriptError(line_number
, error
);