| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "content/browser/appcache/mock_appcache_storage.h" | 5 #include "content/browser/appcache/mock_appcache_storage.h" |
| 6 | 6 |
| 7 #include <stddef.h> |
| 8 |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/location.h" | 10 #include "base/location.h" |
| 9 #include "base/logging.h" | 11 #include "base/logging.h" |
| 10 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 11 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
| 12 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
| 13 #include "base/thread_task_runner_handle.h" | 15 #include "base/thread_task_runner_handle.h" |
| 14 #include "content/browser/appcache/appcache.h" | 16 #include "content/browser/appcache/appcache.h" |
| 15 #include "content/browser/appcache/appcache_entry.h" | 17 #include "content/browser/appcache/appcache_entry.h" |
| 16 #include "content/browser/appcache/appcache_group.h" | 18 #include "content/browser/appcache/appcache_group.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 47 MockAppCacheStorage::~MockAppCacheStorage() { | 49 MockAppCacheStorage::~MockAppCacheStorage() { |
| 48 } | 50 } |
| 49 | 51 |
| 50 void MockAppCacheStorage::GetAllInfo(Delegate* delegate) { | 52 void MockAppCacheStorage::GetAllInfo(Delegate* delegate) { |
| 51 ScheduleTask( | 53 ScheduleTask( |
| 52 base::Bind(&MockAppCacheStorage::ProcessGetAllInfo, | 54 base::Bind(&MockAppCacheStorage::ProcessGetAllInfo, |
| 53 weak_factory_.GetWeakPtr(), | 55 weak_factory_.GetWeakPtr(), |
| 54 make_scoped_refptr(GetOrCreateDelegateReference(delegate)))); | 56 make_scoped_refptr(GetOrCreateDelegateReference(delegate)))); |
| 55 } | 57 } |
| 56 | 58 |
| 57 void MockAppCacheStorage::LoadCache(int64 id, Delegate* delegate) { | 59 void MockAppCacheStorage::LoadCache(int64_t id, Delegate* delegate) { |
| 58 DCHECK(delegate); | 60 DCHECK(delegate); |
| 59 AppCache* cache = working_set_.GetCache(id); | 61 AppCache* cache = working_set_.GetCache(id); |
| 60 if (ShouldCacheLoadAppearAsync(cache)) { | 62 if (ShouldCacheLoadAppearAsync(cache)) { |
| 61 ScheduleTask( | 63 ScheduleTask( |
| 62 base::Bind(&MockAppCacheStorage::ProcessLoadCache, | 64 base::Bind(&MockAppCacheStorage::ProcessLoadCache, |
| 63 weak_factory_.GetWeakPtr(), id, | 65 weak_factory_.GetWeakPtr(), id, |
| 64 make_scoped_refptr(GetOrCreateDelegateReference(delegate)))); | 66 make_scoped_refptr(GetOrCreateDelegateReference(delegate)))); |
| 65 return; | 67 return; |
| 66 } | 68 } |
| 67 ProcessLoadCache(id, GetOrCreateDelegateReference(delegate)); | 69 ProcessLoadCache(id, GetOrCreateDelegateReference(delegate)); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 } | 125 } |
| 124 | 126 |
| 125 GURL fallback_namespace_not_used; | 127 GURL fallback_namespace_not_used; |
| 126 GURL intercept_namespace_not_used; | 128 GURL intercept_namespace_not_used; |
| 127 cache->FindResponseForRequest( | 129 cache->FindResponseForRequest( |
| 128 url, found_entry, &intercept_namespace_not_used, | 130 url, found_entry, &intercept_namespace_not_used, |
| 129 found_fallback_entry, &fallback_namespace_not_used, | 131 found_fallback_entry, &fallback_namespace_not_used, |
| 130 found_network_namespace); | 132 found_network_namespace); |
| 131 } | 133 } |
| 132 | 134 |
| 133 void MockAppCacheStorage::MarkEntryAsForeign( | 135 void MockAppCacheStorage::MarkEntryAsForeign(const GURL& entry_url, |
| 134 const GURL& entry_url, int64 cache_id) { | 136 int64_t cache_id) { |
| 135 AppCache* cache = working_set_.GetCache(cache_id); | 137 AppCache* cache = working_set_.GetCache(cache_id); |
| 136 if (cache) { | 138 if (cache) { |
| 137 AppCacheEntry* entry = cache->GetEntry(entry_url); | 139 AppCacheEntry* entry = cache->GetEntry(entry_url); |
| 138 DCHECK(entry); | 140 DCHECK(entry); |
| 139 if (entry) | 141 if (entry) |
| 140 entry->add_types(AppCacheEntry::FOREIGN); | 142 entry->add_types(AppCacheEntry::FOREIGN); |
| 141 } | 143 } |
| 142 } | 144 } |
| 143 | 145 |
| 144 void MockAppCacheStorage::MakeGroupObsolete(AppCacheGroup* group, | 146 void MockAppCacheStorage::MakeGroupObsolete(AppCacheGroup* group, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 155 response_code)); | 157 response_code)); |
| 156 } | 158 } |
| 157 | 159 |
| 158 void MockAppCacheStorage::StoreEvictionTimes(AppCacheGroup* group) { | 160 void MockAppCacheStorage::StoreEvictionTimes(AppCacheGroup* group) { |
| 159 stored_eviction_times_[group->group_id()] = | 161 stored_eviction_times_[group->group_id()] = |
| 160 std::make_pair(group->last_full_update_check_time(), | 162 std::make_pair(group->last_full_update_check_time(), |
| 161 group->first_evictable_error_time()); | 163 group->first_evictable_error_time()); |
| 162 } | 164 } |
| 163 | 165 |
| 164 AppCacheResponseReader* MockAppCacheStorage::CreateResponseReader( | 166 AppCacheResponseReader* MockAppCacheStorage::CreateResponseReader( |
| 165 const GURL& manifest_url, int64 group_id, int64 response_id) { | 167 const GURL& manifest_url, |
| 168 int64_t group_id, |
| 169 int64_t response_id) { |
| 166 if (simulated_reader_) | 170 if (simulated_reader_) |
| 167 return simulated_reader_.release(); | 171 return simulated_reader_.release(); |
| 168 return new AppCacheResponseReader(response_id, group_id, disk_cache()); | 172 return new AppCacheResponseReader(response_id, group_id, disk_cache()); |
| 169 } | 173 } |
| 170 | 174 |
| 171 AppCacheResponseWriter* MockAppCacheStorage::CreateResponseWriter( | 175 AppCacheResponseWriter* MockAppCacheStorage::CreateResponseWriter( |
| 172 const GURL& manifest_url, int64 group_id) { | 176 const GURL& manifest_url, |
| 177 int64_t group_id) { |
| 173 return new AppCacheResponseWriter(NewResponseId(), group_id, disk_cache()); | 178 return new AppCacheResponseWriter(NewResponseId(), group_id, disk_cache()); |
| 174 } | 179 } |
| 175 | 180 |
| 176 AppCacheResponseMetadataWriter* | 181 AppCacheResponseMetadataWriter* |
| 177 MockAppCacheStorage::CreateResponseMetadataWriter(int64 group_id, | 182 MockAppCacheStorage::CreateResponseMetadataWriter(int64_t group_id, |
| 178 int64 response_id) { | 183 int64_t response_id) { |
| 179 return new AppCacheResponseMetadataWriter(response_id, group_id, | 184 return new AppCacheResponseMetadataWriter(response_id, group_id, |
| 180 disk_cache()); | 185 disk_cache()); |
| 181 } | 186 } |
| 182 | 187 |
| 183 void MockAppCacheStorage::DoomResponses( | 188 void MockAppCacheStorage::DoomResponses( |
| 184 const GURL& manifest_url, const std::vector<int64>& response_ids) { | 189 const GURL& manifest_url, |
| 190 const std::vector<int64_t>& response_ids) { |
| 185 DeleteResponses(manifest_url, response_ids); | 191 DeleteResponses(manifest_url, response_ids); |
| 186 } | 192 } |
| 187 | 193 |
| 188 void MockAppCacheStorage::DeleteResponses( | 194 void MockAppCacheStorage::DeleteResponses( |
| 189 const GURL& manifest_url, const std::vector<int64>& response_ids) { | 195 const GURL& manifest_url, |
| 196 const std::vector<int64_t>& response_ids) { |
| 190 // We don't bother with actually removing responses from the disk-cache, | 197 // We don't bother with actually removing responses from the disk-cache, |
| 191 // just keep track of which ids have been doomed or deleted | 198 // just keep track of which ids have been doomed or deleted |
| 192 std::vector<int64>::const_iterator it = response_ids.begin(); | 199 std::vector<int64_t>::const_iterator it = response_ids.begin(); |
| 193 while (it != response_ids.end()) { | 200 while (it != response_ids.end()) { |
| 194 doomed_response_ids_.insert(*it); | 201 doomed_response_ids_.insert(*it); |
| 195 ++it; | 202 ++it; |
| 196 } | 203 } |
| 197 } | 204 } |
| 198 | 205 |
| 199 void MockAppCacheStorage::ProcessGetAllInfo( | 206 void MockAppCacheStorage::ProcessGetAllInfo( |
| 200 scoped_refptr<DelegateReference> delegate_ref) { | 207 scoped_refptr<DelegateReference> delegate_ref) { |
| 201 if (delegate_ref->delegate) | 208 if (delegate_ref->delegate) |
| 202 delegate_ref->delegate->OnAllInfo(simulated_appcache_info_.get()); | 209 delegate_ref->delegate->OnAllInfo(simulated_appcache_info_.get()); |
| 203 } | 210 } |
| 204 | 211 |
| 205 void MockAppCacheStorage::ProcessLoadCache( | 212 void MockAppCacheStorage::ProcessLoadCache( |
| 206 int64 id, scoped_refptr<DelegateReference> delegate_ref) { | 213 int64_t id, |
| 214 scoped_refptr<DelegateReference> delegate_ref) { |
| 207 AppCache* cache = working_set_.GetCache(id); | 215 AppCache* cache = working_set_.GetCache(id); |
| 208 if (delegate_ref->delegate) | 216 if (delegate_ref->delegate) |
| 209 delegate_ref->delegate->OnCacheLoaded(cache, id); | 217 delegate_ref->delegate->OnCacheLoaded(cache, id); |
| 210 } | 218 } |
| 211 | 219 |
| 212 void MockAppCacheStorage::ProcessLoadOrCreateGroup( | 220 void MockAppCacheStorage::ProcessLoadOrCreateGroup( |
| 213 const GURL& manifest_url, scoped_refptr<DelegateReference> delegate_ref) { | 221 const GURL& manifest_url, scoped_refptr<DelegateReference> delegate_ref) { |
| 214 scoped_refptr<AppCacheGroup> group(working_set_.GetGroup(manifest_url)); | 222 scoped_refptr<AppCacheGroup> group(working_set_.GetGroup(manifest_url)); |
| 215 | 223 |
| 216 // Newly created groups are not put in the stored_groups collection | 224 // Newly created groups are not put in the stored_groups collection |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 if (delegate) | 257 if (delegate) |
| 250 delegate->OnGroupAndNewestCacheStored( | 258 delegate->OnGroupAndNewestCacheStored( |
| 251 group.get(), newest_cache.get(), true, false); | 259 group.get(), newest_cache.get(), true, false); |
| 252 } | 260 } |
| 253 | 261 |
| 254 namespace { | 262 namespace { |
| 255 | 263 |
| 256 struct FoundCandidate { | 264 struct FoundCandidate { |
| 257 GURL namespace_entry_url; | 265 GURL namespace_entry_url; |
| 258 AppCacheEntry entry; | 266 AppCacheEntry entry; |
| 259 int64 cache_id; | 267 int64_t cache_id; |
| 260 int64 group_id; | 268 int64_t group_id; |
| 261 GURL manifest_url; | 269 GURL manifest_url; |
| 262 bool is_cache_in_use; | 270 bool is_cache_in_use; |
| 263 | 271 |
| 264 FoundCandidate() | 272 FoundCandidate() |
| 265 : cache_id(kAppCacheNoCacheId), group_id(0), is_cache_in_use(false) {} | 273 : cache_id(kAppCacheNoCacheId), group_id(0), is_cache_in_use(false) {} |
| 266 }; | 274 }; |
| 267 | 275 |
| 268 void MaybeTakeNewNamespaceEntry( | 276 void MaybeTakeNewNamespaceEntry( |
| 269 AppCacheNamespaceType namespace_type, | 277 AppCacheNamespaceType namespace_type, |
| 270 const AppCacheEntry &entry, | 278 const AppCacheEntry &entry, |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 } | 480 } |
| 473 | 481 |
| 474 void MockAppCacheStorage::RunOnePendingTask() { | 482 void MockAppCacheStorage::RunOnePendingTask() { |
| 475 DCHECK(!pending_tasks_.empty()); | 483 DCHECK(!pending_tasks_.empty()); |
| 476 base::Closure task = pending_tasks_.front(); | 484 base::Closure task = pending_tasks_.front(); |
| 477 pending_tasks_.pop_front(); | 485 pending_tasks_.pop_front(); |
| 478 task.Run(); | 486 task.Run(); |
| 479 } | 487 } |
| 480 | 488 |
| 481 void MockAppCacheStorage::AddStoredCache(AppCache* cache) { | 489 void MockAppCacheStorage::AddStoredCache(AppCache* cache) { |
| 482 int64 cache_id = cache->cache_id(); | 490 int64_t cache_id = cache->cache_id(); |
| 483 if (stored_caches_.find(cache_id) == stored_caches_.end()) { | 491 if (stored_caches_.find(cache_id) == stored_caches_.end()) { |
| 484 stored_caches_.insert( | 492 stored_caches_.insert( |
| 485 StoredCacheMap::value_type(cache_id, make_scoped_refptr(cache))); | 493 StoredCacheMap::value_type(cache_id, make_scoped_refptr(cache))); |
| 486 } | 494 } |
| 487 } | 495 } |
| 488 | 496 |
| 489 void MockAppCacheStorage::RemoveStoredCache(AppCache* cache) { | 497 void MockAppCacheStorage::RemoveStoredCache(AppCache* cache) { |
| 490 // Do not remove from the working set, active caches are still usable | 498 // Do not remove from the working set, active caches are still usable |
| 491 // and may be looked up by id until they fall out of use. | 499 // and may be looked up by id until they fall out of use. |
| 492 stored_caches_.erase(cache->cache_id()); | 500 stored_caches_.erase(cache->cache_id()); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 bool MockAppCacheStorage::ShouldCacheLoadAppearAsync(const AppCache* cache) { | 557 bool MockAppCacheStorage::ShouldCacheLoadAppearAsync(const AppCache* cache) { |
| 550 if (!cache) | 558 if (!cache) |
| 551 return true; | 559 return true; |
| 552 | 560 |
| 553 // If the 'stored' ref is the only ref, real storage will have to load from | 561 // If the 'stored' ref is the only ref, real storage will have to load from |
| 554 // the database. | 562 // the database. |
| 555 return IsCacheStored(cache) && cache->HasOneRef(); | 563 return IsCacheStored(cache) && cache->HasOneRef(); |
| 556 } | 564 } |
| 557 | 565 |
| 558 } // namespace content | 566 } // namespace content |
| OLD | NEW |