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

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: Missed a merging of removed variable. Created 8 years, 1 month 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): Check that the partition_path is not the same as the
215 // base profile path. We expect isolated partition, which will never go
216 // to the default profile path.
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 //
247 // TODO(nasko): Check that the partition_path is not the same as the
248 // base profile path. We expect isolated partition, which will never go
249 // to the default profile path.
240 LazyInitialize(); 250 LazyInitialize();
241 251
242 // Keep a map of request context getters, one per requested app ID. 252 // Keep a map of request context getters, one per requested storage partition.
253 StoragePartitionDescriptor descriptor(partition_path, in_memory);
243 ChromeURLRequestContextGetterMap::iterator iter = 254 ChromeURLRequestContextGetterMap::iterator iter =
244 isolated_media_request_context_getter_map_.find(app_id); 255 isolated_media_request_context_getter_map_.find(descriptor);
245 if (iter != isolated_media_request_context_getter_map_.end()) 256 if (iter != isolated_media_request_context_getter_map_.end())
246 return iter->second; 257 return iter->second;
247 258
248 // Get the app context as the starting point for the media context, so that 259 // Get the app context as the starting point for the media context, so that
249 // it uses the app's cookie store. 260 // it uses the app's cookie store.
250 ChromeURLRequestContextGetter* app_context = 261 ChromeURLRequestContextGetter* app_context =
251 GetIsolatedAppRequestContextGetter(app_id); 262 GetIsolatedAppRequestContextGetter(partition_path, in_memory);
252 ChromeURLRequestContextGetter* context = 263 ChromeURLRequestContextGetter* context =
253 ChromeURLRequestContextGetter::CreateOriginalForIsolatedMedia( 264 ChromeURLRequestContextGetter::CreateOriginalForIsolatedMedia(
254 profile_, app_context, io_data_, app_id); 265 profile_, app_context, io_data_, descriptor);
255 isolated_media_request_context_getter_map_[app_id] = context; 266 isolated_media_request_context_getter_map_[descriptor] = context;
256 267
257 return context; 268 return context;
258 } 269 }
259 270
260 void ProfileImplIOData::Handle::ClearNetworkingHistorySince( 271 void ProfileImplIOData::Handle::ClearNetworkingHistorySince(
261 base::Time time) { 272 base::Time time) {
262 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 273 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
263 LazyInitialize(); 274 LazyInitialize();
264 275
265 BrowserThread::PostTask( 276 BrowserThread::PostTask(
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 extensions_context->ftp_transaction_factory(), 478 extensions_context->ftp_transaction_factory(),
468 extensions_context->ftp_auth_cache()); 479 extensions_context->ftp_auth_cache());
469 480
470 main_job_factory_ = main_job_factory.Pass(); 481 main_job_factory_ = main_job_factory.Pass();
471 main_context->set_job_factory(main_job_factory_.get()); 482 main_context->set_job_factory(main_job_factory_.get());
472 extensions_job_factory_ = extensions_job_factory.Pass(); 483 extensions_job_factory_ = extensions_job_factory.Pass();
473 extensions_context->set_job_factory(extensions_job_factory_.get()); 484 extensions_context->set_job_factory(extensions_job_factory_.get());
474 485
475 // Create a media request context based on the main context, but using a 486 // Create a media request context based on the main context, but using a
476 // media cache. It shares the same job factory as the main context. 487 // media cache. It shares the same job factory as the main context.
477 media_request_context_.reset(InitializeMediaRequestContext(main_context, "")); 488 StoragePartitionDescriptor details(FilePath(), false);
489 media_request_context_.reset(InitializeMediaRequestContext(main_context,
490 details));
478 491
479 lazy_params_.reset(); 492 lazy_params_.reset();
480 } 493 }
481 494
482 ChromeURLRequestContext* 495 ChromeURLRequestContext*
483 ProfileImplIOData::InitializeAppRequestContext( 496 ProfileImplIOData::InitializeAppRequestContext(
484 ChromeURLRequestContext* main_context, 497 ChromeURLRequestContext* main_context,
485 const std::string& app_id, 498 const StoragePartitionDescriptor& partition_descriptor,
486 scoped_ptr<net::URLRequestJobFactory::Interceptor> 499 scoped_ptr<net::URLRequestJobFactory::Interceptor>
487 protocol_handler_interceptor) const { 500 protocol_handler_interceptor) const {
488 // If this is for a guest process, we should not persist cookies and http
489 // cache.
490 bool is_guest_process = (app_id.find("guest-") != std::string::npos);
491
492 // Copy most state from the main context. 501 // Copy most state from the main context.
493 AppRequestContext* context = new AppRequestContext(load_time_stats()); 502 AppRequestContext* context = new AppRequestContext(load_time_stats());
494 context->CopyFrom(main_context); 503 context->CopyFrom(main_context);
495 504
496 using content::StoragePartition; 505 FilePath cookie_path = partition_descriptor.path.Append(
497 FilePath app_path = 506 chrome::kCookieFilename);
498 profile_path_.Append(StoragePartition::GetPartitionPath(app_id)); 507 FilePath cache_path = partition_descriptor.path.Append(chrome::kCacheDirname);
499
500 FilePath cookie_path = app_path.Append(chrome::kCookieFilename);
501 FilePath cache_path = app_path.Append(chrome::kCacheDirname);
502 508
503 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 509 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
504 // Only allow Record Mode if we are in a Debug build or where we are running 510 // Only allow Record Mode if we are in a Debug build or where we are running
505 // a cycle, and the user has limited control. 511 // a cycle, and the user has limited control.
506 bool record_mode = command_line.HasSwitch(switches::kRecordMode) && 512 bool record_mode = command_line.HasSwitch(switches::kRecordMode) &&
507 (chrome::kRecordModeEnabled || 513 (chrome::kRecordModeEnabled ||
508 command_line.HasSwitch(switches::kVisitURLs)); 514 command_line.HasSwitch(switches::kVisitURLs));
509 bool playback_mode = command_line.HasSwitch(switches::kPlaybackMode); 515 bool playback_mode = command_line.HasSwitch(switches::kPlaybackMode);
510 516
511 // Use a separate HTTP disk cache for isolated apps. 517 // Use a separate HTTP disk cache for isolated apps.
512 net::HttpCache::BackendFactory* app_backend = NULL; 518 net::HttpCache::BackendFactory* app_backend = NULL;
513 if (is_guest_process) { 519 if (partition_descriptor.in_memory) {
514 app_backend = net::HttpCache::DefaultBackend::InMemory(0); 520 app_backend = net::HttpCache::DefaultBackend::InMemory(0);
515 } else { 521 } else {
516 app_backend = new net::HttpCache::DefaultBackend( 522 app_backend = new net::HttpCache::DefaultBackend(
517 net::DISK_CACHE, 523 net::DISK_CACHE,
518 cache_path, 524 cache_path,
519 app_cache_max_size_, 525 app_cache_max_size_,
520 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); 526 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE));
521 } 527 }
522 net::HttpNetworkSession* main_network_session = 528 net::HttpNetworkSession* main_network_session =
523 main_http_factory_->GetSession(); 529 main_http_factory_->GetSession();
524 net::HttpCache* app_http_cache = 530 net::HttpCache* app_http_cache =
525 new net::HttpCache(main_network_session, app_backend); 531 new net::HttpCache(main_network_session, app_backend);
526 532
527 scoped_refptr<net::CookieStore> cookie_store = NULL; 533 scoped_refptr<net::CookieStore> cookie_store = NULL;
528 if (is_guest_process) { 534 if (partition_descriptor.in_memory) {
529 cookie_store = new net::CookieMonster(NULL, NULL); 535 cookie_store = new net::CookieMonster(NULL, NULL);
530 } else if (record_mode || playback_mode) { 536 } else if (record_mode || playback_mode) {
531 // Don't use existing cookies and use an in-memory store. 537 // Don't use existing cookies and use an in-memory store.
532 // TODO(creis): We should have a cookie delegate for notifying the cookie 538 // TODO(creis): We should have a cookie delegate for notifying the cookie
533 // extensions API, but we need to update it to understand isolated apps 539 // extensions API, but we need to update it to understand isolated apps
534 // first. 540 // first.
535 cookie_store = new net::CookieMonster(NULL, NULL); 541 cookie_store = new net::CookieMonster(NULL, NULL);
536 app_http_cache->set_mode( 542 app_http_cache->set_mode(
537 record_mode ? net::HttpCache::RECORD : net::HttpCache::PLAYBACK); 543 record_mode ? net::HttpCache::RECORD : net::HttpCache::PLAYBACK);
538 } 544 }
(...skipping 14 matching lines...) Expand all
553 context->SetCookieStore(cookie_store); 559 context->SetCookieStore(cookie_store);
554 context->SetHttpTransactionFactory( 560 context->SetHttpTransactionFactory(
555 scoped_ptr<net::HttpTransactionFactory>(app_http_cache)); 561 scoped_ptr<net::HttpTransactionFactory>(app_http_cache));
556 562
557 // Overwrite the job factory that we inherit from the main context so 563 // Overwrite the job factory that we inherit from the main context so
558 // that we can later provide our own handles for storage related protocols. 564 // that we can later provide our own handles for storage related protocols.
559 // Install all the usual protocol handlers unless we are in a browser plugin 565 // Install all the usual protocol handlers unless we are in a browser plugin
560 // guest process, in which case only web-safe schemes are allowed. 566 // guest process, in which case only web-safe schemes are allowed.
561 scoped_ptr<net::URLRequestJobFactoryImpl> job_factory( 567 scoped_ptr<net::URLRequestJobFactoryImpl> job_factory(
562 new net::URLRequestJobFactoryImpl()); 568 new net::URLRequestJobFactoryImpl());
563 if (!is_guest_process) { 569 if (!partition_descriptor.in_memory) {
564 SetUpJobFactory(job_factory.get(), protocol_handler_interceptor.Pass(), 570 SetUpJobFactory(job_factory.get(), protocol_handler_interceptor.Pass(),
565 network_delegate(), 571 network_delegate(),
566 context->ftp_transaction_factory(), 572 context->ftp_transaction_factory(),
567 context->ftp_auth_cache()); 573 context->ftp_auth_cache());
568 } 574 }
569 context->SetJobFactory(job_factory.PassAs<net::URLRequestJobFactory>()); 575 context->SetJobFactory(job_factory.PassAs<net::URLRequestJobFactory>());
570 576
571 return context; 577 return context;
572 } 578 }
573 579
574 ChromeURLRequestContext* 580 ChromeURLRequestContext*
575 ProfileImplIOData::InitializeMediaRequestContext( 581 ProfileImplIOData::InitializeMediaRequestContext(
576 ChromeURLRequestContext* original_context, 582 ChromeURLRequestContext* original_context,
577 const std::string& app_id) const { 583 const StoragePartitionDescriptor& partition_descriptor) const {
578 // If this is for a guest process, we do not persist storage, so we can 584 // If this is for a in_memory partition, we can simply use the original
579 // simply use the app's in-memory cache (like off-the-record mode). 585 // context (like off-the-record mode).
580 if (app_id.find("guest-") != std::string::npos) 586 if (partition_descriptor.in_memory)
581 return original_context; 587 return original_context;
582 588
583 // Copy most state from the original context. 589 // Copy most state from the original context.
584 MediaRequestContext* context = new MediaRequestContext(load_time_stats()); 590 MediaRequestContext* context = new MediaRequestContext(load_time_stats());
585 context->CopyFrom(original_context); 591 context->CopyFrom(original_context);
586 592
587 using content::StoragePartition; 593 using content::StoragePartition;
588 FilePath app_path =
589 profile_path_.Append(StoragePartition::GetPartitionPath(app_id));
590 FilePath cache_path; 594 FilePath cache_path;
591 int cache_max_size = app_media_cache_max_size_; 595 int cache_max_size = app_media_cache_max_size_;
592 if (app_id.empty()) { 596 if (partition_descriptor.path == profile_path_) {
593 // lazy_params_ is only valid for the default media context creation. 597 // lazy_params_ is only valid for the default media context creation.
594 cache_path = lazy_params_->media_cache_path; 598 cache_path = lazy_params_->media_cache_path;
595 cache_max_size = lazy_params_->media_cache_max_size; 599 cache_max_size = lazy_params_->media_cache_max_size;
596 } else { 600 } else {
597 cache_path = app_path.Append(chrome::kMediaCacheDirname); 601 cache_path = partition_descriptor.path.Append(chrome::kMediaCacheDirname);
598 } 602 }
599 603
600 // Use a separate HTTP disk cache for isolated apps. 604 // Use a separate HTTP disk cache for isolated apps.
601 net::HttpCache::BackendFactory* media_backend = 605 net::HttpCache::BackendFactory* media_backend =
602 new net::HttpCache::DefaultBackend( 606 new net::HttpCache::DefaultBackend(
603 net::MEDIA_CACHE, 607 net::MEDIA_CACHE,
604 cache_path, 608 cache_path,
605 cache_max_size, 609 cache_max_size,
606 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); 610 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE));
607 net::HttpNetworkSession* main_network_session = 611 net::HttpNetworkSession* main_network_session =
(...skipping 15 matching lines...) Expand all
623 627
624 ChromeURLRequestContext* 628 ChromeURLRequestContext*
625 ProfileImplIOData::AcquireMediaRequestContext() const { 629 ProfileImplIOData::AcquireMediaRequestContext() const {
626 DCHECK(media_request_context_.get()); 630 DCHECK(media_request_context_.get());
627 return media_request_context_.get(); 631 return media_request_context_.get();
628 } 632 }
629 633
630 ChromeURLRequestContext* 634 ChromeURLRequestContext*
631 ProfileImplIOData::AcquireIsolatedAppRequestContext( 635 ProfileImplIOData::AcquireIsolatedAppRequestContext(
632 ChromeURLRequestContext* main_context, 636 ChromeURLRequestContext* main_context,
633 const std::string& app_id, 637 const StoragePartitionDescriptor& partition_descriptor,
634 scoped_ptr<net::URLRequestJobFactory::Interceptor> 638 scoped_ptr<net::URLRequestJobFactory::Interceptor>
635 protocol_handler_interceptor) const { 639 protocol_handler_interceptor) const {
636 // We create per-app contexts on demand, unlike the others above. 640 // We create per-app contexts on demand, unlike the others above.
637 ChromeURLRequestContext* app_request_context = 641 ChromeURLRequestContext* app_request_context =
638 InitializeAppRequestContext(main_context, app_id, 642 InitializeAppRequestContext(main_context, partition_descriptor,
639 protocol_handler_interceptor.Pass()); 643 protocol_handler_interceptor.Pass());
640 DCHECK(app_request_context); 644 DCHECK(app_request_context);
641 return app_request_context; 645 return app_request_context;
642 } 646 }
643 647
644 ChromeURLRequestContext* 648 ChromeURLRequestContext*
645 ProfileImplIOData::AcquireIsolatedMediaRequestContext( 649 ProfileImplIOData::AcquireIsolatedMediaRequestContext(
646 ChromeURLRequestContext* app_context, 650 ChromeURLRequestContext* app_context,
647 const std::string& app_id) const { 651 const StoragePartitionDescriptor& partition_descriptor) const {
648 // We create per-app media contexts on demand, unlike the others above. 652 // We create per-app media contexts on demand, unlike the others above.
649 ChromeURLRequestContext* media_request_context = 653 ChromeURLRequestContext* media_request_context =
650 InitializeMediaRequestContext(app_context, app_id); 654 InitializeMediaRequestContext(app_context, partition_descriptor);
651 DCHECK(media_request_context); 655 DCHECK(media_request_context);
652 return media_request_context; 656 return media_request_context;
653 } 657 }
654 658
655 chrome_browser_net::LoadTimeStats* ProfileImplIOData::GetLoadTimeStats( 659 chrome_browser_net::LoadTimeStats* ProfileImplIOData::GetLoadTimeStats(
656 IOThread::Globals* io_thread_globals) const { 660 IOThread::Globals* io_thread_globals) const {
657 return io_thread_globals->load_time_stats.get(); 661 return io_thread_globals->load_time_stats.get();
658 } 662 }
659 663
660 void ProfileImplIOData::SetUpJobFactory( 664 void ProfileImplIOData::SetUpJobFactory(
(...skipping 14 matching lines...) Expand all
675 void ProfileImplIOData::ClearNetworkingHistorySinceOnIOThread( 679 void ProfileImplIOData::ClearNetworkingHistorySinceOnIOThread(
676 base::Time time) { 680 base::Time time) {
677 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 681 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
678 LazyInitialize(); 682 LazyInitialize();
679 683
680 DCHECK(transport_security_state()); 684 DCHECK(transport_security_state());
681 transport_security_state()->DeleteSince(time); 685 transport_security_state()->DeleteSince(time);
682 DCHECK(http_server_properties_manager()); 686 DCHECK(http_server_properties_manager());
683 http_server_properties_manager()->Clear(); 687 http_server_properties_manager()->Clear();
684 } 688 }
OLDNEW
« no previous file with comments | « chrome/browser/profiles/profile_impl_io_data.h ('k') | chrome/browser/profiles/profile_io_data.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698