• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include "net/url_request/url_request_context_getter.h"
6 
7 #include "base/location.h"
8 #include "base/single_thread_task_runner.h"
9 #include "net/url_request/url_request_context.h"
10 
11 namespace net {
12 
URLRequestContextGetter()13 URLRequestContextGetter::URLRequestContextGetter() {}
14 
~URLRequestContextGetter()15 URLRequestContextGetter::~URLRequestContextGetter() {}
16 
OnDestruct() const17 void URLRequestContextGetter::OnDestruct() const {
18   scoped_refptr<base::SingleThreadTaskRunner> network_task_runner =
19       GetNetworkTaskRunner();
20   DCHECK(network_task_runner.get());
21   if (network_task_runner.get()) {
22     if (network_task_runner->BelongsToCurrentThread()) {
23       delete this;
24     } else {
25       if (!network_task_runner->DeleteSoon(FROM_HERE, this)) {
26         // Can't force-delete the object here, because some derived classes
27         // can only be deleted on the owning thread, so just emit a warning to
28         // aid in debugging.
29         DLOG(WARNING) << "URLRequestContextGetter leaking due to no owning"
30                       << " thread.";
31       }
32     }
33   }
34   // If no IO message loop proxy was available, we will just leak memory.
35   // This is also true if the IO thread is gone.
36 }
37 
TrivialURLRequestContextGetter(net::URLRequestContext * context,const scoped_refptr<base::SingleThreadTaskRunner> & main_task_runner)38 TrivialURLRequestContextGetter::TrivialURLRequestContextGetter(
39     net::URLRequestContext* context,
40     const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner)
41     : context_(context), main_task_runner_(main_task_runner) {}
42 
~TrivialURLRequestContextGetter()43 TrivialURLRequestContextGetter::~TrivialURLRequestContextGetter() {}
44 
45 net::URLRequestContext*
GetURLRequestContext()46 TrivialURLRequestContextGetter::GetURLRequestContext() {
47   return context_;
48 }
49 
50 scoped_refptr<base::SingleThreadTaskRunner>
GetNetworkTaskRunner() const51 TrivialURLRequestContextGetter::GetNetworkTaskRunner() const {
52   return main_task_runner_;
53 }
54 
55 
56 }  // namespace net
57