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

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

Powered by Google App Engine
This is Rietveld 408576698