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

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

Issue 215024: Fix appcache_service and request_context referencing. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 3 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 proxy_config.get(), 103 proxy_config.get(),
104 use_v8, 104 use_v8,
105 context, 105 context,
106 g_browser_process->io_thread()->message_loop(), 106 g_browser_process->io_thread()->message_loop(),
107 g_browser_process->file_thread()->message_loop()); 107 g_browser_process->file_thread()->message_loop());
108 } 108 }
109 109
110 // static 110 // static
111 ChromeURLRequestContext* ChromeURLRequestContext::CreateOriginal( 111 ChromeURLRequestContext* ChromeURLRequestContext::CreateOriginal(
112 Profile* profile, const FilePath& cookie_store_path, 112 Profile* profile, const FilePath& cookie_store_path,
113 const FilePath& disk_cache_path, int cache_size) { 113 const FilePath& disk_cache_path, int cache_size,
114 ChromeAppCacheService* appcache_service) {
114 DCHECK(!profile->IsOffTheRecord()); 115 DCHECK(!profile->IsOffTheRecord());
115 ChromeURLRequestContext* context = new ChromeURLRequestContext(profile); 116 ChromeURLRequestContext* context = new ChromeURLRequestContext(
117 profile, appcache_service);
118
119 // The appcache service uses the profile's original context for UpdateJobs.
120 DCHECK(!appcache_service->request_context());
121 appcache_service->set_request_context(context);
116 122
117 // Global host resolver for the context. 123 // Global host resolver for the context.
118 context->host_resolver_ = chrome_browser_net::GetGlobalHostResolver(); 124 context->host_resolver_ = chrome_browser_net::GetGlobalHostResolver();
119 125
120 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 126 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
121 127
122 context->proxy_service_ = CreateProxyService(context, command_line); 128 context->proxy_service_ = CreateProxyService(context, command_line);
123 129
124 net::HttpCache* cache = 130 net::HttpCache* cache =
125 new net::HttpCache(context->host_resolver_, 131 new net::HttpCache(context->host_resolver_,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 cookie_store_path, 168 cookie_store_path,
163 g_browser_process->db_thread()->message_loop()); 169 g_browser_process->db_thread()->message_loop());
164 context->cookie_store_ = new net::CookieMonster(cookie_db.get()); 170 context->cookie_store_ = new net::CookieMonster(cookie_db.get());
165 } 171 }
166 172
167 return context; 173 return context;
168 } 174 }
169 175
170 // static 176 // static
171 ChromeURLRequestContext* ChromeURLRequestContext::CreateOriginalForMedia( 177 ChromeURLRequestContext* ChromeURLRequestContext::CreateOriginalForMedia(
172 Profile* profile, const FilePath& disk_cache_path, int cache_size) { 178 Profile* profile, const FilePath& disk_cache_path, int cache_size,
179 ChromeAppCacheService* appcache_service) {
173 DCHECK(!profile->IsOffTheRecord()); 180 DCHECK(!profile->IsOffTheRecord());
174 return CreateRequestContextForMedia(profile, disk_cache_path, cache_size, 181 return CreateRequestContextForMedia(profile, disk_cache_path, cache_size,
175 false); 182 false, appcache_service);
176 } 183 }
177 184
178 // static 185 // static
179 ChromeURLRequestContext* ChromeURLRequestContext::CreateOriginalForExtensions( 186 ChromeURLRequestContext* ChromeURLRequestContext::CreateOriginalForExtensions(
180 Profile* profile, const FilePath& cookie_store_path) { 187 Profile* profile, const FilePath& cookie_store_path) {
181 DCHECK(!profile->IsOffTheRecord()); 188 DCHECK(!profile->IsOffTheRecord());
182 ChromeURLRequestContext* context = new ChromeURLRequestContext(profile); 189 ChromeURLRequestContext* context = new ChromeURLRequestContext(
190 profile, NULL);
183 191
184 // All we care about for extensions is the cookie store. 192 // All we care about for extensions is the cookie store.
185 DCHECK(!cookie_store_path.empty()); 193 DCHECK(!cookie_store_path.empty());
186 194
187 scoped_refptr<SQLitePersistentCookieStore> cookie_db = 195 scoped_refptr<SQLitePersistentCookieStore> cookie_db =
188 new SQLitePersistentCookieStore( 196 new SQLitePersistentCookieStore(
189 cookie_store_path, 197 cookie_store_path,
190 g_browser_process->db_thread()->message_loop()); 198 g_browser_process->db_thread()->message_loop());
191 net::CookieMonster* cookie_monster = new net::CookieMonster(cookie_db.get()); 199 net::CookieMonster* cookie_monster = new net::CookieMonster(cookie_db.get());
192 200
193 // Enable cookies for extension URLs only. 201 // Enable cookies for extension URLs only.
194 const char* schemes[] = {chrome::kExtensionScheme}; 202 const char* schemes[] = {chrome::kExtensionScheme};
195 cookie_monster->SetCookieableSchemes(schemes, 1); 203 cookie_monster->SetCookieableSchemes(schemes, 1);
196 context->cookie_store_ = cookie_monster; 204 context->cookie_store_ = cookie_monster;
197 205
198 return context; 206 return context;
199 } 207 }
200 208
201 // static 209 // static
202 ChromeURLRequestContext* ChromeURLRequestContext::CreateOffTheRecord( 210 ChromeURLRequestContext* ChromeURLRequestContext::CreateOffTheRecord(
203 Profile* profile) { 211 Profile* profile, ChromeAppCacheService* appcache_service) {
204 DCHECK(profile->IsOffTheRecord()); 212 DCHECK(profile->IsOffTheRecord());
205 ChromeURLRequestContext* context = new ChromeURLRequestContext(profile); 213 ChromeURLRequestContext* context = new ChromeURLRequestContext(
214 profile, appcache_service);
215
216 // The appcache service uses the profile's original context for UpdateJobs.
217 DCHECK(!appcache_service->request_context());
218 appcache_service->set_request_context(context);
206 219
207 // Share the same proxy service and host resolver as the original profile. 220 // Share the same proxy service and host resolver as the original profile.
208 // TODO(eroman): although ProxyService is reference counted, this sharing 221 // TODO(eroman): although ProxyService is reference counted, this sharing
209 // still has a subtle dependency on the lifespan of the original profile -- 222 // still has a subtle dependency on the lifespan of the original profile --
210 // ProxyService holds a (non referencing) pointer to the URLRequestContext 223 // ProxyService holds a (non referencing) pointer to the URLRequestContext
211 // it uses to download PAC scripts, which in this case is the original 224 // it uses to download PAC scripts, which in this case is the original
212 // profile... 225 // profile...
213 context->host_resolver_ = 226 context->host_resolver_ =
214 profile->GetOriginalProfile()->GetRequestContext()->host_resolver(); 227 profile->GetOriginalProfile()->GetRequestContext()->host_resolver();
215 context->proxy_service_ = 228 context->proxy_service_ =
(...skipping 20 matching lines...) Expand all
236 new net::FtpNetworkLayer(context->host_resolver_); 249 new net::FtpNetworkLayer(context->host_resolver_);
237 #endif 250 #endif
238 251
239 return context; 252 return context;
240 } 253 }
241 254
242 // static 255 // static
243 ChromeURLRequestContext* 256 ChromeURLRequestContext*
244 ChromeURLRequestContext::CreateOffTheRecordForExtensions(Profile* profile) { 257 ChromeURLRequestContext::CreateOffTheRecordForExtensions(Profile* profile) {
245 DCHECK(profile->IsOffTheRecord()); 258 DCHECK(profile->IsOffTheRecord());
246 ChromeURLRequestContext* context = new ChromeURLRequestContext(profile); 259 ChromeURLRequestContext* context =
260 new ChromeURLRequestContext(profile, NULL);
247 net::CookieMonster* cookie_monster = new net::CookieMonster; 261 net::CookieMonster* cookie_monster = new net::CookieMonster;
248 262
249 // Enable cookies for extension URLs only. 263 // Enable cookies for extension URLs only.
250 const char* schemes[] = {chrome::kExtensionScheme}; 264 const char* schemes[] = {chrome::kExtensionScheme};
251 cookie_monster->SetCookieableSchemes(schemes, 1); 265 cookie_monster->SetCookieableSchemes(schemes, 1);
252 context->cookie_store_ = cookie_monster; 266 context->cookie_store_ = cookie_monster;
253 267
254 return context; 268 return context;
255 } 269 }
256 270
257 // static 271 // static
258 ChromeURLRequestContext* ChromeURLRequestContext::CreateRequestContextForMedia( 272 ChromeURLRequestContext* ChromeURLRequestContext::CreateRequestContextForMedia(
259 Profile* profile, const FilePath& disk_cache_path, int cache_size, 273 Profile* profile, const FilePath& disk_cache_path, int cache_size,
260 bool off_the_record) { 274 bool off_the_record, ChromeAppCacheService* appcache_service) {
261 URLRequestContext* original_context = 275 URLRequestContext* original_context =
262 profile->GetOriginalProfile()->GetRequestContext(); 276 profile->GetOriginalProfile()->GetRequestContext();
263 ChromeURLRequestContext* context = new ChromeURLRequestContext(profile); 277 ChromeURLRequestContext* context =
278 new ChromeURLRequestContext(profile, appcache_service);
264 context->is_media_ = true; 279 context->is_media_ = true;
265 280
266 // Share the same proxy service of the common profile. 281 // Share the same proxy service of the common profile.
267 context->proxy_service_ = original_context->proxy_service(); 282 context->proxy_service_ = original_context->proxy_service();
268 // Also share the cookie store of the common profile. 283 // Also share the cookie store of the common profile.
269 context->cookie_store_ = original_context->cookie_store(); 284 context->cookie_store_ = original_context->cookie_store();
270 285
271 // Create a media cache with default size. 286 // Create a media cache with default size.
272 // TODO(hclam): make the maximum size of media cache configurable. 287 // TODO(hclam): make the maximum size of media cache configurable.
273 net::HttpCache* original_cache = 288 net::HttpCache* original_cache =
(...skipping 20 matching lines...) Expand all
294 309
295 if (CommandLine::ForCurrentProcess()->HasSwitch( 310 if (CommandLine::ForCurrentProcess()->HasSwitch(
296 switches::kEnableByteRangeSupport)) 311 switches::kEnableByteRangeSupport))
297 cache->set_enable_range_support(true); 312 cache->set_enable_range_support(true);
298 313
299 cache->set_type(net::MEDIA_CACHE); 314 cache->set_type(net::MEDIA_CACHE);
300 context->http_transaction_factory_ = cache; 315 context->http_transaction_factory_ = cache;
301 return context; 316 return context;
302 } 317 }
303 318
304 ChromeURLRequestContext::ChromeURLRequestContext(Profile* profile) 319 ChromeURLRequestContext::ChromeURLRequestContext(
305 : prefs_(profile->GetPrefs()), 320 Profile* profile, ChromeAppCacheService* appcache_service)
321 : appcache_service_(appcache_service),
322 prefs_(profile->GetPrefs()),
306 is_media_(false), 323 is_media_(false),
307 is_off_the_record_(profile->IsOffTheRecord()) { 324 is_off_the_record_(profile->IsOffTheRecord()) {
308 // Set up Accept-Language and Accept-Charset header values 325 // Set up Accept-Language and Accept-Charset header values
309 accept_language_ = net::HttpUtil::GenerateAcceptLanguageHeader( 326 accept_language_ = net::HttpUtil::GenerateAcceptLanguageHeader(
310 WideToASCII(prefs_->GetString(prefs::kAcceptLanguages))); 327 WideToASCII(prefs_->GetString(prefs::kAcceptLanguages)));
311 std::string default_charset = 328 std::string default_charset =
312 WideToASCII(prefs_->GetString(prefs::kDefaultCharset)); 329 WideToASCII(prefs_->GetString(prefs::kDefaultCharset));
313 accept_charset_ = 330 accept_charset_ =
314 net::HttpUtil::GenerateAcceptCharsetHeader(default_charset); 331 net::HttpUtil::GenerateAcceptCharsetHeader(default_charset);
315 332
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 prefs_->AddPrefObserver(prefs::kDefaultCharset, this); 368 prefs_->AddPrefObserver(prefs::kDefaultCharset, this);
352 369
353 if (!is_off_the_record_) { 370 if (!is_off_the_record_) {
354 registrar_.Add(this, NotificationType::EXTENSION_LOADED, 371 registrar_.Add(this, NotificationType::EXTENSION_LOADED,
355 NotificationService::AllSources()); 372 NotificationService::AllSources());
356 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, 373 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED,
357 NotificationService::AllSources()); 374 NotificationService::AllSources());
358 } 375 }
359 376
360 ssl_config_service_ = profile->GetSSLConfigService(); 377 ssl_config_service_ = profile->GetSSLConfigService();
361
362 appcache_service_ = profile->GetAppCacheService();
363 } 378 }
364 379
365 ChromeURLRequestContext::ChromeURLRequestContext( 380 ChromeURLRequestContext::ChromeURLRequestContext(
366 ChromeURLRequestContext* other) { 381 ChromeURLRequestContext* other) {
367 // Set URLRequestContext members 382 // Set URLRequestContext members
368 host_resolver_ = other->host_resolver_; 383 host_resolver_ = other->host_resolver_;
369 proxy_service_ = other->proxy_service_; 384 proxy_service_ = other->proxy_service_;
370 ssl_config_service_ = other->ssl_config_service_; 385 ssl_config_service_ = other->ssl_config_service_;
371 http_transaction_factory_ = other->http_transaction_factory_; 386 http_transaction_factory_ = other->http_transaction_factory_;
372 ftp_transaction_factory_ = other->ftp_transaction_factory_; 387 ftp_transaction_factory_ = other->ftp_transaction_factory_;
373 cookie_store_ = other->cookie_store_; 388 cookie_store_ = other->cookie_store_;
374 cookie_policy_.set_type(other->cookie_policy_.type()); 389 cookie_policy_.set_type(other->cookie_policy_.type());
375 strict_transport_security_state_ = other->strict_transport_security_state_; 390 strict_transport_security_state_ = other->strict_transport_security_state_;
376 accept_language_ = other->accept_language_; 391 accept_language_ = other->accept_language_;
377 accept_charset_ = other->accept_charset_; 392 accept_charset_ = other->accept_charset_;
378 referrer_charset_ = other->referrer_charset_; 393 referrer_charset_ = other->referrer_charset_;
379 394
380 // Set ChromeURLRequestContext members 395 // Set ChromeURLRequestContext members
396 appcache_service_ = other->appcache_service_;
381 extension_paths_ = other->extension_paths_; 397 extension_paths_ = other->extension_paths_;
382 user_script_dir_path_ = other->user_script_dir_path_; 398 user_script_dir_path_ = other->user_script_dir_path_;
383 prefs_ = other->prefs_; 399 prefs_ = other->prefs_;
384 blacklist_ = other->blacklist_; 400 blacklist_ = other->blacklist_;
385 is_media_ = other->is_media_; 401 is_media_ = other->is_media_;
386 is_off_the_record_ = other->is_off_the_record_; 402 is_off_the_record_ = other->is_off_the_record_;
387 appcache_service_ = other->appcache_service_;
388 } 403 }
389 404
390 // NotificationObserver implementation. 405 // NotificationObserver implementation.
391 void ChromeURLRequestContext::Observe(NotificationType type, 406 void ChromeURLRequestContext::Observe(NotificationType type,
392 const NotificationSource& source, 407 const NotificationSource& source,
393 const NotificationDetails& details) { 408 const NotificationDetails& details) {
394 if (NotificationType::PREF_CHANGED == type) { 409 if (NotificationType::PREF_CHANGED == type) {
395 std::wstring* pref_name_in = Details<std::wstring>(details).ptr(); 410 std::wstring* pref_name_in = Details<std::wstring>(details).ptr();
396 PrefService* prefs = Source<PrefService>(source).ptr(); 411 PrefService* prefs = Source<PrefService>(source).ptr();
397 DCHECK(pref_name_in && prefs); 412 DCHECK(pref_name_in && prefs);
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 void ChromeURLRequestContext::OnUnloadedExtension( 547 void ChromeURLRequestContext::OnUnloadedExtension(
533 const std::string& extension_id) { 548 const std::string& extension_id) {
534 ExtensionPaths::iterator iter = extension_paths_.find(extension_id); 549 ExtensionPaths::iterator iter = extension_paths_.find(extension_id);
535 DCHECK(iter != extension_paths_.end()); 550 DCHECK(iter != extension_paths_.end());
536 extension_paths_.erase(iter); 551 extension_paths_.erase(iter);
537 } 552 }
538 553
539 ChromeURLRequestContext::~ChromeURLRequestContext() { 554 ChromeURLRequestContext::~ChromeURLRequestContext() {
540 DCHECK(NULL == prefs_); 555 DCHECK(NULL == prefs_);
541 556
557 if (appcache_service_.get() && appcache_service_->request_context() == this)
558 appcache_service_->set_request_context(NULL);
559
542 NotificationService::current()->Notify( 560 NotificationService::current()->Notify(
543 NotificationType::URL_REQUEST_CONTEXT_RELEASED, 561 NotificationType::URL_REQUEST_CONTEXT_RELEASED,
544 Source<URLRequestContext>(this), 562 Source<URLRequestContext>(this),
545 NotificationService::NoDetails()); 563 NotificationService::NoDetails());
546 564
547 delete ftp_transaction_factory_; 565 delete ftp_transaction_factory_;
548 delete http_transaction_factory_; 566 delete http_transaction_factory_;
549 } 567 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698