Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 | |
|
Charlie Reis
2012/10/30 17:47:48
nit: expect an
Can we just put the check in rathe
nasko
2012/10/30 19:55:25
Your assumption is correct and that will be the ch
Charlie Reis
2012/10/30 20:13:07
Ah, ok.
| |
| 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 Loading... | |
| 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 24 matching lines...) Expand all Loading... | |
| 563 context->ftp_transaction_factory(), | 569 context->ftp_transaction_factory(), |
| 564 context->ftp_auth_cache()); | 570 context->ftp_auth_cache()); |
| 565 context->SetJobFactory(job_factory.PassAs<net::URLRequestJobFactory>()); | 571 context->SetJobFactory(job_factory.PassAs<net::URLRequestJobFactory>()); |
| 566 | 572 |
| 567 return context; | 573 return context; |
| 568 } | 574 } |
| 569 | 575 |
| 570 ChromeURLRequestContext* | 576 ChromeURLRequestContext* |
| 571 ProfileImplIOData::InitializeMediaRequestContext( | 577 ProfileImplIOData::InitializeMediaRequestContext( |
| 572 ChromeURLRequestContext* original_context, | 578 ChromeURLRequestContext* original_context, |
| 573 const std::string& app_id) const { | 579 const StoragePartitionDescriptor& partition_descriptor) const { |
| 574 // If this is for a guest process, we do not persist storage, so we can | 580 // If this is for a in_memory partition, we can simply use the original |
| 575 // simply use the app's in-memory cache (like off-the-record mode). | 581 // context (like off-the-record mode). |
| 576 if (app_id.find("guest-") != std::string::npos) | 582 if (partition_descriptor.in_memory) |
| 577 return original_context; | 583 return original_context; |
| 578 | 584 |
| 579 // Copy most state from the original context. | 585 // Copy most state from the original context. |
| 580 MediaRequestContext* context = new MediaRequestContext(load_time_stats()); | 586 MediaRequestContext* context = new MediaRequestContext(load_time_stats()); |
| 581 context->CopyFrom(original_context); | 587 context->CopyFrom(original_context); |
| 582 | 588 |
| 583 using content::StoragePartition; | 589 using content::StoragePartition; |
| 584 FilePath app_path = | |
| 585 profile_path_.Append(StoragePartition::GetPartitionPath(app_id)); | |
| 586 FilePath cache_path; | 590 FilePath cache_path; |
| 587 int cache_max_size = app_media_cache_max_size_; | 591 int cache_max_size = app_media_cache_max_size_; |
| 588 if (app_id.empty()) { | 592 if (partition_descriptor.path == profile_path_) { |
| 589 // lazy_params_ is only valid for the default media context creation. | 593 // lazy_params_ is only valid for the default media context creation. |
| 590 cache_path = lazy_params_->media_cache_path; | 594 cache_path = lazy_params_->media_cache_path; |
| 591 cache_max_size = lazy_params_->media_cache_max_size; | 595 cache_max_size = lazy_params_->media_cache_max_size; |
| 592 } else { | 596 } else { |
| 593 cache_path = app_path.Append(chrome::kMediaCacheDirname); | 597 cache_path = partition_descriptor.path.Append(chrome::kMediaCacheDirname); |
| 594 } | 598 } |
| 595 | 599 |
| 596 // Use a separate HTTP disk cache for isolated apps. | 600 // Use a separate HTTP disk cache for isolated apps. |
| 597 net::HttpCache::BackendFactory* media_backend = | 601 net::HttpCache::BackendFactory* media_backend = |
| 598 new net::HttpCache::DefaultBackend( | 602 new net::HttpCache::DefaultBackend( |
| 599 net::MEDIA_CACHE, | 603 net::MEDIA_CACHE, |
| 600 cache_path, | 604 cache_path, |
| 601 cache_max_size, | 605 cache_max_size, |
| 602 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); | 606 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); |
| 603 net::HttpNetworkSession* main_network_session = | 607 net::HttpNetworkSession* main_network_session = |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 619 | 623 |
| 620 ChromeURLRequestContext* | 624 ChromeURLRequestContext* |
| 621 ProfileImplIOData::AcquireMediaRequestContext() const { | 625 ProfileImplIOData::AcquireMediaRequestContext() const { |
| 622 DCHECK(media_request_context_.get()); | 626 DCHECK(media_request_context_.get()); |
| 623 return media_request_context_.get(); | 627 return media_request_context_.get(); |
| 624 } | 628 } |
| 625 | 629 |
| 626 ChromeURLRequestContext* | 630 ChromeURLRequestContext* |
| 627 ProfileImplIOData::AcquireIsolatedAppRequestContext( | 631 ProfileImplIOData::AcquireIsolatedAppRequestContext( |
| 628 ChromeURLRequestContext* main_context, | 632 ChromeURLRequestContext* main_context, |
| 629 const std::string& app_id, | 633 const StoragePartitionDescriptor& partition_descriptor, |
| 630 scoped_ptr<net::URLRequestJobFactory::Interceptor> | 634 scoped_ptr<net::URLRequestJobFactory::Interceptor> |
| 631 protocol_handler_interceptor) const { | 635 protocol_handler_interceptor) const { |
| 632 // We create per-app contexts on demand, unlike the others above. | 636 // We create per-app contexts on demand, unlike the others above. |
| 633 ChromeURLRequestContext* app_request_context = | 637 ChromeURLRequestContext* app_request_context = |
| 634 InitializeAppRequestContext(main_context, app_id, | 638 InitializeAppRequestContext(main_context, partition_descriptor, |
| 635 protocol_handler_interceptor.Pass()); | 639 protocol_handler_interceptor.Pass()); |
| 636 DCHECK(app_request_context); | 640 DCHECK(app_request_context); |
| 637 return app_request_context; | 641 return app_request_context; |
| 638 } | 642 } |
| 639 | 643 |
| 640 ChromeURLRequestContext* | 644 ChromeURLRequestContext* |
| 641 ProfileImplIOData::AcquireIsolatedMediaRequestContext( | 645 ProfileImplIOData::AcquireIsolatedMediaRequestContext( |
| 642 ChromeURLRequestContext* app_context, | 646 ChromeURLRequestContext* app_context, |
| 643 const std::string& app_id) const { | 647 const StoragePartitionDescriptor& partition_descriptor) const { |
| 644 // We create per-app media contexts on demand, unlike the others above. | 648 // We create per-app media contexts on demand, unlike the others above. |
| 645 ChromeURLRequestContext* media_request_context = | 649 ChromeURLRequestContext* media_request_context = |
| 646 InitializeMediaRequestContext(app_context, app_id); | 650 InitializeMediaRequestContext(app_context, partition_descriptor); |
| 647 DCHECK(media_request_context); | 651 DCHECK(media_request_context); |
| 648 return media_request_context; | 652 return media_request_context; |
| 649 } | 653 } |
| 650 | 654 |
| 651 chrome_browser_net::LoadTimeStats* ProfileImplIOData::GetLoadTimeStats( | 655 chrome_browser_net::LoadTimeStats* ProfileImplIOData::GetLoadTimeStats( |
| 652 IOThread::Globals* io_thread_globals) const { | 656 IOThread::Globals* io_thread_globals) const { |
| 653 return io_thread_globals->load_time_stats.get(); | 657 return io_thread_globals->load_time_stats.get(); |
| 654 } | 658 } |
| 655 | 659 |
| 656 void ProfileImplIOData::SetUpJobFactory( | 660 void ProfileImplIOData::SetUpJobFactory( |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 671 void ProfileImplIOData::ClearNetworkingHistorySinceOnIOThread( | 675 void ProfileImplIOData::ClearNetworkingHistorySinceOnIOThread( |
| 672 base::Time time) { | 676 base::Time time) { |
| 673 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 677 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 674 LazyInitialize(); | 678 LazyInitialize(); |
| 675 | 679 |
| 676 DCHECK(transport_security_state()); | 680 DCHECK(transport_security_state()); |
| 677 transport_security_state()->DeleteSince(time); | 681 transport_security_state()->DeleteSince(time); |
| 678 DCHECK(http_server_properties_manager()); | 682 DCHECK(http_server_properties_manager()); |
| 679 http_server_properties_manager()->Clear(); | 683 http_server_properties_manager()->Clear(); |
| 680 } | 684 } |
| OLD | NEW |