diff options
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/net/chrome_url_request_context.cc | 50 | ||||
-rw-r--r-- | chrome/browser/net/chrome_url_request_context.h | 10 | ||||
-rw-r--r-- | chrome/browser/profile.cc | 31 | ||||
-rw-r--r-- | chrome/browser/profile.h | 7 |
4 files changed, 98 insertions, 0 deletions
diff --git a/chrome/browser/net/chrome_url_request_context.cc b/chrome/browser/net/chrome_url_request_context.cc index d98f2d6..748c497 100644 --- a/chrome/browser/net/chrome_url_request_context.cc +++ b/chrome/browser/net/chrome_url_request_context.cc @@ -16,6 +16,7 @@ #include "chrome/common/notification_service.h" #include "chrome/common/pref_names.h" #include "net/http/http_cache.h" +#include "net/http/http_network_layer.h" #include "net/http/http_util.h" #include "net/proxy/proxy_service.h" #include "webkit/glue/webkit_glue.h" @@ -76,6 +77,46 @@ ChromeURLRequestContext* ChromeURLRequestContext::CreateOriginal( } // static +ChromeURLRequestContext* ChromeURLRequestContext::CreateOriginalForMedia( + Profile* profile, const FilePath& disk_cache_path) { + DCHECK(!profile->IsOffTheRecord()); + URLRequestContext* original_context = + profile->GetOriginalProfile()->GetRequestContext(); + ChromeURLRequestContext* context = new ChromeURLRequestContext(profile); + // Share the same proxy service of the common profile. + context->proxy_service_ = original_context->proxy_service(); + // Also share the cookie store of the common profile. + context->cookie_store_ = original_context->cookie_store(); + + // Create a media cache with maximum size of kint32max (2GB). + // TODO(hclam): make the maximum size of media cache configurable. + net::HttpCache* original_cache = + original_context->http_transaction_factory()->GetCache(); + net::HttpCache* cache; + if (original_cache) { + // Try to reuse HttpNetworkSession in the original context, assuming that + // HttpTransactionFactory (network_layer()) of HttpCache is implemented + // by HttpNetworkLayer so we can reuse HttpNetworkSession within it. This + // assumption will be invalid if the original HttpCache is constructed with + // HttpCache(HttpTransactionFactory*, disk_cache::Backend*) constructor. + net::HttpNetworkLayer* original_network_layer = + static_cast<net::HttpNetworkLayer*>(original_cache->network_layer()); + cache = new net::HttpCache(original_network_layer->GetSession(), + disk_cache_path.ToWStringHack(), kint32max); + } else { + // If original HttpCache doesn't exist, simply construct one with a whole + // new set of network stack. + cache = new net::HttpCache(original_context->proxy_service(), + disk_cache_path.ToWStringHack(), kint32max); + } + // Set the cache type to media. + cache->set_type(net::HttpCache::MEDIA); + + context->http_transaction_factory_ = cache; + return context; +} + +// static ChromeURLRequestContext* ChromeURLRequestContext::CreateOffTheRecord( Profile* profile) { DCHECK(profile->IsOffTheRecord()); @@ -94,6 +135,15 @@ ChromeURLRequestContext* ChromeURLRequestContext::CreateOffTheRecord( return context; } +// static +ChromeURLRequestContext* ChromeURLRequestContext::CreateOffTheRecordForMedia( + Profile* profile, const FilePath& disk_cache_path) { + // TODO(hclam): since we don't have an implementation of disk cache backend + // for media files in OTR mode, we use the original context first. Change this + // to the proper backend later. + return CreateOriginalForMedia(profile, disk_cache_path); +} + ChromeURLRequestContext::ChromeURLRequestContext(Profile* profile) : prefs_(profile->GetPrefs()), is_off_the_record_(profile->IsOffTheRecord()) { diff --git a/chrome/browser/net/chrome_url_request_context.h b/chrome/browser/net/chrome_url_request_context.h index 15d53e8..df8cc9b 100644 --- a/chrome/browser/net/chrome_url_request_context.h +++ b/chrome/browser/net/chrome_url_request_context.h @@ -28,10 +28,20 @@ class ChromeURLRequestContext : public URLRequestContext, Profile* profile, const FilePath& cookie_store_path, const FilePath& disk_cache_path); + // Create an instance for an original profile for media. This is expected to + // get called on UI thread. This method takes a profile and reuses the + // 'original' URLRequestContext for common files. + static ChromeURLRequestContext* CreateOriginalForMedia(Profile *profile, + const FilePath& disk_cache_path); + // Create an instance for use with an OTR profile. This is expected to get // called on the UI thread. static ChromeURLRequestContext* CreateOffTheRecord(Profile* profile); + // Create an instance of request context for OTR profile for media resources. + static ChromeURLRequestContext* CreateOffTheRecordForMedia(Profile* profile, + const FilePath& disk_cache_path); + // Clean up UI thread resources. This is expected to get called on the UI // thread before the instance is deleted on the IO thread. void CleanupOnUIThread(); diff --git a/chrome/browser/profile.cc b/chrome/browser/profile.cc index 7c7041e..710949f 100644 --- a/chrome/browser/profile.cc +++ b/chrome/browser/profile.cc @@ -207,6 +207,20 @@ class OffTheRecordProfileImpl : public Profile, return request_context_; } + virtual URLRequestContext* GetRequestContextForMedia() { + if (!media_request_context_) { + FilePath cache_path = GetPath(); + cache_path.Append(chrome::kOffTheRecordMediaCacheDirname); + media_request_context_ = + ChromeURLRequestContext::CreateOffTheRecordForMedia( + this, cache_path); + media_request_context_->AddRef(); + + DCHECK(media_request_context_->cookie_store()); + } + return media_request_context_; + } + virtual SessionService* GetSessionService() { // Don't save any sessions when off the record. return NULL; @@ -311,6 +325,9 @@ class OffTheRecordProfileImpl : public Profile, // The context to use for requests made from this OTR session. ChromeURLRequestContext* request_context_; + // The context for requests for media resources. + ChromeURLRequestContext* media_request_context_; + // The download manager that only stores downloaded items in memory. scoped_refptr<DownloadManager> download_manager_; @@ -586,6 +603,20 @@ URLRequestContext* ProfileImpl::GetRequestContext() { return request_context_; } +URLRequestContext* ProfileImpl::GetRequestContextForMedia() { + if (!media_request_context_) { + FilePath cache_path = GetPath(); + cache_path.Append(chrome::kMediaCacheDirname); + media_request_context_ = ChromeURLRequestContext::CreateOriginalForMedia( + this, cache_path); + media_request_context_->AddRef(); + + DCHECK(media_request_context_->cookie_store()); + } + + return media_request_context_; +} + HistoryService* ProfileImpl::GetHistoryService(ServiceAccessType sat) { if (!history_service_created_) { history_service_created_ = true; diff --git a/chrome/browser/profile.h b/chrome/browser/profile.h index 8f513ae..8c93886 100644 --- a/chrome/browser/profile.h +++ b/chrome/browser/profile.h @@ -162,6 +162,10 @@ class Profile { // keep it alive longer than the profile) must Release() it on the I/O thread. virtual URLRequestContext* GetRequestContext() = 0; + // Returns the request context for media resources asociated with this + // profile. + virtual URLRequestContext* GetRequestContextForMedia() = 0; + // Returns the session service for this profile. This may return NULL. If // this profile supports a session service (it isn't off the record), and // the session service hasn't yet been created, this forces creation of @@ -277,6 +281,7 @@ class ProfileImpl : public Profile, virtual DownloadManager* GetDownloadManager(); virtual bool HasCreatedDownloadManager() const; virtual URLRequestContext* GetRequestContext(); + virtual URLRequestContext* GetRequestContextForMedia(); virtual SessionService* GetSessionService(); virtual void ShutdownSessionService(); virtual bool HasSessionService() const; @@ -342,6 +347,8 @@ class ProfileImpl : public Profile, ChromeURLRequestContext* request_context_; + ChromeURLRequestContext* media_request_context_; + scoped_refptr<DownloadManager> download_manager_; scoped_refptr<HistoryService> history_service_; scoped_refptr<WebDataService> web_data_service_; |