| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/net/chrome_url_request_context_getter.h" | 5 #include "chrome/browser/net/chrome_url_request_context_getter.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/message_loop/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop_proxy.h" |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 | 163 |
| 164 } // namespace | 164 } // namespace |
| 165 | 165 |
| 166 // ---------------------------------------------------------------------------- | 166 // ---------------------------------------------------------------------------- |
| 167 // ChromeURLRequestContextGetter | 167 // ChromeURLRequestContextGetter |
| 168 // ---------------------------------------------------------------------------- | 168 // ---------------------------------------------------------------------------- |
| 169 | 169 |
| 170 ChromeURLRequestContextGetter::ChromeURLRequestContextGetter( | 170 ChromeURLRequestContextGetter::ChromeURLRequestContextGetter( |
| 171 ChromeURLRequestContextFactory* factory) | 171 ChromeURLRequestContextFactory* factory) |
| 172 : factory_(factory), | 172 : factory_(factory), |
| 173 url_request_context_(NULL) { | 173 url_request_context_(nullptr) { |
| 174 DCHECK(factory); | 174 DCHECK(factory); |
| 175 } | 175 } |
| 176 | 176 |
| 177 ChromeURLRequestContextGetter::~ChromeURLRequestContextGetter() {} | 177 ChromeURLRequestContextGetter::~ChromeURLRequestContextGetter() { |
| 178 // NotifyContextShuttingDown() must have been called. |
| 179 DCHECK(!factory_.get()); |
| 180 DCHECK(!url_request_context_); |
| 181 } |
| 178 | 182 |
| 179 // Lazily create a URLRequestContext using our factory. | 183 // Lazily create a URLRequestContext using our factory. |
| 180 net::URLRequestContext* | 184 net::URLRequestContext* |
| 181 ChromeURLRequestContextGetter::GetURLRequestContext() { | 185 ChromeURLRequestContextGetter::GetURLRequestContext() { |
| 182 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 186 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 183 | 187 |
| 184 if (factory_.get()) { | 188 if (factory_.get()) { |
| 185 DCHECK(!url_request_context_); | 189 DCHECK(!url_request_context_); |
| 186 url_request_context_ = factory_->Create(); | 190 url_request_context_ = factory_->Create(); |
| 187 factory_.reset(); | 191 factory_.reset(); |
| 188 } | 192 } |
| 189 | 193 |
| 190 // Context reference is valid, unless we're trying to use the | |
| 191 // URLRequestContextGetter after the Profile has already been deleted. | |
| 192 CHECK(url_request_context_); | |
| 193 | |
| 194 return url_request_context_; | 194 return url_request_context_; |
| 195 } | 195 } |
| 196 | 196 |
| 197 void ChromeURLRequestContextGetter::Invalidate() { | 197 void ChromeURLRequestContextGetter::NotifyContextShuttingDown() { |
| 198 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 198 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 199 |
| 199 factory_.reset(); | 200 factory_.reset(); |
| 200 url_request_context_ = NULL; | 201 url_request_context_ = nullptr; |
| 202 URLRequestContextGetter::NotifyContextShuttingDown(); |
| 201 } | 203 } |
| 202 | 204 |
| 203 scoped_refptr<base::SingleThreadTaskRunner> | 205 scoped_refptr<base::SingleThreadTaskRunner> |
| 204 ChromeURLRequestContextGetter::GetNetworkTaskRunner() const { | 206 ChromeURLRequestContextGetter::GetNetworkTaskRunner() const { |
| 205 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); | 207 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); |
| 206 } | 208 } |
| 207 | 209 |
| 208 // static | 210 // static |
| 209 ChromeURLRequestContextGetter* ChromeURLRequestContextGetter::Create( | 211 ChromeURLRequestContextGetter* ChromeURLRequestContextGetter::Create( |
| 210 Profile* profile, | 212 Profile* profile, |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 ChromeURLRequestContextGetter* | 258 ChromeURLRequestContextGetter* |
| 257 ChromeURLRequestContextGetter::CreateForIsolatedMedia( | 259 ChromeURLRequestContextGetter::CreateForIsolatedMedia( |
| 258 Profile* profile, | 260 Profile* profile, |
| 259 ChromeURLRequestContextGetter* app_context, | 261 ChromeURLRequestContextGetter* app_context, |
| 260 const ProfileIOData* profile_io_data, | 262 const ProfileIOData* profile_io_data, |
| 261 const StoragePartitionDescriptor& partition_descriptor) { | 263 const StoragePartitionDescriptor& partition_descriptor) { |
| 262 return new ChromeURLRequestContextGetter( | 264 return new ChromeURLRequestContextGetter( |
| 263 new FactoryForIsolatedMedia( | 265 new FactoryForIsolatedMedia( |
| 264 profile_io_data, partition_descriptor, app_context)); | 266 profile_io_data, partition_descriptor, app_context)); |
| 265 } | 267 } |
| OLD | NEW |