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

Side by Side Diff: chrome/browser/profiles/profile_impl_io_data.cc

Issue 11147026: Initial refactor to get profiles to propagate storage partition details. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Changing bool param to pass by reference. Created 8 years, 2 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/profiles/profile_impl_io_data.h" 5 #include "chrome/browser/profiles/profile_impl_io_data.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 if (!extensions_request_context_getter_) { 201 if (!extensions_request_context_getter_) {
202 extensions_request_context_getter_ = 202 extensions_request_context_getter_ =
203 ChromeURLRequestContextGetter::CreateOriginalForExtensions( 203 ChromeURLRequestContextGetter::CreateOriginalForExtensions(
204 profile_, io_data_); 204 profile_, io_data_);
205 } 205 }
206 return extensions_request_context_getter_; 206 return extensions_request_context_getter_;
207 } 207 }
208 208
209 scoped_refptr<ChromeURLRequestContextGetter> 209 scoped_refptr<ChromeURLRequestContextGetter>
210 ProfileImplIOData::Handle::GetIsolatedAppRequestContextGetter( 210 ProfileImplIOData::Handle::GetIsolatedAppRequestContextGetter(
211 const std::string& app_id) const { 211 const StoragePartitionDetails& partition_details) const {
212 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 212 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
213 CHECK(!app_id.empty()); 213 // TODO(nasko): Enable this check, once the browser tag is properly
214 // isolated in its own directory.
215 // CHECK_NE(partition_details.path.value(), profile_->GetPath().value());
214 LazyInitialize(); 216 LazyInitialize();
215 217
216 // Keep a map of request context getters, one per requested app ID. 218 // Keep a map of request context getters, one per requested storage partition.
217 ChromeURLRequestContextGetterMap::iterator iter = 219 ChromeURLRequestContextGetterMap::iterator iter =
218 app_request_context_getter_map_.find(app_id); 220 app_request_context_getter_map_.find(partition_details);
219 if (iter != app_request_context_getter_map_.end()) 221 if (iter != app_request_context_getter_map_.end())
220 return iter->second; 222 return iter->second;
221 223
222 scoped_ptr<net::URLRequestJobFactory::Interceptor> 224 scoped_ptr<net::URLRequestJobFactory::Interceptor>
223 protocol_handler_interceptor( 225 protocol_handler_interceptor(
224 ProtocolHandlerRegistryFactory::GetForProfile(profile_)-> 226 ProtocolHandlerRegistryFactory::GetForProfile(profile_)->
225 CreateURLInterceptor()); 227 CreateURLInterceptor());
226 ChromeURLRequestContextGetter* context = 228 ChromeURLRequestContextGetter* context =
227 ChromeURLRequestContextGetter::CreateOriginalForIsolatedApp( 229 ChromeURLRequestContextGetter::CreateOriginalForIsolatedApp(
228 profile_, io_data_, app_id, protocol_handler_interceptor.Pass()); 230 profile_, io_data_, partition_details,
229 app_request_context_getter_map_[app_id] = context; 231 protocol_handler_interceptor.Pass());
232 app_request_context_getter_map_[partition_details] = context;
230 233
231 return context; 234 return context;
232 } 235 }
233 236
234 scoped_refptr<ChromeURLRequestContextGetter> 237 scoped_refptr<ChromeURLRequestContextGetter>
235 ProfileImplIOData::Handle::GetIsolatedMediaRequestContextGetter( 238 ProfileImplIOData::Handle::GetIsolatedMediaRequestContextGetter(
236 const std::string& app_id) const { 239 const StoragePartitionDetails& partition_details) const {
237 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 240 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
238 // We must have an app ID, or this will act like the default media context. 241 // We must have a non-default path, or this will act like the default media
239 CHECK(!app_id.empty()); 242 // context.
243 // TODO(nasko): Enable this check, once the browser tag is properly
244 // isolated in its own directory.
245 // CHECK_NE(partition_details.path.value(), profile_->GetPath().value());
240 LazyInitialize(); 246 LazyInitialize();
241 247
242 // Keep a map of request context getters, one per requested app ID. 248 // Keep a map of request context getters, one per requested storage partition.
243 ChromeURLRequestContextGetterMap::iterator iter = 249 ChromeURLRequestContextGetterMap::iterator iter =
244 isolated_media_request_context_getter_map_.find(app_id); 250 isolated_media_request_context_getter_map_.find(partition_details);
245 if (iter != isolated_media_request_context_getter_map_.end()) 251 if (iter != isolated_media_request_context_getter_map_.end())
246 return iter->second; 252 return iter->second;
247 253
248 // Get the app context as the starting point for the media context, so that 254 // Get the app context as the starting point for the media context, so that
249 // it uses the app's cookie store. 255 // it uses the app's cookie store.
250 ChromeURLRequestContextGetter* app_context = 256 ChromeURLRequestContextGetter* app_context =
251 GetIsolatedAppRequestContextGetter(app_id); 257 GetIsolatedAppRequestContextGetter(partition_details);
252 ChromeURLRequestContextGetter* context = 258 ChromeURLRequestContextGetter* context =
253 ChromeURLRequestContextGetter::CreateOriginalForIsolatedMedia( 259 ChromeURLRequestContextGetter::CreateOriginalForIsolatedMedia(
254 profile_, app_context, io_data_, app_id); 260 profile_, app_context, io_data_, partition_details);
255 isolated_media_request_context_getter_map_[app_id] = context; 261 isolated_media_request_context_getter_map_[partition_details] = context;
256 262
257 return context; 263 return context;
258 } 264 }
259 265
260 void ProfileImplIOData::Handle::ClearNetworkingHistorySince( 266 void ProfileImplIOData::Handle::ClearNetworkingHistorySince(
261 base::Time time) { 267 base::Time time) {
262 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 268 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
263 LazyInitialize(); 269 LazyInitialize();
264 270
265 BrowserThread::PostTask( 271 BrowserThread::PostTask(
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 scoped_ptr<net::URLRequestJobFactoryImpl::Interceptor>(NULL), 467 scoped_ptr<net::URLRequestJobFactoryImpl::Interceptor>(NULL),
462 NULL, 468 NULL,
463 extensions_context->ftp_transaction_factory(), 469 extensions_context->ftp_transaction_factory(),
464 extensions_context->ftp_auth_cache()); 470 extensions_context->ftp_auth_cache());
465 471
466 main_context->set_job_factory(main_job_factory_.get()); 472 main_context->set_job_factory(main_job_factory_.get());
467 extensions_context->set_job_factory(extensions_job_factory_.get()); 473 extensions_context->set_job_factory(extensions_job_factory_.get());
468 474
469 // Create a media request context based on the main context, but using a 475 // Create a media request context based on the main context, but using a
470 // media cache. It shares the same job factory as the main context. 476 // media cache. It shares the same job factory as the main context.
471 media_request_context_.reset(InitializeMediaRequestContext(main_context, "")); 477 StoragePartitionDetails details(FilePath(), false);
478 media_request_context_.reset(InitializeMediaRequestContext(main_context,
479 details));
472 480
473 lazy_params_.reset(); 481 lazy_params_.reset();
474 } 482 }
475 483
476 ChromeURLRequestContext* 484 ChromeURLRequestContext*
477 ProfileImplIOData::InitializeAppRequestContext( 485 ProfileImplIOData::InitializeAppRequestContext(
478 ChromeURLRequestContext* main_context, 486 ChromeURLRequestContext* main_context,
479 const std::string& app_id, 487 const StoragePartitionDetails& partition_details,
480 scoped_ptr<net::URLRequestJobFactory::Interceptor> 488 scoped_ptr<net::URLRequestJobFactory::Interceptor>
481 protocol_handler_interceptor) const { 489 protocol_handler_interceptor) const {
482 // If this is for a guest process, we should not persist cookies and http
483 // cache.
484 bool is_guest_process = (app_id.find("guest-") != std::string::npos);
485
486 // Copy most state from the main context. 490 // Copy most state from the main context.
487 AppRequestContext* context = new AppRequestContext(load_time_stats()); 491 AppRequestContext* context = new AppRequestContext(load_time_stats());
488 context->CopyFrom(main_context); 492 context->CopyFrom(main_context);
489 493
490 using content::StoragePartition; 494 FilePath cookie_path = partition_details.path.Append(chrome::kCookieFilename);
491 FilePath app_path = 495 FilePath cache_path = partition_details.path.Append(chrome::kCacheDirname);
492 profile_path_.Append(StoragePartition::GetPartitionPath(app_id));
493
494 FilePath cookie_path = app_path.Append(chrome::kCookieFilename);
495 FilePath cache_path = app_path.Append(chrome::kCacheDirname);
496 496
497 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 497 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
498 // Only allow Record Mode if we are in a Debug build or where we are running 498 // Only allow Record Mode if we are in a Debug build or where we are running
499 // a cycle, and the user has limited control. 499 // a cycle, and the user has limited control.
500 bool record_mode = command_line.HasSwitch(switches::kRecordMode) && 500 bool record_mode = command_line.HasSwitch(switches::kRecordMode) &&
501 (chrome::kRecordModeEnabled || 501 (chrome::kRecordModeEnabled ||
502 command_line.HasSwitch(switches::kVisitURLs)); 502 command_line.HasSwitch(switches::kVisitURLs));
503 bool playback_mode = command_line.HasSwitch(switches::kPlaybackMode); 503 bool playback_mode = command_line.HasSwitch(switches::kPlaybackMode);
504 504
505 // Use a separate HTTP disk cache for isolated apps. 505 // Use a separate HTTP disk cache for isolated apps.
506 net::HttpCache::BackendFactory* app_backend = NULL; 506 net::HttpCache::BackendFactory* app_backend = NULL;
507 if (is_guest_process) { 507 if (partition_details.in_memory) {
508 app_backend = net::HttpCache::DefaultBackend::InMemory(0); 508 app_backend = net::HttpCache::DefaultBackend::InMemory(0);
509 } else { 509 } else {
510 app_backend = new net::HttpCache::DefaultBackend( 510 app_backend = new net::HttpCache::DefaultBackend(
511 net::DISK_CACHE, 511 net::DISK_CACHE,
512 cache_path, 512 cache_path,
513 app_cache_max_size_, 513 app_cache_max_size_,
514 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); 514 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE));
515 } 515 }
516 net::HttpNetworkSession* main_network_session = 516 net::HttpNetworkSession* main_network_session =
517 main_http_factory_->GetSession(); 517 main_http_factory_->GetSession();
518 net::HttpCache* app_http_cache = 518 net::HttpCache* app_http_cache =
519 new net::HttpCache(main_network_session, app_backend); 519 new net::HttpCache(main_network_session, app_backend);
520 520
521 scoped_refptr<net::CookieStore> cookie_store = NULL; 521 scoped_refptr<net::CookieStore> cookie_store = NULL;
522 if (is_guest_process) { 522 if (partition_details.in_memory) {
523 cookie_store = new net::CookieMonster(NULL, NULL); 523 cookie_store = new net::CookieMonster(NULL, NULL);
524 } else if (record_mode || playback_mode) { 524 } else if (record_mode || playback_mode) {
525 // Don't use existing cookies and use an in-memory store. 525 // Don't use existing cookies and use an in-memory store.
526 // TODO(creis): We should have a cookie delegate for notifying the cookie 526 // TODO(creis): We should have a cookie delegate for notifying the cookie
527 // extensions API, but we need to update it to understand isolated apps 527 // extensions API, but we need to update it to understand isolated apps
528 // first. 528 // first.
529 cookie_store = new net::CookieMonster(NULL, NULL); 529 cookie_store = new net::CookieMonster(NULL, NULL);
530 app_http_cache->set_mode( 530 app_http_cache->set_mode(
531 record_mode ? net::HttpCache::RECORD : net::HttpCache::PLAYBACK); 531 record_mode ? net::HttpCache::RECORD : net::HttpCache::PLAYBACK);
532 } 532 }
(...skipping 24 matching lines...) Expand all
557 context->ftp_transaction_factory(), 557 context->ftp_transaction_factory(),
558 context->ftp_auth_cache()); 558 context->ftp_auth_cache());
559 context->SetJobFactory(job_factory.Pass()); 559 context->SetJobFactory(job_factory.Pass());
560 560
561 return context; 561 return context;
562 } 562 }
563 563
564 ChromeURLRequestContext* 564 ChromeURLRequestContext*
565 ProfileImplIOData::InitializeMediaRequestContext( 565 ProfileImplIOData::InitializeMediaRequestContext(
566 ChromeURLRequestContext* original_context, 566 ChromeURLRequestContext* original_context,
567 const std::string& app_id) const { 567 const StoragePartitionDetails& partition_details) const {
568 // If this is for a guest process, we do not persist storage, so we can 568 // If this is for a in_memory partition, we can simply use the original
569 // simply use the app's in-memory cache (like off-the-record mode). 569 // context (like off-the-record mode).
570 if (app_id.find("guest-") != std::string::npos) 570 if (partition_details.in_memory)
571 return original_context; 571 return original_context;
572 572
573 // Copy most state from the original context. 573 // Copy most state from the original context.
574 MediaRequestContext* context = new MediaRequestContext(load_time_stats()); 574 MediaRequestContext* context = new MediaRequestContext(load_time_stats());
575 context->CopyFrom(original_context); 575 context->CopyFrom(original_context);
576 576
577 using content::StoragePartition; 577 using content::StoragePartition;
578 FilePath app_path =
579 profile_path_.Append(StoragePartition::GetPartitionPath(app_id));
580 FilePath cache_path; 578 FilePath cache_path;
581 int cache_max_size = app_media_cache_max_size_; 579 int cache_max_size = app_media_cache_max_size_;
582 if (app_id.empty()) { 580 if (partition_details.path == profile_path_) {
583 // lazy_params_ is only valid for the default media context creation. 581 // lazy_params_ is only valid for the default media context creation.
584 cache_path = lazy_params_->media_cache_path; 582 cache_path = lazy_params_->media_cache_path;
585 cache_max_size = lazy_params_->media_cache_max_size; 583 cache_max_size = lazy_params_->media_cache_max_size;
586 } else { 584 } else {
587 cache_path = app_path.Append(chrome::kMediaCacheDirname); 585 cache_path = partition_details.path.Append(chrome::kMediaCacheDirname);
588 } 586 }
589 587
590 // Use a separate HTTP disk cache for isolated apps. 588 // Use a separate HTTP disk cache for isolated apps.
591 net::HttpCache::BackendFactory* media_backend = 589 net::HttpCache::BackendFactory* media_backend =
592 new net::HttpCache::DefaultBackend( 590 new net::HttpCache::DefaultBackend(
593 net::MEDIA_CACHE, 591 net::MEDIA_CACHE,
594 cache_path, 592 cache_path,
595 cache_max_size, 593 cache_max_size,
596 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); 594 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE));
597 net::HttpNetworkSession* main_network_session = 595 net::HttpNetworkSession* main_network_session =
(...skipping 15 matching lines...) Expand all
613 611
614 ChromeURLRequestContext* 612 ChromeURLRequestContext*
615 ProfileImplIOData::AcquireMediaRequestContext() const { 613 ProfileImplIOData::AcquireMediaRequestContext() const {
616 DCHECK(media_request_context_.get()); 614 DCHECK(media_request_context_.get());
617 return media_request_context_.get(); 615 return media_request_context_.get();
618 } 616 }
619 617
620 ChromeURLRequestContext* 618 ChromeURLRequestContext*
621 ProfileImplIOData::AcquireIsolatedAppRequestContext( 619 ProfileImplIOData::AcquireIsolatedAppRequestContext(
622 ChromeURLRequestContext* main_context, 620 ChromeURLRequestContext* main_context,
623 const std::string& app_id, 621 const StoragePartitionDetails& partition_details,
624 scoped_ptr<net::URLRequestJobFactory::Interceptor> 622 scoped_ptr<net::URLRequestJobFactory::Interceptor>
625 protocol_handler_interceptor) const { 623 protocol_handler_interceptor) const {
626 // We create per-app contexts on demand, unlike the others above. 624 // We create per-app contexts on demand, unlike the others above.
627 ChromeURLRequestContext* app_request_context = 625 ChromeURLRequestContext* app_request_context =
628 InitializeAppRequestContext(main_context, app_id, 626 InitializeAppRequestContext(main_context, partition_details,
629 protocol_handler_interceptor.Pass()); 627 protocol_handler_interceptor.Pass());
630 DCHECK(app_request_context); 628 DCHECK(app_request_context);
631 return app_request_context; 629 return app_request_context;
632 } 630 }
633 631
634 ChromeURLRequestContext* 632 ChromeURLRequestContext*
635 ProfileImplIOData::AcquireIsolatedMediaRequestContext( 633 ProfileImplIOData::AcquireIsolatedMediaRequestContext(
636 ChromeURLRequestContext* app_context, 634 ChromeURLRequestContext* app_context,
637 const std::string& app_id) const { 635 const StoragePartitionDetails& partition_details) const {
638 // We create per-app media contexts on demand, unlike the others above. 636 // We create per-app media contexts on demand, unlike the others above.
639 ChromeURLRequestContext* media_request_context = 637 ChromeURLRequestContext* media_request_context =
640 InitializeMediaRequestContext(app_context, app_id); 638 InitializeMediaRequestContext(app_context, partition_details);
641 DCHECK(media_request_context); 639 DCHECK(media_request_context);
642 return media_request_context; 640 return media_request_context;
643 } 641 }
644 642
645 chrome_browser_net::LoadTimeStats* ProfileImplIOData::GetLoadTimeStats( 643 chrome_browser_net::LoadTimeStats* ProfileImplIOData::GetLoadTimeStats(
646 IOThread::Globals* io_thread_globals) const { 644 IOThread::Globals* io_thread_globals) const {
647 return io_thread_globals->load_time_stats.get(); 645 return io_thread_globals->load_time_stats.get();
648 } 646 }
649 647
650 void ProfileImplIOData::SetUpJobFactory( 648 void ProfileImplIOData::SetUpJobFactory(
(...skipping 14 matching lines...) Expand all
665 void ProfileImplIOData::ClearNetworkingHistorySinceOnIOThread( 663 void ProfileImplIOData::ClearNetworkingHistorySinceOnIOThread(
666 base::Time time) { 664 base::Time time) {
667 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 665 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
668 LazyInitialize(); 666 LazyInitialize();
669 667
670 DCHECK(transport_security_state()); 668 DCHECK(transport_security_state());
671 transport_security_state()->DeleteSince(time); 669 transport_security_state()->DeleteSince(time);
672 DCHECK(http_server_properties_manager()); 670 DCHECK(http_server_properties_manager());
673 http_server_properties_manager()->Clear(); 671 http_server_properties_manager()->Clear();
674 } 672 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698