diff options
author | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-29 19:14:29 +0000 |
---|---|---|
committer | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-29 19:14:29 +0000 |
commit | e7b60a742d466731f93ace36be1de2ca966d4457 (patch) | |
tree | 013a8f0a8d586e2d151e127c280cb433a2f9d4ad | |
parent | 97e1958e5fdacf588ba0588729379749569d5ec1 (diff) | |
download | chromium_src-e7b60a742d466731f93ace36be1de2ca966d4457.zip chromium_src-e7b60a742d466731f93ace36be1de2ca966d4457.tar.gz chromium_src-e7b60a742d466731f93ace36be1de2ca966d4457.tar.bz2 |
Http cache: Add support for a dedicated cache thread.
This is an interface-only change, nothing is really moving to another thread yet.
BUG=26730
TEST=none
Review URL: http://codereview.chromium.org/983007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@45974 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/net/chrome_url_request_context.cc | 6 | ||||
-rw-r--r-- | net/disk_cache/backend_impl.cc | 4 | ||||
-rw-r--r-- | net/disk_cache/disk_cache.h | 19 | ||||
-rw-r--r-- | net/http/http_cache.cc | 11 | ||||
-rw-r--r-- | net/http/http_cache.h | 16 | ||||
-rw-r--r-- | webkit/appcache/appcache_disk_cache.cc | 4 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell_request_context.cc | 2 |
7 files changed, 45 insertions, 17 deletions
diff --git a/chrome/browser/net/chrome_url_request_context.cc b/chrome/browser/net/chrome_url_request_context.cc index 3a25f71..0dad578 100644 --- a/chrome/browser/net/chrome_url_request_context.cc +++ b/chrome/browser/net/chrome_url_request_context.cc @@ -252,7 +252,7 @@ ChromeURLRequestContext* FactoryForOriginal::Create() { context->proxy_service(), context->ssl_config_service(), context->http_auth_handler_factory(), - disk_cache_path_, cache_size_); + disk_cache_path_, NULL, cache_size_); if (command_line.HasSwitch(switches::kDisableByteRangeSupport)) cache->set_enable_range_support(false); @@ -451,7 +451,7 @@ ChromeURLRequestContext* FactoryForMedia::Create() { net::HttpNetworkLayer* main_network_layer = static_cast<net::HttpNetworkLayer*>(main_cache->network_layer()); cache = new net::HttpCache(main_network_layer->GetSession(), - disk_cache_path_, cache_size_); + disk_cache_path_, NULL, cache_size_); // TODO(eroman): Since this is poaching the session from the main // context, it should hold a reference to that context preventing the // session from getting deleted. @@ -464,7 +464,7 @@ ChromeURLRequestContext* FactoryForMedia::Create() { main_context->proxy_service(), main_context->ssl_config_service(), main_context->http_auth_handler_factory(), - disk_cache_path_, cache_size_); + disk_cache_path_, NULL, cache_size_); } if (CommandLine::ForCurrentProcess()->HasSwitch( diff --git a/net/disk_cache/backend_impl.cc b/net/disk_cache/backend_impl.cc index c094472..d45fb29 100644 --- a/net/disk_cache/backend_impl.cc +++ b/net/disk_cache/backend_impl.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -174,7 +174,7 @@ Backend* CreateCacheBackend(const FilePath& full_path, bool force, } int CreateCacheBackend(net::CacheType type, const FilePath& path, int max_bytes, - bool force, Backend** backend, + bool force, MessageLoop* thread, Backend** backend, CompletionCallback* callback) { if (type == net::MEMORY_CACHE) *backend = CreateInMemoryCacheBackend(max_bytes); diff --git a/net/disk_cache/disk_cache.h b/net/disk_cache/disk_cache.h index 3d2793b..c216ccb 100644 --- a/net/disk_cache/disk_cache.h +++ b/net/disk_cache/disk_cache.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -17,6 +17,7 @@ #include "net/base/completion_callback.h" class FilePath; +class MessageLoop; namespace net { class IOBuffer; @@ -56,14 +57,16 @@ Backend* CreateInMemoryCacheBackend(int max_bytes); // If |force| is true, and there is a problem with the cache initialization, the // files will be deleted and a new set will be created. |max_bytes| is the // maximum size the cache can grow to. If zero is passed in as |max_bytes|, the -// cache will determine the value to use. The returned pointer can be NULL if a -// fatal error is found. The actual return value of the function is a net error -// code. If this function returns ERR_IO_PENDING, the |callback| will be invoked -// when a backend is available or a fatal error condition is reached. The -// pointer to receive the |backend| must remain valid until the operation -// completes. +// cache will determine the value to use. |thread| can be used to perform IO +// operations if a dedicated thread is required; a valid value is expected for +// any backend that performs operations on a disk. The returned pointer can be +// NULL if a fatal error is found. The actual return value of the function is a +// net error code. If this function returns ERR_IO_PENDING, the |callback| will +// be invoked when a backend is available or a fatal error condition is reached. +// The pointer to receive the |backend| must remain valid until the operation +// completes (the callback is notified). int CreateCacheBackend(net::CacheType type, const FilePath& path, int max_bytes, - bool force, Backend** backend, + bool force, MessageLoop* thread, Backend** backend, CompletionCallback* callback); // The root interface for a disk cache instance. diff --git a/net/http/http_cache.cc b/net/http/http_cache.cc index 2cb4fa1..7c433a9 100644 --- a/net/http/http_cache.cc +++ b/net/http/http_cache.cc @@ -201,8 +201,10 @@ HttpCache::HttpCache(NetworkChangeNotifier* network_change_notifier, SSLConfigService* ssl_config_service, HttpAuthHandlerFactory* http_auth_handler_factory, const FilePath& cache_dir, + MessageLoop* cache_thread, int cache_size) : disk_cache_dir_(cache_dir), + cache_thread_(cache_thread), mode_(NORMAL), type_(DISK_CACHE), network_layer_(HttpNetworkLayer::CreateFactory( @@ -215,8 +217,10 @@ HttpCache::HttpCache(NetworkChangeNotifier* network_change_notifier, HttpCache::HttpCache(HttpNetworkSession* session, const FilePath& cache_dir, + MessageLoop* cache_thread, int cache_size) : disk_cache_dir_(cache_dir), + cache_thread_(cache_thread), mode_(NORMAL), type_(DISK_CACHE), network_layer_(HttpNetworkLayer::CreateFactory(session)), @@ -289,6 +293,13 @@ disk_cache::Backend* HttpCache::GetBackend() { return disk_cache_.get(); } +int HttpCache::GetBackend(disk_cache::Backend** backend, + CompletionCallback* callback) { + DCHECK(callback != NULL); + *backend = GetBackend(); + return OK; +} + int HttpCache::CreateTransaction(scoped_ptr<HttpTransaction>* trans) { // Do lazy initialization of disk cache if needed. GetBackend(); diff --git a/net/http/http_cache.h b/net/http/http_cache.h index 836bb52..15561fb 100644 --- a/net/http/http_cache.h +++ b/net/http/http_cache.h @@ -28,6 +28,7 @@ #include "net/http/http_transaction_factory.h" class GURL; +class MessageLoop; class ViewCacheHelper; namespace disk_cache { @@ -69,12 +70,14 @@ class HttpCache : public HttpTransactionFactory, // Initialize the cache from the directory where its data is stored. The // disk cache is initialized lazily (by CreateTransaction) in this case. If // |cache_size| is zero, a default value will be calculated automatically. + // The |cache_thread| is the thread where disk operations should take place. HttpCache(NetworkChangeNotifier* network_change_notifier, HostResolver* host_resolver, ProxyService* proxy_service, SSLConfigService* ssl_config_service, HttpAuthHandlerFactory* http_auth_handler_factory, const FilePath& cache_dir, + MessageLoop* cache_thread, int cache_size); // Initialize the cache from the directory where its data is stored. The @@ -83,8 +86,9 @@ class HttpCache : public HttpTransactionFactory, // Provide an existing HttpNetworkSession, the cache can construct a // network layer with a shared HttpNetworkSession in order for multiple // network layers to share information (e.g. authenication data). + // The |cache_thread| is the thread where disk operations should take place. HttpCache(HttpNetworkSession* session, const FilePath& cache_dir, - int cache_size); + MessageLoop* cache_thread, int cache_size); // Initialize using an in-memory cache. The cache is initialized lazily // (by CreateTransaction) in this case. If |cache_size| is zero, a default @@ -108,8 +112,16 @@ class HttpCache : public HttpTransactionFactory, // Returns the cache backend for this HttpCache instance. If the backend // is not initialized yet, this method will initialize it. If the return // value is NULL then the backend cannot be initialized. + // This method is deprecated. disk_cache::Backend* GetBackend(); + // Retrieves the cache backend for this HttpCache instance. If the backend + // is not initialized yet, this method will initialize it. The return value is + // a network error code, and it could be ERR_IO_PENDING, in which case the + // |callback| will be notified when the operation completes. The pointer that + // receives the |backend| must remain valid until the operation completes. + int GetBackend(disk_cache::Backend** backend, CompletionCallback* callback); + // HttpTransactionFactory implementation: virtual int CreateTransaction(scoped_ptr<HttpTransaction>* trans); virtual HttpCache* GetCache(); @@ -201,7 +213,6 @@ class HttpCache : public HttpTransactionFactory, typedef base::hash_map<std::string, NewEntry*> NewEntriesMap; typedef std::set<ActiveEntry*> ActiveEntriesSet; - // Methods ------------------------------------------------------------------ // Generates the cache key for this request. @@ -309,6 +320,7 @@ class HttpCache : public HttpTransactionFactory, // Used when lazily constructing the disk_cache_. FilePath disk_cache_dir_; + MessageLoop* cache_thread_; Mode mode_; CacheType type_; diff --git a/webkit/appcache/appcache_disk_cache.cc b/webkit/appcache/appcache_disk_cache.cc index b8b25bf..bdaadfe 100644 --- a/webkit/appcache/appcache_disk_cache.cc +++ b/webkit/appcache/appcache_disk_cache.cc @@ -104,8 +104,10 @@ int AppCacheDiskCache::Init(net::CacheType cache_type, is_disabled_ = false; create_backend_callback_ = new CreateBackendCallback( this, &AppCacheDiskCache::OnCreateBackendComplete); + + // TODO(michaeln): Pass a valid cache_thread here. int rv = disk_cache::CreateCacheBackend( - cache_type, cache_directory, cache_size, force, + cache_type, cache_directory, cache_size, force, NULL, &(create_backend_callback_->backend_ptr_), create_backend_callback_); if (rv == net::ERR_IO_PENDING) init_callback_ = callback; diff --git a/webkit/tools/test_shell/test_shell_request_context.cc b/webkit/tools/test_shell/test_shell_request_context.cc index 61a5504..66f3b17 100644 --- a/webkit/tools/test_shell/test_shell_request_context.cc +++ b/webkit/tools/test_shell/test_shell_request_context.cc @@ -71,7 +71,7 @@ void TestShellRequestContext::Init( } else { cache = new net::HttpCache(NULL, host_resolver_, proxy_service_, ssl_config_service_, http_auth_handler_factory_, - cache_path, 0); + cache_path, NULL, 0); } cache->set_mode(cache_mode); http_transaction_factory_ = cache; |