diff options
author | michaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-15 20:00:11 +0000 |
---|---|---|
committer | michaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-15 20:00:11 +0000 |
commit | 6c270d442c1ee1a526538b8530e6198a9ada90e4 (patch) | |
tree | 5e5ccfbcd54cc59bbb250a233cf128df9dac5fab | |
parent | e10d86c2067313fa2cdc8684b5f0904b0d8d985e (diff) | |
download | chromium_src-6c270d442c1ee1a526538b8530e6198a9ada90e4.zip chromium_src-6c270d442c1ee1a526538b8530e6198a9ada90e4.tar.gz chromium_src-6c270d442c1ee1a526538b8530e6198a9ada90e4.tar.bz2 |
1) Tell the AppCacheService which request context to use when fetching resources for updates. Done for both chrome and test_shell. The service does not yet take a reference to that context, because the extra reference apparently gives some tests grief.
2) Added methods to generate new storage ids for different object types on the IO thread.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/195077
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26253 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/profile.cc | 6 | ||||
-rw-r--r-- | chrome/common/appcache/chrome_appcache_service.h | 2 | ||||
-rw-r--r-- | webkit/appcache/appcache_service.cc | 6 | ||||
-rw-r--r-- | webkit/appcache/appcache_service.h | 32 | ||||
-rw-r--r-- | webkit/tools/test_shell/simple_appcache_system.cc | 3 | ||||
-rw-r--r-- | webkit/tools/test_shell/simple_appcache_system.h | 7 | ||||
-rw-r--r-- | webkit/tools/test_shell/simple_resource_loader_bridge.cc | 2 |
7 files changed, 49 insertions, 9 deletions
diff --git a/chrome/browser/profile.cc b/chrome/browser/profile.cc index f4fb817..de7f949 100644 --- a/chrome/browser/profile.cc +++ b/chrome/browser/profile.cc @@ -224,7 +224,8 @@ class OffTheRecordProfileImpl : public Profile, virtual ChromeAppCacheService* GetAppCacheService() { if (!appcache_service_.get()) { appcache_service_ = new ChromeAppCacheService(); - appcache_service_->InitializeOnUIThread(GetPath(), true); + appcache_service_->InitializeOnUIThread( + GetPath(), GetRequestContext(), true); } return appcache_service_.get(); } @@ -780,7 +781,8 @@ Profile* ProfileImpl::GetOriginalProfile() { ChromeAppCacheService* ProfileImpl::GetAppCacheService() { if (!appcache_service_.get()) { appcache_service_ = new ChromeAppCacheService(); - appcache_service_->InitializeOnUIThread(GetPath(), false); + appcache_service_->InitializeOnUIThread( + GetPath(), GetRequestContext(), false); } return appcache_service_.get(); } diff --git a/chrome/common/appcache/chrome_appcache_service.h b/chrome/common/appcache/chrome_appcache_service.h index 63736da..3dd6082 100644 --- a/chrome/common/appcache/chrome_appcache_service.h +++ b/chrome/common/appcache/chrome_appcache_service.h @@ -33,8 +33,10 @@ class ChromeAppCacheService } void InitializeOnUIThread(const FilePath& data_directory, + URLRequestContext* request_context, bool is_incognito) { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); + set_request_context(request_context); // Some test cases run without an IO thread. MessageLoop* io_thread = ChromeThread::GetMessageLoop(ChromeThread::IO); diff --git a/webkit/appcache/appcache_service.cc b/webkit/appcache/appcache_service.cc index 0fd5356..029c4ef 100644 --- a/webkit/appcache/appcache_service.cc +++ b/webkit/appcache/appcache_service.cc @@ -11,6 +11,11 @@ namespace appcache { +AppCacheService::AppCacheService() + : last_cache_id_(0), last_group_id_(0), + last_entry_id_(0), last_response_id_(0) { +} + AppCacheService::~AppCacheService() { DCHECK(backends_.empty()); DCHECK(caches_.empty()); @@ -20,6 +25,7 @@ AppCacheService::~AppCacheService() { void AppCacheService::Initialize(const FilePath& cache_directory) { // An empty cache directory indicates chrome incognito. cache_directory_ = cache_directory; + // TODO(michaeln): load last_<foo>_ids from storage } void AppCacheService::RegisterBackend( diff --git a/webkit/appcache/appcache_service.h b/webkit/appcache/appcache_service.h index bc8bee8..0ccad80 100644 --- a/webkit/appcache/appcache_service.h +++ b/webkit/appcache/appcache_service.h @@ -11,6 +11,8 @@ #include "base/hash_tables.h" #include "base/file_path.h" +#include "base/ref_counted.h" +#include "net/url_request/url_request_context.h" #include "googleurl/src/gurl.h" namespace appcache { @@ -20,13 +22,24 @@ class AppCacheBackendImpl; class AppCacheGroup; // Class that manages the application cache service. Sends notifications -// to many frontends. One instance per user-profile. +// to many frontends. One instance per user-profile. Each instance has +// exclusive access to it's cache_directory on disk. class AppCacheService { public: + AppCacheService(); virtual ~AppCacheService(); void Initialize(const FilePath& cache_directory); + // Context for use during cache updates, should only be accessed + // on the IO thread. + URLRequestContext* request_context() { return request_context_.get(); } + void set_request_context(URLRequestContext* context) { + // TODO(michaeln): need to look into test failures that occur + // when we take this reference? Stubbing out for now. + // request_context_ = context; + } + // TODO(jennb): API to set service settings, like file paths for storage // track which processes are using this appcache service @@ -53,6 +66,12 @@ class AppCacheService { return (it != groups_.end()) ? it->second : NULL; } + // The service generates unique storage ids for different object types. + int64 NewCacheId() { return ++last_cache_id_; } + int64 NewGroupId() { return ++last_group_id_; } + int64 NewEntryId() { return ++last_entry_id_; } + int64 NewResponseId() { return ++last_response_id_; } + private: // In-memory representation of stored appcache data. Represents a subset // of the appcache database currently in use. @@ -61,16 +80,25 @@ class AppCacheService { CacheMap caches_; GroupMap groups_; + // The last storage id used for different object types. + int64 last_cache_id_; + int64 last_group_id_; + int64 last_entry_id_; + int64 last_response_id_; + // Track current processes. One 'backend' per child process. typedef std::map<int, AppCacheBackendImpl*> BackendMap; BackendMap backends_; FilePath cache_directory_; + + // Context for use during cache updates. + scoped_refptr<URLRequestContext> request_context_; + // TODO(jennb): info about appcache storage // AppCacheDatabase db_; // DiskCache response_storage_; - // TODO(jennb): service settings: e.g. max size of app cache? // TODO(jennb): service state: e.g. reached quota? }; diff --git a/webkit/tools/test_shell/simple_appcache_system.cc b/webkit/tools/test_shell/simple_appcache_system.cc index 5ab7fe2..489579f 100644 --- a/webkit/tools/test_shell/simple_appcache_system.cc +++ b/webkit/tools/test_shell/simple_appcache_system.cc @@ -258,7 +258,7 @@ void SimpleAppCacheSystem::InitOnUIThread( cache_directory_ = cache_directory; } -void SimpleAppCacheSystem::InitOnIOThread() { +void SimpleAppCacheSystem::InitOnIOThread(URLRequestContext* request_context) { if (!is_initailized_on_ui_thread()) return; @@ -270,6 +270,7 @@ void SimpleAppCacheSystem::InitOnIOThread() { service_ = new appcache::AppCacheService(); backend_impl_ = new appcache::AppCacheBackendImpl(); service_->Initialize(cache_directory_); + service_->set_request_context(request_context); backend_impl_->Initialize(service_, frontend_proxy_.get(), kSingleProcessId); AppCacheInterceptor::EnsureRegistered(); diff --git a/webkit/tools/test_shell/simple_appcache_system.h b/webkit/tools/test_shell/simple_appcache_system.h index 184842f..c029051 100644 --- a/webkit/tools/test_shell/simple_appcache_system.h +++ b/webkit/tools/test_shell/simple_appcache_system.h @@ -19,6 +19,7 @@ class WebApplicationCacheHostClient; class SimpleBackendProxy; class SimpleFrontendProxy; class URLRequest; +class URLRequestContext; // A class that composes the constituent parts of an appcache system // together for use in a single process with two relavant threads, @@ -43,9 +44,9 @@ class SimpleAppCacheSystem : public MessageLoop::DestructionObserver { // at a time, but after IO thread termination a new one can be // started on which this method should be called. The instance // is assumed to outlive the IO thread. - static void InitializeOnIOThread() { + static void InitializeOnIOThread(URLRequestContext* request_context) { if (instance_) - instance_->InitOnIOThread(); + instance_->InitOnIOThread(request_context); } // Called by TestShellWebKitInit to manufacture a 'host' for webcore. @@ -79,7 +80,7 @@ class SimpleAppCacheSystem : public MessageLoop::DestructionObserver { // Instance methods called by our static public methods void InitOnUIThread(const FilePath& cache_directory); - void InitOnIOThread(); + void InitOnIOThread(URLRequestContext* request_context); WebKit::WebApplicationCacheHost* CreateCacheHostForWebKit( WebKit::WebApplicationCacheHostClient* client); void SetExtraRequestBits(URLRequest* request, diff --git a/webkit/tools/test_shell/simple_resource_loader_bridge.cc b/webkit/tools/test_shell/simple_resource_loader_bridge.cc index 142ab5e..0f1be30 100644 --- a/webkit/tools/test_shell/simple_resource_loader_bridge.cc +++ b/webkit/tools/test_shell/simple_resource_loader_bridge.cc @@ -75,7 +75,7 @@ class IOThread : public base::Thread { } virtual void Init() { - SimpleAppCacheSystem::InitializeOnIOThread(); + SimpleAppCacheSystem::InitializeOnIOThread(request_context); } virtual void CleanUp() { |