Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(681)

Side by Side Diff: chrome/browser/net/chrome_url_request_context.cc

Issue 42467: Fix an invalid DCHECK for media request context (Closed)
Patch Set: rvargas & aa's comments Created 11 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/net/chrome_url_request_context.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 context->cookie_store_ = new net::CookieMonster(context->cookie_db_.get()); 101 context->cookie_store_ = new net::CookieMonster(context->cookie_db_.get());
102 } 102 }
103 103
104 return context; 104 return context;
105 } 105 }
106 106
107 // static 107 // static
108 ChromeURLRequestContext* ChromeURLRequestContext::CreateOriginalForMedia( 108 ChromeURLRequestContext* ChromeURLRequestContext::CreateOriginalForMedia(
109 Profile* profile, const FilePath& disk_cache_path) { 109 Profile* profile, const FilePath& disk_cache_path) {
110 DCHECK(!profile->IsOffTheRecord()); 110 DCHECK(!profile->IsOffTheRecord());
111 return CreateRequestContextForMedia(profile, disk_cache_path);
112 }
113
114 // static
115 ChromeURLRequestContext* ChromeURLRequestContext::CreateOffTheRecord(
116 Profile* profile) {
117 DCHECK(profile->IsOffTheRecord());
118 ChromeURLRequestContext* context = new ChromeURLRequestContext(profile);
119
120 // Share the same proxy service as the original profile. This proxy
121 // service's lifespan is dependent on the lifespan of the original profile,
122 // which we reference (see above).
123 context->proxy_service_ =
124 profile->GetOriginalProfile()->GetRequestContext()->proxy_service();
125
126 context->http_transaction_factory_ =
127 new net::HttpCache(context->proxy_service_, 0);
128 context->cookie_store_ = new net::CookieMonster;
129
130 return context;
131 }
132
133 // static
134 ChromeURLRequestContext* ChromeURLRequestContext::CreateOffTheRecordForMedia(
135 Profile* profile, const FilePath& disk_cache_path) {
136 // TODO(hclam): since we don't have an implementation of disk cache backend
137 // for media files in OTR mode, we create a request context just like the
138 // original one.
139 DCHECK(profile->IsOffTheRecord());
140 return CreateRequestContextForMedia(profile, disk_cache_path);
141 }
142
143 // static
144 ChromeURLRequestContext* ChromeURLRequestContext::CreateRequestContextForMedia(
145 Profile* profile, const FilePath& disk_cache_path) {
111 URLRequestContext* original_context = 146 URLRequestContext* original_context =
112 profile->GetOriginalProfile()->GetRequestContext(); 147 profile->GetOriginalProfile()->GetRequestContext();
113 ChromeURLRequestContext* context = new ChromeURLRequestContext(profile); 148 ChromeURLRequestContext* context = new ChromeURLRequestContext(profile);
114 // Share the same proxy service of the common profile. 149 // Share the same proxy service of the common profile.
115 context->proxy_service_ = original_context->proxy_service(); 150 context->proxy_service_ = original_context->proxy_service();
116 // Also share the cookie store of the common profile. 151 // Also share the cookie store of the common profile.
117 context->cookie_store_ = original_context->cookie_store(); 152 context->cookie_store_ = original_context->cookie_store();
118 153
119 // Create a media cache with maximum size of kint32max (2GB). 154 // Create a media cache with maximum size of kint32max (2GB).
120 // TODO(hclam): make the maximum size of media cache configurable. 155 // TODO(hclam): make the maximum size of media cache configurable.
121 net::HttpCache* original_cache = 156 net::HttpCache* original_cache =
122 original_context->http_transaction_factory()->GetCache(); 157 original_context->http_transaction_factory()->GetCache();
123 net::HttpCache* cache; 158 net::HttpCache* cache;
124 if (original_cache) { 159 if (original_cache) {
125 // Try to reuse HttpNetworkSession in the original context, assuming that 160 // Try to reuse HttpNetworkSession in the original context, assuming that
126 // HttpTransactionFactory (network_layer()) of HttpCache is implemented 161 // HttpTransactionFactory (network_layer()) of HttpCache is implemented
127 // by HttpNetworkLayer so we can reuse HttpNetworkSession within it. This 162 // by HttpNetworkLayer so we can reuse HttpNetworkSession within it. This
128 // assumption will be invalid if the original HttpCache is constructed with 163 // assumption will be invalid if the original HttpCache is constructed with
129 // HttpCache(HttpTransactionFactory*, disk_cache::Backend*) constructor. 164 // HttpCache(HttpTransactionFactory*, disk_cache::Backend*) constructor.
130 net::HttpNetworkLayer* original_network_layer = 165 net::HttpNetworkLayer* original_network_layer =
131 static_cast<net::HttpNetworkLayer*>(original_cache->network_layer()); 166 static_cast<net::HttpNetworkLayer*>(original_cache->network_layer());
132 cache = new net::HttpCache(original_network_layer->GetSession(), 167 cache = new net::HttpCache(original_network_layer->GetSession(),
133 disk_cache_path.ToWStringHack(), kint32max); 168 disk_cache_path.ToWStringHack(), kint32max);
134 } else { 169 } else {
135 // If original HttpCache doesn't exist, simply construct one with a whole 170 // If original HttpCache doesn't exist, simply construct one with a whole
136 // new set of network stack. 171 // new set of network stack.
137 cache = new net::HttpCache(original_context->proxy_service(), 172 cache = new net::HttpCache(original_context->proxy_service(),
138 disk_cache_path.ToWStringHack(), kint32max); 173 disk_cache_path.ToWStringHack(), kint32max);
139 } 174 }
140 // Set the cache type to media. 175 // Set the cache type to media.
141 cache->set_type(net::HttpCache::MEDIA); 176 cache->set_type(net::HttpCache::MEDIA);
142 177
143 context->http_transaction_factory_ = cache; 178 context->http_transaction_factory_ = cache;
144 return context; 179 return context;
145 } 180 }
146 181
147 // static
148 ChromeURLRequestContext* ChromeURLRequestContext::CreateOffTheRecord(
149 Profile* profile) {
150 DCHECK(profile->IsOffTheRecord());
151 ChromeURLRequestContext* context = new ChromeURLRequestContext(profile);
152
153 // Share the same proxy service as the original profile. This proxy
154 // service's lifespan is dependent on the lifespan of the original profile,
155 // which we reference (see above).
156 context->proxy_service_ =
157 profile->GetOriginalProfile()->GetRequestContext()->proxy_service();
158
159 context->http_transaction_factory_ =
160 new net::HttpCache(context->proxy_service_, 0);
161 context->cookie_store_ = new net::CookieMonster;
162
163 return context;
164 }
165
166 // static
167 ChromeURLRequestContext* ChromeURLRequestContext::CreateOffTheRecordForMedia(
168 Profile* profile, const FilePath& disk_cache_path) {
169 // TODO(hclam): since we don't have an implementation of disk cache backend
170 // for media files in OTR mode, we use the original context first. Change this
171 // to the proper backend later.
172 return CreateOriginalForMedia(profile, disk_cache_path);
173 }
174
175 ChromeURLRequestContext::ChromeURLRequestContext(Profile* profile) 182 ChromeURLRequestContext::ChromeURLRequestContext(Profile* profile)
176 : prefs_(profile->GetPrefs()), 183 : prefs_(profile->GetPrefs()),
177 is_off_the_record_(profile->IsOffTheRecord()) { 184 is_off_the_record_(profile->IsOffTheRecord()) {
178 // Set up Accept-Language and Accept-Charset header values 185 // Set up Accept-Language and Accept-Charset header values
179 accept_language_ = net::HttpUtil::GenerateAcceptLanguageHeader( 186 accept_language_ = net::HttpUtil::GenerateAcceptLanguageHeader(
180 WideToASCII(prefs_->GetString(prefs::kAcceptLanguages))); 187 WideToASCII(prefs_->GetString(prefs::kAcceptLanguages)));
181 accept_charset_ = net::HttpUtil::GenerateAcceptCharsetHeader( 188 accept_charset_ = net::HttpUtil::GenerateAcceptCharsetHeader(
182 WideToASCII(prefs_->GetString(prefs::kDefaultCharset))); 189 WideToASCII(prefs_->GetString(prefs::kDefaultCharset)));
183 190
184 cookie_policy_.SetType(net::CookiePolicy::FromInt( 191 cookie_policy_.SetType(net::CookiePolicy::FromInt(
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 306
300 delete cookie_store_; 307 delete cookie_store_;
301 delete ftp_transaction_factory_; 308 delete ftp_transaction_factory_;
302 delete http_transaction_factory_; 309 delete http_transaction_factory_;
303 310
304 // Do not delete the proxy service in the case of OTR, as it is owned by the 311 // Do not delete the proxy service in the case of OTR, as it is owned by the
305 // original URLRequestContext. 312 // original URLRequestContext.
306 if (!is_off_the_record_) 313 if (!is_off_the_record_)
307 delete proxy_service_; 314 delete proxy_service_;
308 } 315 }
OLDNEW
« no previous file with comments | « chrome/browser/net/chrome_url_request_context.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698