diff options
author | hclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-02 22:53:18 +0000 |
---|---|---|
committer | hclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-02 22:53:18 +0000 |
commit | e7f2964e84ca06d711d33723e7725d03ee2aa136 (patch) | |
tree | e2cc8f033863a972998fdd668dd698d222bea3aa /chrome/browser/net/chrome_url_request_context.cc | |
parent | e9e6b1c6d3870e9a1e9a8aa7e6c454cdcd354d0f (diff) | |
download | chromium_src-e7f2964e84ca06d711d33723e7725d03ee2aa136.zip chromium_src-e7f2964e84ca06d711d33723e7725d03ee2aa136.tar.gz chromium_src-e7f2964e84ca06d711d33723e7725d03ee2aa136.tar.bz2 |
Proposed change to support resource loading for media files.
Highlights of changes:
- Added methods to disk_cache::Entry:
- Entry::PrepareTargetAsExternalFile(int index)
Prepare a stream in an entry to use external file for storage.
- Entry::GetExternalFile(int index)
Get the external file backing the stream in the entry.
- Added a property "CacheType type_" to HttpCache, along with setter and getter.
There shall be two cache types, COMMON_CACHE and MEDIA_CACHE for distinguishing between different purpose of HttpCache. We have this property to trigger special behavior for caching needs of media files.
- Added static methods to ChromeURLRequestContext
- ChromeURLRequestContext::CreateOriginalForMedia
Create a URLRequestContext for media files for the original profile.
- ChromeURLRequestContext::CreateOffTheRecordForMedia
Create a URLRequestContext for media files for off the record profile.
- Added method to Profile interface.
- GetRequestContextForMedia
To get the request context for media files from the context.
Design decissions:
- Enforce writing to external file by calling methods to Entry rather than construct Backend by a different flag.
Since we only want a valid and full response to go into an external file rather than redirection response or erroneous response, we should let HttpCache::Transaction to decide when to have an external file for response data. We eliminate a lot of useless external cache files.
- Adding the CacheType enum and property to HttpCache, we could allow possible (?) future extensions to HttpCache to handle other different caching needs. And there's no need to add change constructors of HttpCache, but maybe we should add a specific constructor to accomodate a media HttpCache?
- Adding Profile::GetRequestContextForMedia()
Since we will need to use this new request context in ResourceDispatcherHost, I think the best place to keep it is in the profile. Also we will expose to user that there's a separate cache for media, so it's better to expose it in the Profile level to allow settings to the media cache, e.g. max file size, etc.
Review URL: http://codereview.chromium.org/19747
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10745 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/net/chrome_url_request_context.cc')
-rw-r--r-- | chrome/browser/net/chrome_url_request_context.cc | 50 |
1 files changed, 50 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()) { |