OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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.h" | 5 #include "chrome/browser/profiles/profile_impl.h" |
6 | 6 |
7 #include "app/resource_bundle.h" | 7 #include "app/resource_bundle.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/environment.h" | 9 #include "base/environment.h" |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 if (spellcheck_host_.get()) | 498 if (spellcheck_host_.get()) |
499 spellcheck_host_->UnsetObserver(); | 499 spellcheck_host_->UnsetObserver(); |
500 | 500 |
501 if (default_request_context_ == request_context_) | 501 if (default_request_context_ == request_context_) |
502 default_request_context_ = NULL; | 502 default_request_context_ = NULL; |
503 | 503 |
504 CleanupRequestContext(request_context_); | 504 CleanupRequestContext(request_context_); |
505 CleanupRequestContext(media_request_context_); | 505 CleanupRequestContext(media_request_context_); |
506 CleanupRequestContext(extensions_request_context_); | 506 CleanupRequestContext(extensions_request_context_); |
507 | 507 |
| 508 // Clean up all isolated app request contexts. |
| 509 for (ChromeURLRequestContextGetterMap::iterator iter = |
| 510 app_request_context_map_.begin(); |
| 511 iter != app_request_context_map_.end(); |
| 512 iter++) { |
| 513 CleanupRequestContext(iter->second); |
| 514 } |
| 515 |
508 // HistoryService may call into the BookmarkModel, as such we need to | 516 // HistoryService may call into the BookmarkModel, as such we need to |
509 // delete HistoryService before the BookmarkModel. The destructor for | 517 // delete HistoryService before the BookmarkModel. The destructor for |
510 // HistoryService will join with HistoryService's backend thread so that | 518 // HistoryService will join with HistoryService's backend thread so that |
511 // by the time the destructor has finished we're sure it will no longer call | 519 // by the time the destructor has finished we're sure it will no longer call |
512 // into the BookmarkModel. | 520 // into the BookmarkModel. |
513 history_service_ = NULL; | 521 history_service_ = NULL; |
514 bookmark_bar_model_.reset(); | 522 bookmark_bar_model_.reset(); |
515 | 523 |
516 // FaviconService depends on HistoryServce so make sure we delete | 524 // FaviconService depends on HistoryServce so make sure we delete |
517 // HistoryService first. | 525 // HistoryService first. |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
719 // URLRequestContext is constructed by the IO thread... | 727 // URLRequestContext is constructed by the IO thread... |
720 NotificationService::current()->Notify( | 728 NotificationService::current()->Notify( |
721 NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE, | 729 NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE, |
722 NotificationService::AllSources(), NotificationService::NoDetails()); | 730 NotificationService::AllSources(), NotificationService::NoDetails()); |
723 } | 731 } |
724 } | 732 } |
725 | 733 |
726 return request_context_; | 734 return request_context_; |
727 } | 735 } |
728 | 736 |
| 737 URLRequestContextGetter* ProfileImpl::GetRequestContext(const Extension* app) { |
| 738 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 739 switches::kEnableExperimentalAppManifests) |
| 740 && app != NULL |
| 741 && app->is_storage_isolated()) |
| 742 return GetRequestContextForIsolatedApp(app); |
| 743 |
| 744 return GetRequestContext(); |
| 745 } |
| 746 |
729 URLRequestContextGetter* ProfileImpl::GetRequestContextForMedia() { | 747 URLRequestContextGetter* ProfileImpl::GetRequestContextForMedia() { |
730 if (!media_request_context_) { | 748 if (!media_request_context_) { |
731 FilePath cache_path = base_cache_path_; | 749 FilePath cache_path = base_cache_path_; |
732 int max_size; | 750 int max_size; |
733 GetCacheParameters(kMediaContext, &cache_path, &max_size); | 751 GetCacheParameters(kMediaContext, &cache_path, &max_size); |
734 | 752 |
735 cache_path = GetMediaCachePath(cache_path); | 753 cache_path = GetMediaCachePath(cache_path); |
736 media_request_context_ = | 754 media_request_context_ = |
737 ChromeURLRequestContextGetter::CreateOriginalForMedia( | 755 ChromeURLRequestContextGetter::CreateOriginalForMedia( |
738 this, cache_path, max_size); | 756 this, cache_path, max_size); |
(...skipping 17 matching lines...) Expand all Loading... |
756 cookie_path = cookie_path.Append(chrome::kExtensionsCookieFilename); | 774 cookie_path = cookie_path.Append(chrome::kExtensionsCookieFilename); |
757 | 775 |
758 extensions_request_context_ = | 776 extensions_request_context_ = |
759 ChromeURLRequestContextGetter::CreateOriginalForExtensions( | 777 ChromeURLRequestContextGetter::CreateOriginalForExtensions( |
760 this, cookie_path); | 778 this, cookie_path); |
761 } | 779 } |
762 | 780 |
763 return extensions_request_context_; | 781 return extensions_request_context_; |
764 } | 782 } |
765 | 783 |
| 784 URLRequestContextGetter* ProfileImpl::GetRequestContextForIsolatedApp( |
| 785 const Extension* installed_app) { |
| 786 CHECK(installed_app); |
| 787 std::string id = installed_app->id(); |
| 788 |
| 789 // Keep a map of request contexts, one per requested app ID. Once created, |
| 790 // the context will exist for the lifetime of the profile. |
| 791 ChromeURLRequestContextGetterMap::iterator iter = |
| 792 app_request_context_map_.find(id); |
| 793 if (iter != app_request_context_map_.end()) |
| 794 return iter->second; |
| 795 |
| 796 // Have to create a new context for this app. |
| 797 FilePath cookie_path = GetPath(); |
| 798 cookie_path = cookie_path.Append(chrome::kAppStorageDirname); |
| 799 |
| 800 // Create the directory if it doesn't yet exist. |
| 801 if (!file_util::DirectoryExists(cookie_path)) |
| 802 file_util::CreateDirectory(cookie_path); |
| 803 |
| 804 cookie_path = cookie_path.Append(installed_app->id() + |
| 805 chrome::kAppCookiesFileExtension); |
| 806 |
| 807 ChromeURLRequestContextGetter* context = |
| 808 ChromeURLRequestContextGetter::CreateOriginalForIsolatedApp( |
| 809 this, installed_app, cookie_path); |
| 810 app_request_context_map_[id] = context; |
| 811 |
| 812 return context; |
| 813 } |
| 814 |
766 void ProfileImpl::RegisterExtensionWithRequestContexts( | 815 void ProfileImpl::RegisterExtensionWithRequestContexts( |
767 const Extension* extension) { | 816 const Extension* extension) { |
768 // AddRef to ensure the data lives until the other thread gets it. Balanced in | 817 // AddRef to ensure the data lives until the other thread gets it. Balanced in |
769 // OnNewExtensions. | 818 // OnNewExtensions. |
770 extension->AddRef(); | 819 extension->AddRef(); |
771 BrowserThread::PostTask( | 820 BrowserThread::PostTask( |
772 BrowserThread::IO, FROM_HERE, | 821 BrowserThread::IO, FROM_HERE, |
773 NewRunnableMethod(extension_info_map_.get(), | 822 NewRunnableMethod(extension_info_map_.get(), |
774 &ExtensionInfoMap::AddExtension, | 823 &ExtensionInfoMap::AddExtension, |
775 extension)); | 824 extension)); |
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1364 } | 1413 } |
1365 | 1414 |
1366 PrerenderManager* ProfileImpl::GetPrerenderManager() { | 1415 PrerenderManager* ProfileImpl::GetPrerenderManager() { |
1367 CommandLine* cl = CommandLine::ForCurrentProcess(); | 1416 CommandLine* cl = CommandLine::ForCurrentProcess(); |
1368 if (!cl->HasSwitch(switches::kEnablePagePrerender)) | 1417 if (!cl->HasSwitch(switches::kEnablePagePrerender)) |
1369 return NULL; | 1418 return NULL; |
1370 if (!prerender_manager_.get()) | 1419 if (!prerender_manager_.get()) |
1371 prerender_manager_.reset(new PrerenderManager(this)); | 1420 prerender_manager_.reset(new PrerenderManager(this)); |
1372 return prerender_manager_.get(); | 1421 return prerender_manager_.get(); |
1373 } | 1422 } |
OLD | NEW |