summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/net/chrome_url_request_context.cc16
-rw-r--r--chrome/browser/net/chrome_url_request_context.h6
-rw-r--r--chrome/browser/profile.cc64
-rw-r--r--chrome/common/chrome_switches.cc6
-rw-r--r--chrome/common/chrome_switches.h2
-rw-r--r--net/disk_cache/backend_impl.cc4
6 files changed, 70 insertions, 28 deletions
diff --git a/chrome/browser/net/chrome_url_request_context.cc b/chrome/browser/net/chrome_url_request_context.cc
index 1e01821..dda5449 100644
--- a/chrome/browser/net/chrome_url_request_context.cc
+++ b/chrome/browser/net/chrome_url_request_context.cc
@@ -108,7 +108,7 @@ static net::ProxyService* CreateProxyService(URLRequestContext* context,
// static
ChromeURLRequestContext* ChromeURLRequestContext::CreateOriginal(
Profile* profile, const FilePath& cookie_store_path,
- const FilePath& disk_cache_path) {
+ const FilePath& disk_cache_path, int cache_size) {
DCHECK(!profile->IsOffTheRecord());
ChromeURLRequestContext* context = new ChromeURLRequestContext(profile);
@@ -121,7 +121,7 @@ ChromeURLRequestContext* ChromeURLRequestContext::CreateOriginal(
net::HttpCache* cache =
new net::HttpCache(context->host_resolver_,
context->proxy_service_,
- disk_cache_path.ToWStringHack(), 0);
+ disk_cache_path.ToWStringHack(), cache_size);
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
bool record_mode = chrome::kRecordModeEnabled &&
@@ -161,9 +161,10 @@ ChromeURLRequestContext* ChromeURLRequestContext::CreateOriginal(
// static
ChromeURLRequestContext* ChromeURLRequestContext::CreateOriginalForMedia(
- Profile* profile, const FilePath& disk_cache_path) {
+ Profile* profile, const FilePath& disk_cache_path, int cache_size) {
DCHECK(!profile->IsOffTheRecord());
- return CreateRequestContextForMedia(profile, disk_cache_path, false);
+ return CreateRequestContextForMedia(profile, disk_cache_path, cache_size,
+ false);
}
// static
@@ -223,7 +224,8 @@ ChromeURLRequestContext::CreateOffTheRecordForExtensions(Profile* profile) {
// static
ChromeURLRequestContext* ChromeURLRequestContext::CreateRequestContextForMedia(
- Profile* profile, const FilePath& disk_cache_path, bool off_the_record) {
+ Profile* profile, const FilePath& disk_cache_path, int cache_size,
+ bool off_the_record) {
URLRequestContext* original_context =
profile->GetOriginalProfile()->GetRequestContext();
ChromeURLRequestContext* context = new ChromeURLRequestContext(profile);
@@ -248,13 +250,13 @@ ChromeURLRequestContext* ChromeURLRequestContext::CreateRequestContextForMedia(
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(), 0);
+ disk_cache_path.ToWStringHack(), cache_size);
} else {
// If original HttpCache doesn't exist, simply construct one with a whole
// new set of network stack.
cache = new net::HttpCache(original_context->host_resolver(),
original_context->proxy_service(),
- disk_cache_path.ToWStringHack(), 0);
+ disk_cache_path.ToWStringHack(), cache_size);
}
cache->set_type(net::MEDIA_CACHE);
diff --git a/chrome/browser/net/chrome_url_request_context.h b/chrome/browser/net/chrome_url_request_context.h
index 6e7d122..c709858 100644
--- a/chrome/browser/net/chrome_url_request_context.h
+++ b/chrome/browser/net/chrome_url_request_context.h
@@ -30,13 +30,13 @@ class ChromeURLRequestContext : public URLRequestContext,
// expected to get called on the UI thread.
static ChromeURLRequestContext* CreateOriginal(
Profile* profile, const FilePath& cookie_store_path,
- const FilePath& disk_cache_path);
+ const FilePath& disk_cache_path, int cache_size);
// 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);
+ const FilePath& disk_cache_path, int cache_size);
// Create an instance for an original profile for extensions. This is expected
// to get called on UI thread.
@@ -78,7 +78,7 @@ private:
// context. This helper method is called from CreateOriginalForMedia and
// CreateOffTheRecordForMedia.
static ChromeURLRequestContext* CreateRequestContextForMedia(Profile* profile,
- const FilePath& disk_cache_path, bool off_the_record);
+ const FilePath& disk_cache_path, int cache_size, bool off_the_record);
// NotificationObserver implementation.
virtual void Observe(NotificationType type,
diff --git a/chrome/browser/profile.cc b/chrome/browser/profile.cc
index 4c776f4..54ecdf2 100644
--- a/chrome/browser/profile.cc
+++ b/chrome/browser/profile.cc
@@ -48,9 +48,49 @@
using base::Time;
using base::TimeDelta;
+namespace {
+
// Delay, in milliseconds, before we explicitly create the SessionService.
static const int kCreateSessionServiceDelayMS = 500;
+enum ContextType {
+ kNormalContext,
+ kMediaContext
+};
+
+// Gets the cache parameters from the command line. |type| is the type of
+// request context that we need, |cache_path| will be set to the user provided
+// path, or will not be touched if there is not an argument. |max_size| will
+// be the user provided value or zero by default.
+void GetCacheParameters(ContextType type, FilePath* cache_path,
+ int* max_size) {
+ DCHECK(cache_path);
+ DCHECK(max_size);
+
+ // Override the cache location if specified by the user.
+ std::wstring user_path(CommandLine::ForCurrentProcess()->GetSwitchValue(
+ switches::kDiskCacheDir));
+
+ if (!user_path.empty()) {
+ *cache_path = FilePath::FromWStringHack(user_path);
+ }
+
+ const wchar_t* arg = kNormalContext == type ? switches::kDiskCacheSize :
+ switches::kMediaCacheSize;
+ std::string value =
+ WideToASCII(CommandLine::ForCurrentProcess()->GetSwitchValue(arg));
+
+ // By default we let the cache determine the right size.
+ *max_size = 0;
+ if (!StringToInt(value, max_size)) {
+ *max_size = 0;
+ } else if (max_size < 0) {
+ *max_size = 0;
+ }
+}
+
+} // namespace
+
// A pointer to the request context for the default profile. See comments on
// Profile::GetDefaultRequestContext.
URLRequestContext* Profile::default_request_context_;
@@ -717,18 +757,12 @@ URLRequestContext* ProfileImpl::GetRequestContext() {
FilePath cookie_path = GetPath();
cookie_path = cookie_path.Append(chrome::kCookieFilename);
FilePath cache_path = GetPath();
-
- // Override the cache location if specified by the user.
- const std::wstring user_cache_dir(
- CommandLine::ForCurrentProcess()->GetSwitchValue(
- switches::kDiskCacheDir));
- if (!user_cache_dir.empty()) {
- cache_path = FilePath::FromWStringHack(user_cache_dir);
- }
+ int max_size;
+ GetCacheParameters(kNormalContext, &cache_path, &max_size);
cache_path = cache_path.Append(chrome::kCacheDirname);
request_context_ = ChromeURLRequestContext::CreateOriginal(
- this, cookie_path, cache_path);
+ this, cookie_path, cache_path, max_size);
request_context_->AddRef();
// The first request context is always a normal (non-OTR) request context.
@@ -750,18 +784,12 @@ URLRequestContext* ProfileImpl::GetRequestContext() {
URLRequestContext* ProfileImpl::GetRequestContextForMedia() {
if (!media_request_context_) {
FilePath cache_path = GetPath();
-
- // Override the cache location if specified by the user.
- const std::wstring user_cache_dir(
- CommandLine::ForCurrentProcess()->GetSwitchValue(
- switches::kDiskCacheDir));
- if (!user_cache_dir.empty()) {
- cache_path = FilePath::FromWStringHack(user_cache_dir);
- }
+ int max_size;
+ GetCacheParameters(kMediaContext, &cache_path, &max_size);
cache_path = cache_path.Append(chrome::kMediaCacheDirname);
media_request_context_ = ChromeURLRequestContext::CreateOriginalForMedia(
- this, cache_path);
+ this, cache_path, max_size);
media_request_context_->AddRef();
DCHECK(media_request_context_->cookie_store());
diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc
index fb6eb3f..c3c2275 100644
--- a/chrome/common/chrome_switches.cc
+++ b/chrome/common/chrome_switches.cc
@@ -124,6 +124,12 @@ const wchar_t kPluginDataDir[] = L"plugin-data-dir";
// UserDatadir.
const wchar_t kDiskCacheDir[] = L"disk-cache-dir";
+// Forces the maximum disk space to be used by the disk cache, in bytes.
+const wchar_t kDiskCacheSize[] = L"disk-cache-size";
+
+// Forces the maximum disk space to be used by the media cache, in bytes.
+const wchar_t kMediaCacheSize[] = L"media-cache-size";
+
// Whether the multiple profiles feature based on the user-data-dir flag is
// enabled or not.
const wchar_t kEnableUserDataDirProfiles[] = L"enable-udd-profiles";
diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h
index 39defef..3946774 100644
--- a/chrome/common/chrome_switches.h
+++ b/chrome/common/chrome_switches.h
@@ -43,6 +43,8 @@ extern const wchar_t kTestSandbox[];
extern const wchar_t kUserDataDir[];
extern const wchar_t kPluginDataDir[];
extern const wchar_t kDiskCacheDir[];
+extern const wchar_t kDiskCacheSize[];
+extern const wchar_t kMediaCacheSize[];
extern const wchar_t kEnableUserDataDirProfiles[];
extern const wchar_t kParentProfile[];
extern const wchar_t kApp[];
diff --git a/net/disk_cache/backend_impl.cc b/net/disk_cache/backend_impl.cc
index d17b5e3..d41efe8 100644
--- a/net/disk_cache/backend_impl.cc
+++ b/net/disk_cache/backend_impl.cc
@@ -582,6 +582,10 @@ bool BackendImpl::SetMaxSize(int max_bytes) {
if (!max_bytes)
return true;
+ // Avoid a DCHECK later on.
+ if (max_bytes >= kint32max - kint32max / 10)
+ max_bytes = kint32max - kint32max / 10 - 1;
+
user_flags_ |= kMaxSize;
max_size_ = max_bytes;
return true;