| 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" |
| 11 #include "chrome/browser/extensions/extensions_service.h" | 11 #include "chrome/browser/extensions/extensions_service.h" |
| 12 #include "chrome/browser/extensions/user_script_master.h" | 12 #include "chrome/browser/extensions/user_script_master.h" |
| 13 #include "chrome/browser/profile.h" | 13 #include "chrome/browser/profile.h" |
| 14 #include "chrome/common/chrome_constants.h" | 14 #include "chrome/common/chrome_constants.h" |
| 15 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
| 16 #include "chrome/common/notification_service.h" | 16 #include "chrome/common/notification_service.h" |
| 17 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
| 18 #include "net/http/http_cache.h" | 18 #include "net/http/http_cache.h" |
| 19 #include "net/http/http_network_layer.h" |
| 19 #include "net/http/http_util.h" | 20 #include "net/http/http_util.h" |
| 20 #include "net/proxy/proxy_service.h" | 21 #include "net/proxy/proxy_service.h" |
| 21 #include "webkit/glue/webkit_glue.h" | 22 #include "webkit/glue/webkit_glue.h" |
| 22 | 23 |
| 23 // Sets up proxy info if it was specified, otherwise returns NULL. The | 24 // Sets up proxy info if it was specified, otherwise returns NULL. The |
| 24 // returned pointer MUST be deleted by the caller if non-NULL. | 25 // returned pointer MUST be deleted by the caller if non-NULL. |
| 25 static net::ProxyInfo* CreateProxyInfo() { | 26 static net::ProxyInfo* CreateProxyInfo() { |
| 26 net::ProxyInfo* proxy_info = NULL; | 27 net::ProxyInfo* proxy_info = NULL; |
| 27 | 28 |
| 28 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 29 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 context->cookie_db_.reset(new SQLitePersistentCookieStore( | 70 context->cookie_db_.reset(new SQLitePersistentCookieStore( |
| 70 cookie_store_path.ToWStringHack(), | 71 cookie_store_path.ToWStringHack(), |
| 71 g_browser_process->db_thread()->message_loop())); | 72 g_browser_process->db_thread()->message_loop())); |
| 72 context->cookie_store_ = new net::CookieMonster(context->cookie_db_.get()); | 73 context->cookie_store_ = new net::CookieMonster(context->cookie_db_.get()); |
| 73 } | 74 } |
| 74 | 75 |
| 75 return context; | 76 return context; |
| 76 } | 77 } |
| 77 | 78 |
| 78 // static | 79 // static |
| 80 ChromeURLRequestContext* ChromeURLRequestContext::CreateOriginalForMedia( |
| 81 Profile* profile, const FilePath& disk_cache_path) { |
| 82 DCHECK(!profile->IsOffTheRecord()); |
| 83 URLRequestContext* original_context = |
| 84 profile->GetOriginalProfile()->GetRequestContext(); |
| 85 ChromeURLRequestContext* context = new ChromeURLRequestContext(profile); |
| 86 // Share the same proxy service of the common profile. |
| 87 context->proxy_service_ = original_context->proxy_service(); |
| 88 // Also share the cookie store of the common profile. |
| 89 context->cookie_store_ = original_context->cookie_store(); |
| 90 |
| 91 // Create a media cache with maximum size of kint32max (2GB). |
| 92 // TODO(hclam): make the maximum size of media cache configurable. |
| 93 net::HttpCache* original_cache = |
| 94 original_context->http_transaction_factory()->GetCache(); |
| 95 net::HttpCache* cache; |
| 96 if (original_cache) { |
| 97 // Try to reuse HttpNetworkSession in the original context, assuming that |
| 98 // HttpTransactionFactory (network_layer()) of HttpCache is implemented |
| 99 // by HttpNetworkLayer so we can reuse HttpNetworkSession within it. This |
| 100 // assumption will be invalid if the original HttpCache is constructed with |
| 101 // HttpCache(HttpTransactionFactory*, disk_cache::Backend*) constructor. |
| 102 net::HttpNetworkLayer* original_network_layer = |
| 103 static_cast<net::HttpNetworkLayer*>(original_cache->network_layer()); |
| 104 cache = new net::HttpCache(original_network_layer->GetSession(), |
| 105 disk_cache_path.ToWStringHack(), kint32max); |
| 106 } else { |
| 107 // If original HttpCache doesn't exist, simply construct one with a whole |
| 108 // new set of network stack. |
| 109 cache = new net::HttpCache(original_context->proxy_service(), |
| 110 disk_cache_path.ToWStringHack(), kint32max); |
| 111 } |
| 112 // Set the cache type to media. |
| 113 cache->set_type(net::HttpCache::MEDIA); |
| 114 |
| 115 context->http_transaction_factory_ = cache; |
| 116 return context; |
| 117 } |
| 118 |
| 119 // static |
| 79 ChromeURLRequestContext* ChromeURLRequestContext::CreateOffTheRecord( | 120 ChromeURLRequestContext* ChromeURLRequestContext::CreateOffTheRecord( |
| 80 Profile* profile) { | 121 Profile* profile) { |
| 81 DCHECK(profile->IsOffTheRecord()); | 122 DCHECK(profile->IsOffTheRecord()); |
| 82 ChromeURLRequestContext* context = new ChromeURLRequestContext(profile); | 123 ChromeURLRequestContext* context = new ChromeURLRequestContext(profile); |
| 83 | 124 |
| 84 // Share the same proxy service as the original profile. This proxy | 125 // Share the same proxy service as the original profile. This proxy |
| 85 // service's lifespan is dependent on the lifespan of the original profile, | 126 // service's lifespan is dependent on the lifespan of the original profile, |
| 86 // which we reference (see above). | 127 // which we reference (see above). |
| 87 context->proxy_service_ = | 128 context->proxy_service_ = |
| 88 profile->GetOriginalProfile()->GetRequestContext()->proxy_service(); | 129 profile->GetOriginalProfile()->GetRequestContext()->proxy_service(); |
| 89 | 130 |
| 90 context->http_transaction_factory_ = | 131 context->http_transaction_factory_ = |
| 91 new net::HttpCache(context->proxy_service_, 0); | 132 new net::HttpCache(context->proxy_service_, 0); |
| 92 context->cookie_store_ = new net::CookieMonster; | 133 context->cookie_store_ = new net::CookieMonster; |
| 93 | 134 |
| 94 return context; | 135 return context; |
| 95 } | 136 } |
| 96 | 137 |
| 138 // static |
| 139 ChromeURLRequestContext* ChromeURLRequestContext::CreateOffTheRecordForMedia( |
| 140 Profile* profile, const FilePath& disk_cache_path) { |
| 141 // TODO(hclam): since we don't have an implementation of disk cache backend |
| 142 // for media files in OTR mode, we use the original context first. Change this |
| 143 // to the proper backend later. |
| 144 return CreateOriginalForMedia(profile, disk_cache_path); |
| 145 } |
| 146 |
| 97 ChromeURLRequestContext::ChromeURLRequestContext(Profile* profile) | 147 ChromeURLRequestContext::ChromeURLRequestContext(Profile* profile) |
| 98 : prefs_(profile->GetPrefs()), | 148 : prefs_(profile->GetPrefs()), |
| 99 is_off_the_record_(profile->IsOffTheRecord()) { | 149 is_off_the_record_(profile->IsOffTheRecord()) { |
| 100 // Set up Accept-Language and Accept-Charset header values | 150 // Set up Accept-Language and Accept-Charset header values |
| 101 accept_language_ = net::HttpUtil::GenerateAcceptLanguageHeader( | 151 accept_language_ = net::HttpUtil::GenerateAcceptLanguageHeader( |
| 102 WideToASCII(prefs_->GetString(prefs::kAcceptLanguages))); | 152 WideToASCII(prefs_->GetString(prefs::kAcceptLanguages))); |
| 103 accept_charset_ = net::HttpUtil::GenerateAcceptCharsetHeader( | 153 accept_charset_ = net::HttpUtil::GenerateAcceptCharsetHeader( |
| 104 WideToASCII(prefs_->GetString(prefs::kDefaultCharset))); | 154 WideToASCII(prefs_->GetString(prefs::kDefaultCharset))); |
| 105 | 155 |
| 106 cookie_policy_.SetType(net::CookiePolicy::FromInt( | 156 cookie_policy_.SetType(net::CookiePolicy::FromInt( |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 NotificationService::NoDetails()); | 270 NotificationService::NoDetails()); |
| 221 | 271 |
| 222 delete cookie_store_; | 272 delete cookie_store_; |
| 223 delete http_transaction_factory_; | 273 delete http_transaction_factory_; |
| 224 | 274 |
| 225 // Do not delete the proxy service in the case of OTR, as it is owned by the | 275 // Do not delete the proxy service in the case of OTR, as it is owned by the |
| 226 // original URLRequestContext. | 276 // original URLRequestContext. |
| 227 if (!is_off_the_record_) | 277 if (!is_off_the_record_) |
| 228 delete proxy_service_; | 278 delete proxy_service_; |
| 229 } | 279 } |
| OLD | NEW |