summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorhclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-02 22:53:18 +0000
committerhclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-02 22:53:18 +0000
commite7f2964e84ca06d711d33723e7725d03ee2aa136 (patch)
treee2cc8f033863a972998fdd668dd698d222bea3aa /chrome/browser
parente9e6b1c6d3870e9a1e9a8aa7e6c454cdcd354d0f (diff)
downloadchromium_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')
-rw-r--r--chrome/browser/net/chrome_url_request_context.cc50
-rw-r--r--chrome/browser/net/chrome_url_request_context.h10
-rw-r--r--chrome/browser/profile.cc31
-rw-r--r--chrome/browser/profile.h7
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_;