| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_BROWSER_APPCACHE_APPCACHE_STORAGE_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_APPCACHE_APPCACHE_STORAGE_IMPL_H_ |
| 6 #define CONTENT_BROWSER_APPCACHE_APPCACHE_STORAGE_IMPL_H_ | 6 #define CONTENT_BROWSER_APPCACHE_APPCACHE_STORAGE_IMPL_H_ |
| 7 | 7 |
| 8 #include <deque> | 8 #include <deque> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 | 36 |
| 37 void Initialize( | 37 void Initialize( |
| 38 const base::FilePath& cache_directory, | 38 const base::FilePath& cache_directory, |
| 39 const scoped_refptr<base::SingleThreadTaskRunner>& db_thread, | 39 const scoped_refptr<base::SingleThreadTaskRunner>& db_thread, |
| 40 const scoped_refptr<base::SingleThreadTaskRunner>& cache_thread); | 40 const scoped_refptr<base::SingleThreadTaskRunner>& cache_thread); |
| 41 void Disable(); | 41 void Disable(); |
| 42 bool is_disabled() const { return is_disabled_; } | 42 bool is_disabled() const { return is_disabled_; } |
| 43 | 43 |
| 44 // AppCacheStorage methods, see the base class for doc comments. | 44 // AppCacheStorage methods, see the base class for doc comments. |
| 45 void GetAllInfo(Delegate* delegate) override; | 45 void GetAllInfo(Delegate* delegate) override; |
| 46 void LoadCache(int64 id, Delegate* delegate) override; | 46 void LoadCache(int64_t id, Delegate* delegate) override; |
| 47 void LoadOrCreateGroup(const GURL& manifest_url, Delegate* delegate) override; | 47 void LoadOrCreateGroup(const GURL& manifest_url, Delegate* delegate) override; |
| 48 void StoreGroupAndNewestCache(AppCacheGroup* group, | 48 void StoreGroupAndNewestCache(AppCacheGroup* group, |
| 49 AppCache* newest_cache, | 49 AppCache* newest_cache, |
| 50 Delegate* delegate) override; | 50 Delegate* delegate) override; |
| 51 void FindResponseForMainRequest(const GURL& url, | 51 void FindResponseForMainRequest(const GURL& url, |
| 52 const GURL& preferred_manifest_url, | 52 const GURL& preferred_manifest_url, |
| 53 Delegate* delegate) override; | 53 Delegate* delegate) override; |
| 54 void FindResponseForSubRequest(AppCache* cache, | 54 void FindResponseForSubRequest(AppCache* cache, |
| 55 const GURL& url, | 55 const GURL& url, |
| 56 AppCacheEntry* found_entry, | 56 AppCacheEntry* found_entry, |
| 57 AppCacheEntry* found_fallback_entry, | 57 AppCacheEntry* found_fallback_entry, |
| 58 bool* found_network_namespace) override; | 58 bool* found_network_namespace) override; |
| 59 void MarkEntryAsForeign(const GURL& entry_url, int64 cache_id) override; | 59 void MarkEntryAsForeign(const GURL& entry_url, int64_t cache_id) override; |
| 60 void MakeGroupObsolete(AppCacheGroup* group, | 60 void MakeGroupObsolete(AppCacheGroup* group, |
| 61 Delegate* delegate, | 61 Delegate* delegate, |
| 62 int response_code) override; | 62 int response_code) override; |
| 63 void StoreEvictionTimes(AppCacheGroup* group) override; | 63 void StoreEvictionTimes(AppCacheGroup* group) override; |
| 64 AppCacheResponseReader* CreateResponseReader(const GURL& manifest_url, | 64 AppCacheResponseReader* CreateResponseReader(const GURL& manifest_url, |
| 65 int64 group_id, | 65 int64_t group_id, |
| 66 int64 response_id) override; | 66 int64_t response_id) override; |
| 67 AppCacheResponseWriter* CreateResponseWriter(const GURL& manifest_url, | 67 AppCacheResponseWriter* CreateResponseWriter(const GURL& manifest_url, |
| 68 int64 group_id) override; | 68 int64_t group_id) override; |
| 69 AppCacheResponseMetadataWriter* CreateResponseMetadataWriter( | 69 AppCacheResponseMetadataWriter* CreateResponseMetadataWriter( |
| 70 int64 group_id, | 70 int64_t group_id, |
| 71 int64 response_id) override; | 71 int64_t response_id) override; |
| 72 void DoomResponses(const GURL& manifest_url, | 72 void DoomResponses(const GURL& manifest_url, |
| 73 const std::vector<int64>& response_ids) override; | 73 const std::vector<int64_t>& response_ids) override; |
| 74 void DeleteResponses(const GURL& manifest_url, | 74 void DeleteResponses(const GURL& manifest_url, |
| 75 const std::vector<int64>& response_ids) override; | 75 const std::vector<int64_t>& response_ids) override; |
| 76 | 76 |
| 77 private: | 77 private: |
| 78 // The AppCacheStorageImpl class methods and datamembers may only be | 78 // The AppCacheStorageImpl class methods and datamembers may only be |
| 79 // accessed on the IO thread. This class manufactures seperate DatabaseTasks | 79 // accessed on the IO thread. This class manufactures seperate DatabaseTasks |
| 80 // which access the DB on a seperate background thread. | 80 // which access the DB on a seperate background thread. |
| 81 class DatabaseTask; | 81 class DatabaseTask; |
| 82 class InitTask; | 82 class InitTask; |
| 83 class DisableDatabaseTask; | 83 class DisableDatabaseTask; |
| 84 class GetAllInfoTask; | 84 class GetAllInfoTask; |
| 85 class StoreOrLoadTask; | 85 class StoreOrLoadTask; |
| 86 class CacheLoadTask; | 86 class CacheLoadTask; |
| 87 class GroupLoadTask; | 87 class GroupLoadTask; |
| 88 class StoreGroupAndCacheTask; | 88 class StoreGroupAndCacheTask; |
| 89 class FindMainResponseTask; | 89 class FindMainResponseTask; |
| 90 class MarkEntryAsForeignTask; | 90 class MarkEntryAsForeignTask; |
| 91 class MakeGroupObsoleteTask; | 91 class MakeGroupObsoleteTask; |
| 92 class GetDeletableResponseIdsTask; | 92 class GetDeletableResponseIdsTask; |
| 93 class InsertDeletableResponseIdsTask; | 93 class InsertDeletableResponseIdsTask; |
| 94 class DeleteDeletableResponseIdsTask; | 94 class DeleteDeletableResponseIdsTask; |
| 95 class LazyUpdateLastAccessTimeTask; | 95 class LazyUpdateLastAccessTimeTask; |
| 96 class CommitLastAccessTimesTask; | 96 class CommitLastAccessTimesTask; |
| 97 class UpdateEvictionTimesTask; | 97 class UpdateEvictionTimesTask; |
| 98 | 98 |
| 99 typedef std::deque<DatabaseTask*> DatabaseTaskQueue; | 99 typedef std::deque<DatabaseTask*> DatabaseTaskQueue; |
| 100 typedef std::map<int64, CacheLoadTask*> PendingCacheLoads; | 100 typedef std::map<int64_t, CacheLoadTask*> PendingCacheLoads; |
| 101 typedef std::map<GURL, GroupLoadTask*> PendingGroupLoads; | 101 typedef std::map<GURL, GroupLoadTask*> PendingGroupLoads; |
| 102 typedef std::deque<std::pair<GURL, int64> > PendingForeignMarkings; | 102 typedef std::deque<std::pair<GURL, int64_t>> PendingForeignMarkings; |
| 103 typedef std::set<StoreGroupAndCacheTask*> PendingQuotaQueries; | 103 typedef std::set<StoreGroupAndCacheTask*> PendingQuotaQueries; |
| 104 | 104 |
| 105 bool IsInitTaskComplete() { | 105 bool IsInitTaskComplete() { |
| 106 return last_cache_id_ != AppCacheStorage::kUnitializedId; | 106 return last_cache_id_ != AppCacheStorage::kUnitializedId; |
| 107 } | 107 } |
| 108 | 108 |
| 109 CacheLoadTask* GetPendingCacheLoadTask(int64 cache_id); | 109 CacheLoadTask* GetPendingCacheLoadTask(int64_t cache_id); |
| 110 GroupLoadTask* GetPendingGroupLoadTask(const GURL& manifest_url); | 110 GroupLoadTask* GetPendingGroupLoadTask(const GURL& manifest_url); |
| 111 void GetPendingForeignMarkingsForCache( | 111 void GetPendingForeignMarkingsForCache(int64_t cache_id, |
| 112 int64 cache_id, std::vector<GURL>* urls); | 112 std::vector<GURL>* urls); |
| 113 | 113 |
| 114 void ScheduleSimpleTask(const base::Closure& task); | 114 void ScheduleSimpleTask(const base::Closure& task); |
| 115 void RunOnePendingSimpleTask(); | 115 void RunOnePendingSimpleTask(); |
| 116 | 116 |
| 117 void DelayedStartDeletingUnusedResponses(); | 117 void DelayedStartDeletingUnusedResponses(); |
| 118 void StartDeletingResponses(const std::vector<int64>& response_ids); | 118 void StartDeletingResponses(const std::vector<int64_t>& response_ids); |
| 119 void ScheduleDeleteOneResponse(); | 119 void ScheduleDeleteOneResponse(); |
| 120 void DeleteOneResponse(); | 120 void DeleteOneResponse(); |
| 121 void OnDeletedOneResponse(int rv); | 121 void OnDeletedOneResponse(int rv); |
| 122 void OnDiskCacheInitialized(int rv); | 122 void OnDiskCacheInitialized(int rv); |
| 123 void DeleteAndStartOver(); | 123 void DeleteAndStartOver(); |
| 124 void DeleteAndStartOverPart2(); | 124 void DeleteAndStartOverPart2(); |
| 125 void CallScheduleReinitialize(); | 125 void CallScheduleReinitialize(); |
| 126 void LazilyCommitLastAccessTimes(); | 126 void LazilyCommitLastAccessTimes(); |
| 127 void OnLazyCommitTimer(); | 127 void OnLazyCommitTimer(); |
| 128 | 128 |
| 129 // Sometimes we can respond without having to query the database. | 129 // Sometimes we can respond without having to query the database. |
| 130 bool FindResponseForMainRequestInGroup( | 130 bool FindResponseForMainRequestInGroup( |
| 131 AppCacheGroup* group, const GURL& url, Delegate* delegate); | 131 AppCacheGroup* group, const GURL& url, Delegate* delegate); |
| 132 void DeliverShortCircuitedFindMainResponse( | 132 void DeliverShortCircuitedFindMainResponse( |
| 133 const GURL& url, | 133 const GURL& url, |
| 134 const AppCacheEntry& found_entry, | 134 const AppCacheEntry& found_entry, |
| 135 scoped_refptr<AppCacheGroup> group, | 135 scoped_refptr<AppCacheGroup> group, |
| 136 scoped_refptr<AppCache> newest_cache, | 136 scoped_refptr<AppCache> newest_cache, |
| 137 scoped_refptr<DelegateReference> delegate_ref); | 137 scoped_refptr<DelegateReference> delegate_ref); |
| 138 | 138 |
| 139 void CallOnMainResponseFound( | 139 void CallOnMainResponseFound(DelegateReferenceVector* delegates, |
| 140 DelegateReferenceVector* delegates, | 140 const GURL& url, |
| 141 const GURL& url, const AppCacheEntry& entry, | 141 const AppCacheEntry& entry, |
| 142 const GURL& namespace_entry_url, const AppCacheEntry& fallback_entry, | 142 const GURL& namespace_entry_url, |
| 143 int64 cache_id, int64 group_id, const GURL& manifest_url); | 143 const AppCacheEntry& fallback_entry, |
| 144 int64_t cache_id, |
| 145 int64_t group_id, |
| 146 const GURL& manifest_url); |
| 144 | 147 |
| 145 CONTENT_EXPORT AppCacheDiskCache* disk_cache(); | 148 CONTENT_EXPORT AppCacheDiskCache* disk_cache(); |
| 146 | 149 |
| 147 // The directory in which we place files in the file system. | 150 // The directory in which we place files in the file system. |
| 148 base::FilePath cache_directory_; | 151 base::FilePath cache_directory_; |
| 149 bool is_incognito_; | 152 bool is_incognito_; |
| 150 | 153 |
| 151 // This class operates primarily on the IO thread, but schedules | 154 // This class operates primarily on the IO thread, but schedules |
| 152 // its DatabaseTasks on the db thread. Separately, the disk_cache uses | 155 // its DatabaseTasks on the db thread. Separately, the disk_cache uses |
| 153 // the cache thread. | 156 // the cache thread. |
| 154 scoped_refptr<base::SingleThreadTaskRunner> db_thread_; | 157 scoped_refptr<base::SingleThreadTaskRunner> db_thread_; |
| 155 scoped_refptr<base::SingleThreadTaskRunner> cache_thread_; | 158 scoped_refptr<base::SingleThreadTaskRunner> cache_thread_; |
| 156 | 159 |
| 157 // Structures to keep track of DatabaseTasks that are in-flight. | 160 // Structures to keep track of DatabaseTasks that are in-flight. |
| 158 DatabaseTaskQueue scheduled_database_tasks_; | 161 DatabaseTaskQueue scheduled_database_tasks_; |
| 159 PendingCacheLoads pending_cache_loads_; | 162 PendingCacheLoads pending_cache_loads_; |
| 160 PendingGroupLoads pending_group_loads_; | 163 PendingGroupLoads pending_group_loads_; |
| 161 PendingForeignMarkings pending_foreign_markings_; | 164 PendingForeignMarkings pending_foreign_markings_; |
| 162 PendingQuotaQueries pending_quota_queries_; | 165 PendingQuotaQueries pending_quota_queries_; |
| 163 | 166 |
| 164 // Structures to keep track of lazy response deletion. | 167 // Structures to keep track of lazy response deletion. |
| 165 std::deque<int64> deletable_response_ids_; | 168 std::deque<int64_t> deletable_response_ids_; |
| 166 std::vector<int64> deleted_response_ids_; | 169 std::vector<int64_t> deleted_response_ids_; |
| 167 bool is_response_deletion_scheduled_; | 170 bool is_response_deletion_scheduled_; |
| 168 bool did_start_deleting_responses_; | 171 bool did_start_deleting_responses_; |
| 169 int64 last_deletable_response_rowid_; | 172 int64_t last_deletable_response_rowid_; |
| 170 | 173 |
| 171 // Created on the IO thread, but only used on the DB thread. | 174 // Created on the IO thread, but only used on the DB thread. |
| 172 AppCacheDatabase* database_; | 175 AppCacheDatabase* database_; |
| 173 | 176 |
| 174 // Set if we discover a fatal error like a corrupt SQL database or | 177 // Set if we discover a fatal error like a corrupt SQL database or |
| 175 // disk cache and cannot continue. | 178 // disk cache and cannot continue. |
| 176 bool is_disabled_; | 179 bool is_disabled_; |
| 177 | 180 |
| 178 scoped_ptr<AppCacheDiskCache> disk_cache_; | 181 scoped_ptr<AppCacheDiskCache> disk_cache_; |
| 179 base::OneShotTimer lazy_commit_timer_; | 182 base::OneShotTimer lazy_commit_timer_; |
| 180 | 183 |
| 181 // Used to short-circuit certain operations without having to schedule | 184 // Used to short-circuit certain operations without having to schedule |
| 182 // any tasks on the background database thread. | 185 // any tasks on the background database thread. |
| 183 std::deque<base::Closure> pending_simple_tasks_; | 186 std::deque<base::Closure> pending_simple_tasks_; |
| 184 base::WeakPtrFactory<AppCacheStorageImpl> weak_factory_; | 187 base::WeakPtrFactory<AppCacheStorageImpl> weak_factory_; |
| 185 | 188 |
| 186 friend class content::AppCacheStorageImplTest; | 189 friend class content::AppCacheStorageImplTest; |
| 187 friend class content::ChromeAppCacheServiceTest; | 190 friend class content::ChromeAppCacheServiceTest; |
| 188 }; | 191 }; |
| 189 | 192 |
| 190 } // namespace content | 193 } // namespace content |
| 191 | 194 |
| 192 #endif // CONTENT_BROWSER_APPCACHE_APPCACHE_STORAGE_IMPL_H_ | 195 #endif // CONTENT_BROWSER_APPCACHE_APPCACHE_STORAGE_IMPL_H_ |
| OLD | NEW |