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

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

Issue 6201005: Initial support for partitioning cookies for isolated apps. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update cookie logic in test. Created 9 years, 11 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) 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
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++) {
willchan no longer on Chromium 2011/01/26 23:21:52 http://www.corp.google.com/eng/doc/cppguide.xml?ex
Charlie Reis 2011/03/01 21:33:11 Done.
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
719 // net::URLRequestContext is constructed by the IO thread... 727 // net::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)
Matt Perry 2011/01/26 20:09:23 chrome style is: (HasSwitch() && app && ap
Charlie Reis 2011/03/01 21:33:11 Done.
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
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 cookie_path = cookie_path.Append(installed_app->id() +
804 chrome::kAppCookiesFileExtension);
805
806 ChromeURLRequestContextGetter* context =
807 ChromeURLRequestContextGetter::CreateOriginalForIsolatedApp(
808 this, installed_app, cookie_path);
809 app_request_context_map_[id] = context;
810
811 return context;
812 }
813
766 void ProfileImpl::RegisterExtensionWithRequestContexts( 814 void ProfileImpl::RegisterExtensionWithRequestContexts(
767 const Extension* extension) { 815 const Extension* extension) {
768 // AddRef to ensure the data lives until the other thread gets it. Balanced in 816 // AddRef to ensure the data lives until the other thread gets it. Balanced in
769 // OnNewExtensions. 817 // OnNewExtensions.
770 extension->AddRef(); 818 extension->AddRef();
771 BrowserThread::PostTask( 819 BrowserThread::PostTask(
772 BrowserThread::IO, FROM_HERE, 820 BrowserThread::IO, FROM_HERE,
773 NewRunnableMethod(extension_info_map_.get(), 821 NewRunnableMethod(extension_info_map_.get(),
774 &ExtensionInfoMap::AddExtension, 822 &ExtensionInfoMap::AddExtension,
775 extension)); 823 extension));
(...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after
1389 } 1437 }
1390 1438
1391 PrerenderManager* ProfileImpl::GetPrerenderManager() { 1439 PrerenderManager* ProfileImpl::GetPrerenderManager() {
1392 CommandLine* cl = CommandLine::ForCurrentProcess(); 1440 CommandLine* cl = CommandLine::ForCurrentProcess();
1393 if (!cl->HasSwitch(switches::kEnablePagePrerender)) 1441 if (!cl->HasSwitch(switches::kEnablePagePrerender))
1394 return NULL; 1442 return NULL;
1395 if (!prerender_manager_) 1443 if (!prerender_manager_)
1396 prerender_manager_ = new PrerenderManager(this); 1444 prerender_manager_ = new PrerenderManager(this);
1397 return prerender_manager_; 1445 return prerender_manager_;
1398 } 1446 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698