Include all dupe types (event when value is zero) in scan stats.
[chromium-blink-merge.git] / net / proxy / network_delegate_error_observer.cc
blob1bb0537d6cdaa6dad357692a319e54fe2a75426d
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/single_thread_task_runner.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,
21 base::SingleThreadTaskRunner* origin_runner);
23 void NotifyPACScriptError(int line_number, const base::string16& error);
25 void Shutdown();
27 private:
28 friend class base::RefCountedThreadSafe<NetworkDelegateErrorObserver::Core>;
30 virtual ~Core();
32 NetworkDelegate* network_delegate_;
33 scoped_refptr<base::SingleThreadTaskRunner> origin_runner_;
35 DISALLOW_COPY_AND_ASSIGN(Core);
38 NetworkDelegateErrorObserver::Core::Core(
39 NetworkDelegate* network_delegate,
40 base::SingleThreadTaskRunner* origin_runner)
41 : network_delegate_(network_delegate), origin_runner_(origin_runner) {
42 DCHECK(origin_runner);
45 NetworkDelegateErrorObserver::Core::~Core() {}
48 void NetworkDelegateErrorObserver::Core::NotifyPACScriptError(
49 int line_number,
50 const base::string16& error) {
51 if (!origin_runner_->BelongsToCurrentThread()) {
52 origin_runner_->PostTask(FROM_HERE, base::Bind(&Core::NotifyPACScriptError,
53 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_runner_->BelongsToCurrentThread());
62 network_delegate_ = NULL;
65 // NetworkDelegateErrorObserver -----------------------------------------------
67 NetworkDelegateErrorObserver::NetworkDelegateErrorObserver(
68 NetworkDelegate* network_delegate,
69 base::SingleThreadTaskRunner* origin_runner)
70 : core_(new Core(network_delegate, origin_runner)) {
73 NetworkDelegateErrorObserver::~NetworkDelegateErrorObserver() {
74 core_->Shutdown();
77 // static
78 scoped_ptr<ProxyResolverErrorObserver> NetworkDelegateErrorObserver::Create(
79 NetworkDelegate* network_delegate,
80 const scoped_refptr<base::SingleThreadTaskRunner>& origin_runner) {
81 return make_scoped_ptr(
82 new NetworkDelegateErrorObserver(network_delegate, origin_runner.get()));
85 void NetworkDelegateErrorObserver::OnPACScriptError(
86 int line_number,
87 const base::string16& error) {
88 core_->NotifyPACScriptError(line_number, error);
91 } // namespace net