diff options
-rw-r--r-- | chrome/browser/browser_main.cc | 1 | ||||
-rw-r--r-- | chrome/browser/browser_process.h | 3 | ||||
-rw-r--r-- | chrome/browser/browser_process_impl.cc | 17 | ||||
-rw-r--r-- | chrome/browser/browser_process_impl.h | 11 | ||||
-rw-r--r-- | chrome/browser/chrome_thread.cc | 1 | ||||
-rw-r--r-- | chrome/browser/chrome_thread.h | 3 | ||||
-rw-r--r-- | chrome/browser/net/chrome_url_request_context.cc | 12 | ||||
-rw-r--r-- | chrome/test/testing_browser_process.h | 4 | ||||
-rw-r--r-- | net/disk_cache/backend_impl.cc | 4 | ||||
-rw-r--r-- | net/disk_cache/disk_cache.h | 9 | ||||
-rw-r--r-- | net/http/http_cache.h | 6 |
11 files changed, 57 insertions, 14 deletions
diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc index 75d74c4..c58fbd6 100644 --- a/chrome/browser/browser_main.cc +++ b/chrome/browser/browser_main.cc @@ -388,6 +388,7 @@ void CreateChildThreads(BrowserProcessImpl* process) { process->db_thread(); process->file_thread(); process->process_launcher_thread(); + process->cache_thread(); process->io_thread(); } diff --git a/chrome/browser/browser_process.h b/chrome/browser/browser_process.h index 91614b6..8e05348 100644 --- a/chrome/browser/browser_process.h +++ b/chrome/browser/browser_process.h @@ -94,6 +94,9 @@ class BrowserProcess { // database. History has its own thread since it has much higher traffic. virtual base::Thread* db_thread() = 0; + // Returns the thread that is used for background cache operations. + virtual base::Thread* cache_thread() = 0; + #if defined(USE_X11) // Returns the thread that is used to process UI requests in cases where // we can't route the request to the UI thread. Note that this thread diff --git a/chrome/browser/browser_process_impl.cc b/chrome/browser/browser_process_impl.cc index 9c118bb..f630571 100644 --- a/chrome/browser/browser_process_impl.cc +++ b/chrome/browser/browser_process_impl.cc @@ -78,6 +78,7 @@ BrowserProcessImpl::BrowserProcessImpl(const CommandLine& command_line) created_file_thread_(false), created_db_thread_(false), created_process_launcher_thread_(false), + created_cache_thread_(false), created_profile_manager_(false), created_local_state_(false), created_icon_manager_(false), @@ -155,6 +156,9 @@ BrowserProcessImpl::~BrowserProcessImpl() { // request before going away. io_thread_.reset(); + // The IO thread was the only user of this thread. + cache_thread_.reset(); + // Stop the process launcher thread after the IO thread, in case the IO thread // posted a task to terminate a process on the process launcher thread. process_launcher_thread_.reset(); @@ -378,6 +382,19 @@ void BrowserProcessImpl::CreateProcessLauncherThread() { process_launcher_thread_.swap(thread); } +void BrowserProcessImpl::CreateCacheThread() { + DCHECK(!created_cache_thread_ && !cache_thread_.get()); + created_cache_thread_ = true; + + scoped_ptr<base::Thread> thread( + new BrowserProcessSubThread(ChromeThread::CACHE)); + base::Thread::Options options; + options.message_loop_type = MessageLoop::TYPE_IO; + if (!thread->StartWithOptions(options)) + return; + cache_thread_.swap(thread); +} + void BrowserProcessImpl::CreateProfileManager() { DCHECK(!created_profile_manager_ && profile_manager_.get() == NULL); created_profile_manager_ = true; diff --git a/chrome/browser/browser_process_impl.h b/chrome/browser/browser_process_impl.h index d476b58..703d70c 100644 --- a/chrome/browser/browser_process_impl.h +++ b/chrome/browser/browser_process_impl.h @@ -76,6 +76,13 @@ class BrowserProcessImpl : public BrowserProcess, public NonThreadSafe { return process_launcher_thread_.get(); } + virtual base::Thread* cache_thread() { + DCHECK(CalledOnValidThread()); + if (!created_cache_thread_) + CreateCacheThread(); + return cache_thread_.get(); + } + #if defined(USE_X11) virtual base::Thread* background_x11_thread() { DCHECK(CalledOnValidThread()); @@ -221,6 +228,7 @@ class BrowserProcessImpl : public BrowserProcess, public NonThreadSafe { void CreateFileThread(); void CreateDBThread(); void CreateProcessLauncherThread(); + void CreateCacheThread(); void CreateTemplateURLModel(); void CreateProfileManager(); void CreateWebDataService(); @@ -260,6 +268,9 @@ class BrowserProcessImpl : public BrowserProcess, public NonThreadSafe { bool created_process_launcher_thread_; scoped_ptr<base::Thread> process_launcher_thread_; + bool created_cache_thread_; + scoped_ptr<base::Thread> cache_thread_; + bool created_profile_manager_; scoped_ptr<ProfileManager> profile_manager_; diff --git a/chrome/browser/chrome_thread.cc b/chrome/browser/chrome_thread.cc index a9c6092..984d188 100644 --- a/chrome/browser/chrome_thread.cc +++ b/chrome/browser/chrome_thread.cc @@ -14,6 +14,7 @@ static const char* chrome_thread_names[ChromeThread::ID_COUNT] = { "Chrome_WebKitThread", // WEBKIT "Chrome_FileThread", // FILE "Chrome_ProcessLauncherThread", // PROCESS_LAUNCHER + "Chrome_CacheThread", // CACHE "Chrome_IOThread", // IO #if defined(USE_X11) "Chrome_Background_X11Thread", // BACKGROUND_X11 diff --git a/chrome/browser/chrome_thread.h b/chrome/browser/chrome_thread.h index da7493f..5dbedfa 100644 --- a/chrome/browser/chrome_thread.h +++ b/chrome/browser/chrome_thread.h @@ -55,6 +55,9 @@ class ChromeThread : public base::Thread { // Used to launch and terminate processes. PROCESS_LAUNCHER, + // This is the thread to handle slow HTTP cache operations. + CACHE, + // This is the thread that processes IPC and network messages. IO, diff --git a/chrome/browser/net/chrome_url_request_context.cc b/chrome/browser/net/chrome_url_request_context.cc index 061ee29..aff7ba3 100644 --- a/chrome/browser/net/chrome_url_request_context.cc +++ b/chrome/browser/net/chrome_url_request_context.cc @@ -247,9 +247,9 @@ ChromeURLRequestContext* FactoryForOriginal::Create() { command_line, MessageLoop::current() /*io_loop*/)); - net::HttpCache::DefaultBackend* backend = - new net::HttpCache::DefaultBackend(net::DISK_CACHE, disk_cache_path_, - cache_size_, NULL); + net::HttpCache::DefaultBackend* backend = new net::HttpCache::DefaultBackend( + net::DISK_CACHE, disk_cache_path_, cache_size_, + ChromeThread::GetMessageLoopProxyForThread(ChromeThread::CACHE)); net::HttpCache* cache = new net::HttpCache(io_thread()->globals()->network_change_notifier.get(), context->host_resolver(), @@ -446,9 +446,9 @@ ChromeURLRequestContext* FactoryForMedia::Create() { // Create a media cache with default size. // TODO(hclam): make the maximum size of media cache configurable. - net::HttpCache::DefaultBackend* backend = - new net::HttpCache::DefaultBackend(net::MEDIA_CACHE, disk_cache_path_, - cache_size_, NULL); + net::HttpCache::DefaultBackend* backend = new net::HttpCache::DefaultBackend( + net::MEDIA_CACHE, disk_cache_path_, cache_size_, + ChromeThread::GetMessageLoopProxyForThread(ChromeThread::CACHE)); net::HttpCache* main_cache = main_context->http_transaction_factory()->GetCache(); diff --git a/chrome/test/testing_browser_process.h b/chrome/test/testing_browser_process.h index e704330..fdfe776 100644 --- a/chrome/test/testing_browser_process.h +++ b/chrome/test/testing_browser_process.h @@ -61,6 +61,10 @@ class TestingBrowserProcess : public BrowserProcess { return NULL; } + virtual base::Thread* cache_thread() { + return NULL; + } + virtual ProfileManager* profile_manager() { return NULL; } diff --git a/net/disk_cache/backend_impl.cc b/net/disk_cache/backend_impl.cc index d45fb29..84e956f 100644 --- a/net/disk_cache/backend_impl.cc +++ b/net/disk_cache/backend_impl.cc @@ -174,8 +174,8 @@ Backend* CreateCacheBackend(const FilePath& full_path, bool force, } int CreateCacheBackend(net::CacheType type, const FilePath& path, int max_bytes, - bool force, MessageLoop* thread, Backend** backend, - CompletionCallback* callback) { + bool force, base::MessageLoopProxy* thread, + Backend** backend, CompletionCallback* callback) { if (type == net::MEMORY_CACHE) *backend = CreateInMemoryCacheBackend(max_bytes); else diff --git a/net/disk_cache/disk_cache.h b/net/disk_cache/disk_cache.h index c216ccb..fab9c91 100644 --- a/net/disk_cache/disk_cache.h +++ b/net/disk_cache/disk_cache.h @@ -17,7 +17,10 @@ #include "net/base/completion_callback.h" class FilePath; -class MessageLoop; + +namespace base { +class MessageLoopProxy; +} namespace net { class IOBuffer; @@ -66,8 +69,8 @@ Backend* CreateInMemoryCacheBackend(int max_bytes); // 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, MessageLoop* thread, Backend** backend, - CompletionCallback* callback); + bool force, base::MessageLoopProxy* thread, + Backend** backend, CompletionCallback* callback); // The root interface for a disk cache instance. class Backend { diff --git a/net/http/http_cache.h b/net/http/http_cache.h index c82dc4e..177bdc7 100644 --- a/net/http/http_cache.h +++ b/net/http/http_cache.h @@ -20,6 +20,7 @@ #include "base/basictypes.h" #include "base/file_path.h" #include "base/hash_tables.h" +#include "base/message_loop_proxy.h" #include "base/scoped_ptr.h" #include "base/task.h" #include "base/weak_ptr.h" @@ -28,7 +29,6 @@ #include "net/http/http_transaction_factory.h" class GURL; -class MessageLoop; class ViewCacheHelper; namespace disk_cache { @@ -89,7 +89,7 @@ class HttpCache : public HttpTransactionFactory, // |cache_thread| is the thread where disk operations should take place. If // |max_bytes| is zero, a default value will be calculated automatically. DefaultBackend(CacheType type, const FilePath& path, int max_bytes, - MessageLoop* thread) + base::MessageLoopProxy* thread) : type_(type), path_(path), max_bytes_(max_bytes), thread_(thread) {} // Returns a factory for an in-memory cache. @@ -105,7 +105,7 @@ class HttpCache : public HttpTransactionFactory, CacheType type_; const FilePath path_; int max_bytes_; - MessageLoop* thread_; + scoped_refptr<base::MessageLoopProxy> thread_; }; // The disk cache is initialized lazily (by CreateTransaction) in this case. |