diff options
author | michaeln@chromium.org <michaeln@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-29 22:46:55 +0000 |
---|---|---|
committer | michaeln@chromium.org <michaeln@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-29 22:46:55 +0000 |
commit | 35f2094cd0ac27018aff2646445f44c3f9ee8d36 (patch) | |
tree | 0f4892fb2f6bcf9d5f044e70c1cf1ed0d42bb882 /webkit/appcache/appcache_storage_impl.h | |
parent | 6d38a7fc2594f14cbb87e28389c81965381b64e8 (diff) | |
download | chromium_src-35f2094cd0ac27018aff2646445f44c3f9ee8d36.zip chromium_src-35f2094cd0ac27018aff2646445f44c3f9ee8d36.tar.gz chromium_src-35f2094cd0ac27018aff2646445f44c3f9ee8d36.tar.bz2 |
AppCacheDatabase and SQL based AppCacheStorageImpl.
Still nothing is being written to disk with this CL,
in-memory SQLite and DiskCaches are being utilized.
Responses are not yet being removed from the DiskCasche
when the should be. Once that's done (in the next CL), we'll
start saving things on disk.
BUG=none
TEST=appcache_database_unittest.cc, appcache_storage_impl_unittest.cc
Review URL: http://codereview.chromium.org/518020
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35354 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/appcache/appcache_storage_impl.h')
-rw-r--r-- | webkit/appcache/appcache_storage_impl.h | 96 |
1 files changed, 90 insertions, 6 deletions
diff --git a/webkit/appcache/appcache_storage_impl.h b/webkit/appcache/appcache_storage_impl.h index ef75d1e..71fe34e 100644 --- a/webkit/appcache/appcache_storage_impl.h +++ b/webkit/appcache/appcache_storage_impl.h @@ -5,22 +5,106 @@ #ifndef WEBKIT_APPCACHE_APPCACHE_STORAGE_IMPL_H_ #define WEBKIT_APPCACHE_APPCACHE_STORAGE_IMPL_H_ +#include <deque> +#include <map> +#include <set> +#include <vector> + #include "base/file_path.h" -#include "webkit/appcache/mock_appcache_storage.h" +#include "net/disk_cache/disk_cache.h" +#include "webkit/appcache/appcache_database.h" +#include "webkit/appcache/appcache_storage.h" namespace appcache { -// TODO(michaeln): write me, for now we derive from 'mock' storage. -class AppCacheStorageImpl : public MockAppCacheStorage { +class AppCacheStorageImpl : public AppCacheStorage { public: - explicit AppCacheStorageImpl(AppCacheService* service) - : MockAppCacheStorage(service), is_incognito_(false) {} + explicit AppCacheStorageImpl(AppCacheService* service); + virtual ~AppCacheStorageImpl(); void Initialize(const FilePath& cache_directory); + // AppCacheStorage methods + virtual void LoadCache(int64 id, Delegate* delegate); + virtual void LoadOrCreateGroup(const GURL& manifest_url, Delegate* delegate); + virtual void StoreGroupAndNewestCache( + AppCacheGroup* group, AppCache* newest_cache, Delegate* delegate); + virtual void FindResponseForMainRequest(const GURL& url, Delegate* delegate); + virtual void FindResponseForSubRequest( + AppCache* cache, const GURL& url, + AppCacheEntry* found_entry, AppCacheEntry* found_fallback_entry, + bool* found_network_namespace); + virtual void MarkEntryAsForeign(const GURL& entry_url, int64 cache_id); + virtual void MakeGroupObsolete(AppCacheGroup* group, Delegate* delegate); + virtual AppCacheResponseReader* CreateResponseReader( + const GURL& manifest_url, int64 response_id); + virtual AppCacheResponseWriter* CreateResponseWriter( + const GURL& manifest_url); + virtual void DoomResponses( + const GURL& manifest_url, const std::vector<int64>& response_ids); + private: - bool is_incognito_; + friend class AppCacheStorageImplTest; + + // A handful of tasks used to perform database operations on the + // background database thread. + class DatabaseTask; + class InitTask; + class CloseConnectionTask; + class StoreOrLoadTask; + class CacheLoadTask; + class GroupLoadTask; + class StoreGroupAndCacheTask; + class FindMainResponseTask; + class MarkEntryAsForeignTask; + class MakeGroupObsoleteTask; + + typedef std::deque<DatabaseTask*> DatabaseTaskQueue; + typedef std::map<int64, CacheLoadTask*> PendingCacheLoads; + typedef std::map<GURL, GroupLoadTask*> PendingGroupLoads; + typedef std::deque<std::pair<GURL, int64> > PendingForeignMarkings; + + bool IsInitTaskComplete() { + return last_cache_id_ != AppCacheStorage::kUnitializedId; + } + + CacheLoadTask* GetPendingCacheLoadTask(int64 cache_id); + GroupLoadTask* GetPendingGroupLoadTask(const GURL& manifest_url); + void GetPendingForeignMarkingsForCache( + int64 cache_id, std::vector<GURL>* urls); + + void ScheduleSimpleTask(Task* task); + void RunOnePendingSimpleTask(); + + // Sometimes we can respond without having to query the database. + void DeliverShortCircuitedFindMainResponse( + const GURL& url, AppCacheEntry found_entry, + scoped_refptr<AppCacheGroup> group, scoped_refptr<AppCache> newest_cache, + scoped_refptr<DelegateReference> delegate_ref); + + disk_cache::Backend* disk_cache(); + + // The directory in which we place files in the file system. FilePath cache_directory_; + bool is_incognito_; + + // Structures to keep track of DatabaseTasks that are in-flight. + DatabaseTaskQueue scheduled_database_tasks_; + PendingCacheLoads pending_cache_loads_; + PendingGroupLoads pending_group_loads_; + PendingForeignMarkings pending_foreign_markings_; + + // Created on the IO thread, but only used on the DB thread. + AppCacheDatabase* database_; + + // TODO(michaeln): use a disk_cache per group (manifest or group_id). + scoped_ptr<disk_cache::Backend> disk_cache_; + + // Used to short-circuit certain operations without having to schedule + // any tasks on the background database thread. + std::set<GURL> origins_with_groups_; + std::deque<Task*> pending_simple_tasks_; + ScopedRunnableMethodFactory<AppCacheStorageImpl> method_factory_; }; } // namespace appcache |