Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(56)

Side by Side Diff: webkit/appcache/mock_appcache_storage.cc

Issue 8343018: More groundwork for flat file based response storage. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #include "webkit/appcache/mock_appcache_storage.h" 5 #include "webkit/appcache/mock_appcache_storage.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 16 matching lines...) Expand all
27 namespace appcache { 27 namespace appcache {
28 28
29 MockAppCacheStorage::MockAppCacheStorage(AppCacheService* service) 29 MockAppCacheStorage::MockAppCacheStorage(AppCacheService* service)
30 : AppCacheStorage(service), 30 : AppCacheStorage(service),
31 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), 31 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)),
32 simulate_make_group_obsolete_failure_(false), 32 simulate_make_group_obsolete_failure_(false),
33 simulate_store_group_and_newest_cache_failure_(false), 33 simulate_store_group_and_newest_cache_failure_(false),
34 simulate_find_main_resource_(false), 34 simulate_find_main_resource_(false),
35 simulate_find_sub_resource_(false), 35 simulate_find_sub_resource_(false),
36 simulated_found_cache_id_(kNoCacheId), 36 simulated_found_cache_id_(kNoCacheId),
37 simulated_found_group_id_(0),
37 simulated_found_network_namespace_(false) { 38 simulated_found_network_namespace_(false) {
38 last_cache_id_ = 0; 39 last_cache_id_ = 0;
39 last_group_id_ = 0; 40 last_group_id_ = 0;
40 last_response_id_ = 0; 41 last_response_id_ = 0;
41 } 42 }
42 43
43 MockAppCacheStorage::~MockAppCacheStorage() { 44 MockAppCacheStorage::~MockAppCacheStorage() {
44 STLDeleteElements(&pending_tasks_); 45 STLDeleteElements(&pending_tasks_);
45 } 46 }
46 47
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 DCHECK(group && delegate); 140 DCHECK(group && delegate);
140 141
141 // Always make this method look async. 142 // Always make this method look async.
142 ScheduleTask(method_factory_.NewRunnableMethod( 143 ScheduleTask(method_factory_.NewRunnableMethod(
143 &MockAppCacheStorage::ProcessMakeGroupObsolete, 144 &MockAppCacheStorage::ProcessMakeGroupObsolete,
144 make_scoped_refptr(group), 145 make_scoped_refptr(group),
145 make_scoped_refptr(GetOrCreateDelegateReference(delegate)))); 146 make_scoped_refptr(GetOrCreateDelegateReference(delegate))));
146 } 147 }
147 148
148 AppCacheResponseReader* MockAppCacheStorage::CreateResponseReader( 149 AppCacheResponseReader* MockAppCacheStorage::CreateResponseReader(
149 const GURL& manifest_url, int64 response_id) { 150 const GURL& manifest_url, int64 group_id, int64 response_id) {
150 if (simulated_reader_.get()) 151 if (simulated_reader_.get())
151 return simulated_reader_.release(); 152 return simulated_reader_.release();
152 return new AppCacheResponseReader(response_id, disk_cache()); 153 return new AppCacheResponseReader(response_id, group_id, disk_cache());
153 } 154 }
154 155
155 AppCacheResponseWriter* MockAppCacheStorage::CreateResponseWriter( 156 AppCacheResponseWriter* MockAppCacheStorage::CreateResponseWriter(
156 const GURL& manifest_url) { 157 const GURL& manifest_url, int64 group_id) {
157 return new AppCacheResponseWriter(NewResponseId(), disk_cache()); 158 return new AppCacheResponseWriter(NewResponseId(), group_id, disk_cache());
158 } 159 }
159 160
160 void MockAppCacheStorage::DoomResponses( 161 void MockAppCacheStorage::DoomResponses(
161 const GURL& manifest_url, const std::vector<int64>& response_ids) { 162 const GURL& manifest_url, const std::vector<int64>& response_ids) {
162 DeleteResponses(manifest_url, response_ids); 163 DeleteResponses(manifest_url, response_ids);
163 } 164 }
164 165
165 void MockAppCacheStorage::DeleteResponses( 166 void MockAppCacheStorage::DeleteResponses(
166 const GURL& manifest_url, const std::vector<int64>& response_ids) { 167 const GURL& manifest_url, const std::vector<int64>& response_ids) {
167 // We don't bother with actually removing responses from the disk-cache, 168 // We don't bother with actually removing responses from the disk-cache,
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 if (delegate) 226 if (delegate)
226 delegate->OnGroupAndNewestCacheStored(group, newest_cache, true, false); 227 delegate->OnGroupAndNewestCacheStored(group, newest_cache, true, false);
227 } 228 }
228 229
229 namespace { 230 namespace {
230 231
231 struct FoundCandidate { 232 struct FoundCandidate {
232 GURL url; 233 GURL url;
233 AppCacheEntry entry; 234 AppCacheEntry entry;
234 int64 cache_id; 235 int64 cache_id;
236 int64 group_id;
235 GURL manifest_url; 237 GURL manifest_url;
236 bool is_cache_in_use; 238 bool is_cache_in_use;
237 239
238 FoundCandidate() : cache_id(kNoCacheId), is_cache_in_use(false) {} 240 FoundCandidate()
241 : cache_id(kNoCacheId), group_id(0), is_cache_in_use(false) {}
239 }; 242 };
240 243
241 } // namespace 244 } // namespace
242 245
243 void MockAppCacheStorage::ProcessFindResponseForMainRequest( 246 void MockAppCacheStorage::ProcessFindResponseForMainRequest(
244 const GURL& url, scoped_refptr<DelegateReference> delegate_ref) { 247 const GURL& url, scoped_refptr<DelegateReference> delegate_ref) {
245 if (simulate_find_main_resource_) { 248 if (simulate_find_main_resource_) {
246 simulate_find_main_resource_ = false; 249 simulate_find_main_resource_ = false;
247 if (delegate_ref->delegate) { 250 if (delegate_ref->delegate) {
248 delegate_ref->delegate->OnMainResponseFound( 251 delegate_ref->delegate->OnMainResponseFound(
249 url, simulated_found_entry_, 252 url, simulated_found_entry_,
250 simulated_found_fallback_url_, simulated_found_fallback_entry_, 253 simulated_found_fallback_url_, simulated_found_fallback_entry_,
251 simulated_found_cache_id_, simulated_found_manifest_url_); 254 simulated_found_cache_id_, simulated_found_group_id_,
255 simulated_found_manifest_url_);
252 } 256 }
253 return; 257 return;
254 } 258 }
255 259
256 // This call has no persistent side effects, if the delegate has gone 260 // This call has no persistent side effects, if the delegate has gone
257 // away, we can just bail out early. 261 // away, we can just bail out early.
258 if (!delegate_ref->delegate) 262 if (!delegate_ref->delegate)
259 return; 263 return;
260 264
261 // TODO(michaeln): The heuristics around choosing amoungst 265 // TODO(michaeln): The heuristics around choosing amoungst
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 continue; 302 continue;
299 } 303 }
300 304
301 // We have a bias for hits from caches that are in use. 305 // We have a bias for hits from caches that are in use.
302 bool is_in_use = IsCacheStored(cache) && !cache->HasOneRef(); 306 bool is_in_use = IsCacheStored(cache) && !cache->HasOneRef();
303 307
304 if (found_entry.has_response_id()) { 308 if (found_entry.has_response_id()) {
305 found_candidate.url = url; 309 found_candidate.url = url;
306 found_candidate.entry = found_entry; 310 found_candidate.entry = found_entry;
307 found_candidate.cache_id = cache->cache_id(); 311 found_candidate.cache_id = cache->cache_id();
312 found_candidate.group_id = group->group_id();
308 found_candidate.manifest_url = group->manifest_url(); 313 found_candidate.manifest_url = group->manifest_url();
309 found_candidate.is_cache_in_use = is_in_use; 314 found_candidate.is_cache_in_use = is_in_use;
310 if (is_in_use) 315 if (is_in_use)
311 break; // We break out of the loop with this direct hit. 316 break; // We break out of the loop with this direct hit.
312 } else { 317 } else {
313 DCHECK(found_fallback_entry.has_response_id()); 318 DCHECK(found_fallback_entry.has_response_id());
314 319
315 bool take_new_candidate = true; 320 bool take_new_candidate = true;
316 321
317 // Does the newly found entry trump our current candidate? 322 // Does the newly found entry trump our current candidate?
(...skipping 12 matching lines...) Expand all
330 } else { 335 } else {
331 take_new_candidate = false; 336 take_new_candidate = false;
332 } 337 }
333 } 338 }
334 339
335 if (take_new_candidate) { 340 if (take_new_candidate) {
336 found_fallback_candidate.url = 341 found_fallback_candidate.url =
337 cache->GetFallbackEntryUrl(found_fallback_namespace); 342 cache->GetFallbackEntryUrl(found_fallback_namespace);
338 found_fallback_candidate.entry = found_fallback_entry; 343 found_fallback_candidate.entry = found_fallback_entry;
339 found_fallback_candidate.cache_id = cache->cache_id(); 344 found_fallback_candidate.cache_id = cache->cache_id();
345 found_fallback_candidate.group_id = group->group_id();
340 found_fallback_candidate.manifest_url = group->manifest_url(); 346 found_fallback_candidate.manifest_url = group->manifest_url();
341 found_fallback_candidate.is_cache_in_use = is_in_use; 347 found_fallback_candidate.is_cache_in_use = is_in_use;
342 found_fallback_candidate_namespace = found_fallback_namespace; 348 found_fallback_candidate_namespace = found_fallback_namespace;
343 } 349 }
344 } 350 }
345 } 351 }
346 352
347 // Found a direct hit. 353 // Found a direct hit.
348 if (found_candidate.entry.has_response_id()) { 354 if (found_candidate.entry.has_response_id()) {
349 delegate_ref->delegate->OnMainResponseFound( 355 delegate_ref->delegate->OnMainResponseFound(
350 url, found_candidate.entry, GURL(), AppCacheEntry(), 356 url, found_candidate.entry, GURL(), AppCacheEntry(),
351 found_candidate.cache_id, found_candidate.manifest_url); 357 found_candidate.cache_id, found_candidate.group_id,
358 found_candidate.manifest_url);
352 return; 359 return;
353 } 360 }
354 361
355 // Found a fallback namespace. 362 // Found a fallback namespace.
356 if (found_fallback_candidate.entry.has_response_id()) { 363 if (found_fallback_candidate.entry.has_response_id()) {
357 delegate_ref->delegate->OnMainResponseFound( 364 delegate_ref->delegate->OnMainResponseFound(
358 url, AppCacheEntry(), 365 url, AppCacheEntry(),
359 found_fallback_candidate.url, 366 found_fallback_candidate.url,
360 found_fallback_candidate.entry, 367 found_fallback_candidate.entry,
361 found_fallback_candidate.cache_id, 368 found_fallback_candidate.cache_id,
369 found_fallback_candidate.group_id,
362 found_fallback_candidate.manifest_url); 370 found_fallback_candidate.manifest_url);
363 return; 371 return;
364 } 372 }
365 373
366 // Didn't find anything. 374 // Didn't find anything.
367 delegate_ref->delegate->OnMainResponseFound( 375 delegate_ref->delegate->OnMainResponseFound(
368 url, AppCacheEntry(), GURL(), AppCacheEntry(), kNoCacheId, GURL()); 376 url, AppCacheEntry(), GURL(), AppCacheEntry(), kNoCacheId, 0, GURL());
369 } 377 }
370 378
371 void MockAppCacheStorage::ProcessMakeGroupObsolete( 379 void MockAppCacheStorage::ProcessMakeGroupObsolete(
372 scoped_refptr<AppCacheGroup> group, 380 scoped_refptr<AppCacheGroup> group,
373 scoped_refptr<DelegateReference> delegate_ref) { 381 scoped_refptr<DelegateReference> delegate_ref) {
374 if (simulate_make_group_obsolete_failure_) { 382 if (simulate_make_group_obsolete_failure_) {
375 if (delegate_ref->delegate) 383 if (delegate_ref->delegate)
376 delegate_ref->delegate->OnGroupMadeObsolete(group, false); 384 delegate_ref->delegate->OnGroupMadeObsolete(group, false);
377 return; 385 return;
378 } 386 }
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 bool MockAppCacheStorage::ShouldCacheLoadAppearAsync(const AppCache* cache) { 491 bool MockAppCacheStorage::ShouldCacheLoadAppearAsync(const AppCache* cache) {
484 if (!cache) 492 if (!cache)
485 return true; 493 return true;
486 494
487 // If the 'stored' ref is the only ref, real storage will have to load from 495 // If the 'stored' ref is the only ref, real storage will have to load from
488 // the database. 496 // the database.
489 return IsCacheStored(cache) && cache->HasOneRef(); 497 return IsCacheStored(cache) && cache->HasOneRef();
490 } 498 }
491 499
492 } // namespace appcache 500 } // namespace appcache
OLDNEW
« no previous file with comments | « webkit/appcache/mock_appcache_storage.h ('k') | webkit/appcache/mock_appcache_storage_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698