OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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.h" | 5 #include "chrome/browser/net/chrome_url_request_context.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/chrome_thread.h" | 10 #include "chrome/browser/chrome_thread.h" |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 profile->GetOriginalProfile()->GetRequestContext()->proxy_service(); | 190 profile->GetOriginalProfile()->GetRequestContext()->proxy_service(); |
191 | 191 |
192 context->http_transaction_factory_ = | 192 context->http_transaction_factory_ = |
193 new net::HttpCache(context->proxy_service_, 0); | 193 new net::HttpCache(context->proxy_service_, 0); |
194 context->cookie_store_ = new net::CookieMonster; | 194 context->cookie_store_ = new net::CookieMonster; |
195 | 195 |
196 return context; | 196 return context; |
197 } | 197 } |
198 | 198 |
199 // static | 199 // static |
200 ChromeURLRequestContext* ChromeURLRequestContext::CreateOffTheRecordForMedia( | |
201 Profile* profile, const FilePath& disk_cache_path) { | |
202 // TODO(hclam): since we don't have an implementation of disk cache backend | |
203 // for media files in OTR mode, we create a request context just like the | |
204 // original one. | |
205 DCHECK(profile->IsOffTheRecord()); | |
206 return CreateRequestContextForMedia(profile, disk_cache_path, true); | |
207 } | |
208 | |
209 // static | |
210 ChromeURLRequestContext* | 200 ChromeURLRequestContext* |
211 ChromeURLRequestContext::CreateOffTheRecordForExtensions(Profile* profile) { | 201 ChromeURLRequestContext::CreateOffTheRecordForExtensions(Profile* profile) { |
212 DCHECK(profile->IsOffTheRecord()); | 202 DCHECK(profile->IsOffTheRecord()); |
213 ChromeURLRequestContext* context = new ChromeURLRequestContext(profile); | 203 ChromeURLRequestContext* context = new ChromeURLRequestContext(profile); |
214 context->cookie_store_ = new net::CookieMonster; | 204 context->cookie_store_ = new net::CookieMonster; |
215 | 205 |
216 // Enable cookies for extension URLs only. | 206 // Enable cookies for extension URLs only. |
217 const char* schemes[] = {chrome::kExtensionScheme}; | 207 const char* schemes[] = {chrome::kExtensionScheme}; |
218 context->cookie_store_->SetCookieableSchemes(schemes, 1); | 208 context->cookie_store_->SetCookieableSchemes(schemes, 1); |
219 | 209 |
220 return context; | 210 return context; |
221 } | 211 } |
222 | 212 |
223 // static | 213 // static |
224 ChromeURLRequestContext* ChromeURLRequestContext::CreateRequestContextForMedia( | 214 ChromeURLRequestContext* ChromeURLRequestContext::CreateRequestContextForMedia( |
225 Profile* profile, const FilePath& disk_cache_path, bool off_the_record) { | 215 Profile* profile, const FilePath& disk_cache_path, bool off_the_record) { |
226 URLRequestContext* original_context = | 216 URLRequestContext* original_context = |
227 profile->GetOriginalProfile()->GetRequestContext(); | 217 profile->GetOriginalProfile()->GetRequestContext(); |
228 ChromeURLRequestContext* context = new ChromeURLRequestContext(profile); | 218 ChromeURLRequestContext* context = new ChromeURLRequestContext(profile); |
229 context->is_media_ = true; | 219 context->is_media_ = true; |
230 | 220 |
231 // Share the same proxy service of the common profile. | 221 // Share the same proxy service of the common profile. |
232 context->proxy_service_ = original_context->proxy_service(); | 222 context->proxy_service_ = original_context->proxy_service(); |
233 // Also share the cookie store of the common profile. | 223 // Also share the cookie store of the common profile. |
234 context->cookie_store_ = original_context->cookie_store(); | 224 context->cookie_store_ = original_context->cookie_store(); |
235 | 225 |
236 // Create a media cache with maximum size of ~1.8GB, which is a | 226 // Create a media cache with default size. |
237 // size cache backend won't complain. | |
238 // TODO(hclam): make the maximum size of media cache configurable. | 227 // TODO(hclam): make the maximum size of media cache configurable. |
239 net::HttpCache* original_cache = | 228 net::HttpCache* original_cache = |
240 original_context->http_transaction_factory()->GetCache(); | 229 original_context->http_transaction_factory()->GetCache(); |
241 net::HttpCache* cache; | 230 net::HttpCache* cache; |
242 if (original_cache) { | 231 if (original_cache) { |
243 // Try to reuse HttpNetworkSession in the original context, assuming that | 232 // Try to reuse HttpNetworkSession in the original context, assuming that |
244 // HttpTransactionFactory (network_layer()) of HttpCache is implemented | 233 // HttpTransactionFactory (network_layer()) of HttpCache is implemented |
245 // by HttpNetworkLayer so we can reuse HttpNetworkSession within it. This | 234 // by HttpNetworkLayer so we can reuse HttpNetworkSession within it. This |
246 // assumption will be invalid if the original HttpCache is constructed with | 235 // assumption will be invalid if the original HttpCache is constructed with |
247 // HttpCache(HttpTransactionFactory*, disk_cache::Backend*) constructor. | 236 // HttpCache(HttpTransactionFactory*, disk_cache::Backend*) constructor. |
248 net::HttpNetworkLayer* original_network_layer = | 237 net::HttpNetworkLayer* original_network_layer = |
249 static_cast<net::HttpNetworkLayer*>(original_cache->network_layer()); | 238 static_cast<net::HttpNetworkLayer*>(original_cache->network_layer()); |
250 cache = new net::HttpCache(original_network_layer->GetSession(), | 239 cache = new net::HttpCache(original_network_layer->GetSession(), |
251 disk_cache_path.ToWStringHack(), kint32max - kint32max / 10 - 1); | 240 disk_cache_path.ToWStringHack(), 0); |
252 } else { | 241 } else { |
253 // If original HttpCache doesn't exist, simply construct one with a whole | 242 // If original HttpCache doesn't exist, simply construct one with a whole |
254 // new set of network stack. | 243 // new set of network stack. |
255 cache = new net::HttpCache(original_context->proxy_service(), | 244 cache = new net::HttpCache(original_context->proxy_service(), |
256 disk_cache_path.ToWStringHack(), kint32max - kint32max / 10 - 1); | 245 disk_cache_path.ToWStringHack(), 0); |
257 } | 246 } |
258 | 247 |
259 // Set the cache type to media. | 248 cache->set_type(net::MEDIA_CACHE); |
260 if (off_the_record) { | |
261 cache->set_type(net::TEMP_MEDIA_CACHE); | |
262 } else { | |
263 cache->set_type(net::MEDIA_CACHE); | |
264 } | |
265 | |
266 context->http_transaction_factory_ = cache; | 249 context->http_transaction_factory_ = cache; |
267 return context; | 250 return context; |
268 } | 251 } |
269 | 252 |
270 ChromeURLRequestContext::ChromeURLRequestContext(Profile* profile) | 253 ChromeURLRequestContext::ChromeURLRequestContext(Profile* profile) |
271 : prefs_(profile->GetPrefs()), | 254 : prefs_(profile->GetPrefs()), |
272 is_media_(false), | 255 is_media_(false), |
273 is_off_the_record_(profile->IsOffTheRecord()) { | 256 is_off_the_record_(profile->IsOffTheRecord()) { |
274 // Set up Accept-Language and Accept-Charset header values | 257 // Set up Accept-Language and Accept-Charset header values |
275 accept_language_ = net::HttpUtil::GenerateAcceptLanguageHeader( | 258 accept_language_ = net::HttpUtil::GenerateAcceptLanguageHeader( |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 // Do not delete the cookie store in the case of the media context, as it is | 409 // Do not delete the cookie store in the case of the media context, as it is |
427 // owned by the original context. | 410 // owned by the original context. |
428 if (!is_media_) | 411 if (!is_media_) |
429 delete cookie_store_; | 412 delete cookie_store_; |
430 | 413 |
431 // Do not delete the proxy service in the case of OTR or media contexts, as | 414 // Do not delete the proxy service in the case of OTR or media contexts, as |
432 // it is owned by the original URLRequestContext. | 415 // it is owned by the original URLRequestContext. |
433 if (!is_off_the_record_ && !is_media_) | 416 if (!is_off_the_record_ && !is_media_) |
434 delete proxy_service_; | 417 delete proxy_service_; |
435 } | 418 } |
OLD | NEW |