Autofill: Add WalletIntegrationAvailable() to components.
[chromium-blink-merge.git] / net / proxy / network_delegate_error_observer.cc
blob8029141a0a4035024cbdc6750079a52447d81917
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"
7 #include "base/bind.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"
13 namespace net {
15 // NetworkDelegateErrorObserver::Core -----------------------------------------
17 class NetworkDelegateErrorObserver::Core
18 : public base::RefCountedThreadSafe<NetworkDelegateErrorObserver::Core> {
19 public:
20 Core(NetworkDelegate* network_delegate, base::MessageLoopProxy* origin_loop);
22 void NotifyPACScriptError(int line_number, const base::string16& error);
24 void Shutdown();
26 private:
27 friend class base::RefCountedThreadSafe<NetworkDelegateErrorObserver::Core>;
29 virtual ~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) {
41 DCHECK(origin_loop);
44 NetworkDelegateErrorObserver::Core::~Core() {}
47 void NetworkDelegateErrorObserver::Core::NotifyPACScriptError(
48 int line_number,
49 const base::string16& error) {
50 if (!origin_loop_->BelongsToCurrentThread()) {
51 origin_loop_->PostTask(
52 FROM_HERE,
53 base::Bind(&Core::NotifyPACScriptError, this, line_number, error));
54 return;
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() {
73 core_->Shutdown();
76 void NetworkDelegateErrorObserver::OnPACScriptError(
77 int line_number,
78 const base::string16& error) {
79 core_->NotifyPACScriptError(line_number, error);
82 } // namespace net