| 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/privacy_blacklist/blacklist.h" | 10 #include "chrome/browser/privacy_blacklist/blacklist.h" |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 return net::ProxyService::Create( | 101 return net::ProxyService::Create( |
| 102 proxy_config.get(), | 102 proxy_config.get(), |
| 103 use_v8, | 103 use_v8, |
| 104 context, | 104 context, |
| 105 g_browser_process->io_thread()->message_loop()); | 105 g_browser_process->io_thread()->message_loop()); |
| 106 } | 106 } |
| 107 | 107 |
| 108 // static | 108 // static |
| 109 ChromeURLRequestContext* ChromeURLRequestContext::CreateOriginal( | 109 ChromeURLRequestContext* ChromeURLRequestContext::CreateOriginal( |
| 110 Profile* profile, const FilePath& cookie_store_path, | 110 Profile* profile, const FilePath& cookie_store_path, |
| 111 const FilePath& disk_cache_path) { | 111 const FilePath& disk_cache_path, int cache_size) { |
| 112 DCHECK(!profile->IsOffTheRecord()); | 112 DCHECK(!profile->IsOffTheRecord()); |
| 113 ChromeURLRequestContext* context = new ChromeURLRequestContext(profile); | 113 ChromeURLRequestContext* context = new ChromeURLRequestContext(profile); |
| 114 | 114 |
| 115 // Global host resolver for the context. | 115 // Global host resolver for the context. |
| 116 context->host_resolver_ = chrome_browser_net::GetGlobalHostResolver(); | 116 context->host_resolver_ = chrome_browser_net::GetGlobalHostResolver(); |
| 117 | 117 |
| 118 context->proxy_service_ = CreateProxyService( | 118 context->proxy_service_ = CreateProxyService( |
| 119 context, *CommandLine::ForCurrentProcess()); | 119 context, *CommandLine::ForCurrentProcess()); |
| 120 | 120 |
| 121 net::HttpCache* cache = | 121 net::HttpCache* cache = |
| 122 new net::HttpCache(context->host_resolver_, | 122 new net::HttpCache(context->host_resolver_, |
| 123 context->proxy_service_, | 123 context->proxy_service_, |
| 124 disk_cache_path.ToWStringHack(), 0); | 124 disk_cache_path.ToWStringHack(), cache_size); |
| 125 | 125 |
| 126 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 126 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 127 bool record_mode = chrome::kRecordModeEnabled && | 127 bool record_mode = chrome::kRecordModeEnabled && |
| 128 command_line.HasSwitch(switches::kRecordMode); | 128 command_line.HasSwitch(switches::kRecordMode); |
| 129 bool playback_mode = command_line.HasSwitch(switches::kPlaybackMode); | 129 bool playback_mode = command_line.HasSwitch(switches::kPlaybackMode); |
| 130 | 130 |
| 131 if (record_mode || playback_mode) { | 131 if (record_mode || playback_mode) { |
| 132 // Don't use existing cookies and use an in-memory store. | 132 // Don't use existing cookies and use an in-memory store. |
| 133 context->cookie_store_ = new net::CookieMonster(); | 133 context->cookie_store_ = new net::CookieMonster(); |
| 134 cache->set_mode( | 134 cache->set_mode( |
| (...skipping 19 matching lines...) Expand all Loading... |
| 154 cookie_store_path.ToWStringHack(), | 154 cookie_store_path.ToWStringHack(), |
| 155 g_browser_process->db_thread()->message_loop())); | 155 g_browser_process->db_thread()->message_loop())); |
| 156 context->cookie_store_ = new net::CookieMonster(context->cookie_db_.get()); | 156 context->cookie_store_ = new net::CookieMonster(context->cookie_db_.get()); |
| 157 } | 157 } |
| 158 | 158 |
| 159 return context; | 159 return context; |
| 160 } | 160 } |
| 161 | 161 |
| 162 // static | 162 // static |
| 163 ChromeURLRequestContext* ChromeURLRequestContext::CreateOriginalForMedia( | 163 ChromeURLRequestContext* ChromeURLRequestContext::CreateOriginalForMedia( |
| 164 Profile* profile, const FilePath& disk_cache_path) { | 164 Profile* profile, const FilePath& disk_cache_path, int cache_size) { |
| 165 DCHECK(!profile->IsOffTheRecord()); | 165 DCHECK(!profile->IsOffTheRecord()); |
| 166 return CreateRequestContextForMedia(profile, disk_cache_path, false); | 166 return CreateRequestContextForMedia(profile, disk_cache_path, cache_size, |
| 167 false); |
| 167 } | 168 } |
| 168 | 169 |
| 169 // static | 170 // static |
| 170 ChromeURLRequestContext* ChromeURLRequestContext::CreateOriginalForExtensions( | 171 ChromeURLRequestContext* ChromeURLRequestContext::CreateOriginalForExtensions( |
| 171 Profile* profile, const FilePath& cookie_store_path) { | 172 Profile* profile, const FilePath& cookie_store_path) { |
| 172 DCHECK(!profile->IsOffTheRecord()); | 173 DCHECK(!profile->IsOffTheRecord()); |
| 173 ChromeURLRequestContext* context = new ChromeURLRequestContext(profile); | 174 ChromeURLRequestContext* context = new ChromeURLRequestContext(profile); |
| 174 | 175 |
| 175 // All we care about for extensions is the cookie store. | 176 // All we care about for extensions is the cookie store. |
| 176 DCHECK(!cookie_store_path.empty()); | 177 DCHECK(!cookie_store_path.empty()); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 | 217 |
| 217 // Enable cookies for extension URLs only. | 218 // Enable cookies for extension URLs only. |
| 218 const char* schemes[] = {chrome::kExtensionScheme}; | 219 const char* schemes[] = {chrome::kExtensionScheme}; |
| 219 context->cookie_store_->SetCookieableSchemes(schemes, 1); | 220 context->cookie_store_->SetCookieableSchemes(schemes, 1); |
| 220 | 221 |
| 221 return context; | 222 return context; |
| 222 } | 223 } |
| 223 | 224 |
| 224 // static | 225 // static |
| 225 ChromeURLRequestContext* ChromeURLRequestContext::CreateRequestContextForMedia( | 226 ChromeURLRequestContext* ChromeURLRequestContext::CreateRequestContextForMedia( |
| 226 Profile* profile, const FilePath& disk_cache_path, bool off_the_record) { | 227 Profile* profile, const FilePath& disk_cache_path, int cache_size, |
| 228 bool off_the_record) { |
| 227 URLRequestContext* original_context = | 229 URLRequestContext* original_context = |
| 228 profile->GetOriginalProfile()->GetRequestContext(); | 230 profile->GetOriginalProfile()->GetRequestContext(); |
| 229 ChromeURLRequestContext* context = new ChromeURLRequestContext(profile); | 231 ChromeURLRequestContext* context = new ChromeURLRequestContext(profile); |
| 230 context->is_media_ = true; | 232 context->is_media_ = true; |
| 231 | 233 |
| 232 // Share the same proxy service of the common profile. | 234 // Share the same proxy service of the common profile. |
| 233 context->proxy_service_ = original_context->proxy_service(); | 235 context->proxy_service_ = original_context->proxy_service(); |
| 234 // Also share the cookie store of the common profile. | 236 // Also share the cookie store of the common profile. |
| 235 context->cookie_store_ = original_context->cookie_store(); | 237 context->cookie_store_ = original_context->cookie_store(); |
| 236 | 238 |
| 237 // Create a media cache with default size. | 239 // Create a media cache with default size. |
| 238 // TODO(hclam): make the maximum size of media cache configurable. | 240 // TODO(hclam): make the maximum size of media cache configurable. |
| 239 net::HttpCache* original_cache = | 241 net::HttpCache* original_cache = |
| 240 original_context->http_transaction_factory()->GetCache(); | 242 original_context->http_transaction_factory()->GetCache(); |
| 241 net::HttpCache* cache; | 243 net::HttpCache* cache; |
| 242 if (original_cache) { | 244 if (original_cache) { |
| 243 // Try to reuse HttpNetworkSession in the original context, assuming that | 245 // Try to reuse HttpNetworkSession in the original context, assuming that |
| 244 // HttpTransactionFactory (network_layer()) of HttpCache is implemented | 246 // HttpTransactionFactory (network_layer()) of HttpCache is implemented |
| 245 // by HttpNetworkLayer so we can reuse HttpNetworkSession within it. This | 247 // by HttpNetworkLayer so we can reuse HttpNetworkSession within it. This |
| 246 // assumption will be invalid if the original HttpCache is constructed with | 248 // assumption will be invalid if the original HttpCache is constructed with |
| 247 // HttpCache(HttpTransactionFactory*, disk_cache::Backend*) constructor. | 249 // HttpCache(HttpTransactionFactory*, disk_cache::Backend*) constructor. |
| 248 net::HttpNetworkLayer* original_network_layer = | 250 net::HttpNetworkLayer* original_network_layer = |
| 249 static_cast<net::HttpNetworkLayer*>(original_cache->network_layer()); | 251 static_cast<net::HttpNetworkLayer*>(original_cache->network_layer()); |
| 250 cache = new net::HttpCache(original_network_layer->GetSession(), | 252 cache = new net::HttpCache(original_network_layer->GetSession(), |
| 251 disk_cache_path.ToWStringHack(), 0); | 253 disk_cache_path.ToWStringHack(), cache_size); |
| 252 } else { | 254 } else { |
| 253 // If original HttpCache doesn't exist, simply construct one with a whole | 255 // If original HttpCache doesn't exist, simply construct one with a whole |
| 254 // new set of network stack. | 256 // new set of network stack. |
| 255 cache = new net::HttpCache(original_context->host_resolver(), | 257 cache = new net::HttpCache(original_context->host_resolver(), |
| 256 original_context->proxy_service(), | 258 original_context->proxy_service(), |
| 257 disk_cache_path.ToWStringHack(), 0); | 259 disk_cache_path.ToWStringHack(), cache_size); |
| 258 } | 260 } |
| 259 | 261 |
| 260 cache->set_type(net::MEDIA_CACHE); | 262 cache->set_type(net::MEDIA_CACHE); |
| 261 context->http_transaction_factory_ = cache; | 263 context->http_transaction_factory_ = cache; |
| 262 return context; | 264 return context; |
| 263 } | 265 } |
| 264 | 266 |
| 265 ChromeURLRequestContext::ChromeURLRequestContext(Profile* profile) | 267 ChromeURLRequestContext::ChromeURLRequestContext(Profile* profile) |
| 266 : prefs_(profile->GetPrefs()), | 268 : prefs_(profile->GetPrefs()), |
| 267 is_media_(false), | 269 is_media_(false), |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 delete cookie_store_; | 461 delete cookie_store_; |
| 460 | 462 |
| 461 // Do not delete the proxy service in the case of OTR or media contexts, as | 463 // Do not delete the proxy service in the case of OTR or media contexts, as |
| 462 // it is owned by the original URLRequestContext. | 464 // it is owned by the original URLRequestContext. |
| 463 if (!is_off_the_record_ && !is_media_) | 465 if (!is_off_the_record_ && !is_media_) |
| 464 delete proxy_service_; | 466 delete proxy_service_; |
| 465 | 467 |
| 466 // Do not delete host_resolver_; it will be freed by FreeGlobalHostResolver() | 468 // Do not delete host_resolver_; it will be freed by FreeGlobalHostResolver() |
| 467 // during the teardown of DNS prefetching. | 469 // during the teardown of DNS prefetching. |
| 468 } | 470 } |
| OLD | NEW |