Use native radiobutton for Default Search Engine picker dialog.
[chromium-blink-merge.git] / net / url_request / url_request_context_getter.cc
blob34d77809be53864ae8c7854994810b83f687d700
1 // Copyright (c) 2012 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/url_request/url_request_context_getter.h"
7 #include "base/location.h"
8 #include "base/single_thread_task_runner.h"
9 #include "net/url_request/url_request_context.h"
10 #include "net/url_request/url_request_context_getter_observer.h"
12 namespace net {
14 void URLRequestContextGetter::AddObserver(
15 URLRequestContextGetterObserver* observer) {
16 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread());
17 observer_list_.AddObserver(observer);
20 void URLRequestContextGetter::RemoveObserver(
21 URLRequestContextGetterObserver* observer) {
22 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread());
23 observer_list_.RemoveObserver(observer);
26 URLRequestContextGetter::URLRequestContextGetter() {}
28 URLRequestContextGetter::~URLRequestContextGetter() {}
30 void URLRequestContextGetter::OnDestruct() const {
31 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner =
32 GetNetworkTaskRunner();
33 DCHECK(network_task_runner.get());
34 if (network_task_runner.get()) {
35 if (network_task_runner->BelongsToCurrentThread()) {
36 delete this;
37 } else {
38 if (!network_task_runner->DeleteSoon(FROM_HERE, this)) {
39 // Can't force-delete the object here, because some derived classes
40 // can only be deleted on the owning thread, so just emit a warning to
41 // aid in debugging.
42 DLOG(WARNING) << "URLRequestContextGetter leaking due to no owning"
43 << " thread.";
47 // If no IO message loop proxy was available, we will just leak memory.
48 // This is also true if the IO thread is gone.
51 void URLRequestContextGetter::NotifyContextShuttingDown() {
52 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread());
54 // Once shutdown starts, this must always return NULL.
55 DCHECK(!GetURLRequestContext());
57 FOR_EACH_OBSERVER(URLRequestContextGetterObserver, observer_list_,
58 OnContextShuttingDown());
61 TrivialURLRequestContextGetter::TrivialURLRequestContextGetter(
62 URLRequestContext* context,
63 const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner)
64 : context_(context), main_task_runner_(main_task_runner) {
67 TrivialURLRequestContextGetter::~TrivialURLRequestContextGetter() {}
69 URLRequestContext* TrivialURLRequestContextGetter::GetURLRequestContext() {
70 return context_;
73 scoped_refptr<base::SingleThreadTaskRunner>
74 TrivialURLRequestContextGetter::GetNetworkTaskRunner() const {
75 return main_task_runner_;
79 } // namespace net