OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/ref_counted.h" | 9 #include "base/ref_counted.h" |
10 #include "base/stl_util-inl.h" | 10 #include "base/stl_util-inl.h" |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 RemoveStoredCaches(copy); | 205 RemoveStoredCaches(copy); |
206 } | 206 } |
207 | 207 |
208 if (delegate) | 208 if (delegate) |
209 delegate->OnGroupAndNewestCacheStored(group, newest_cache, true, false); | 209 delegate->OnGroupAndNewestCacheStored(group, newest_cache, true, false); |
210 } | 210 } |
211 | 211 |
212 namespace { | 212 namespace { |
213 | 213 |
214 struct FoundCandidate { | 214 struct FoundCandidate { |
| 215 GURL url; |
215 AppCacheEntry entry; | 216 AppCacheEntry entry; |
216 int64 cache_id; | 217 int64 cache_id; |
217 GURL manifest_url; | 218 GURL manifest_url; |
218 bool is_cache_in_use; | 219 bool is_cache_in_use; |
219 | 220 |
220 FoundCandidate() : cache_id(kNoCacheId), is_cache_in_use(false) {} | 221 FoundCandidate() : cache_id(kNoCacheId), is_cache_in_use(false) {} |
221 }; | 222 }; |
222 | 223 |
223 } // namespace | 224 } // namespace |
224 | 225 |
225 void MockAppCacheStorage::ProcessFindResponseForMainRequest( | 226 void MockAppCacheStorage::ProcessFindResponseForMainRequest( |
226 const GURL& url, scoped_refptr<DelegateReference> delegate_ref) { | 227 const GURL& url, scoped_refptr<DelegateReference> delegate_ref) { |
227 if (simulate_find_main_resource_) { | 228 if (simulate_find_main_resource_) { |
228 simulate_find_main_resource_ = false; | 229 simulate_find_main_resource_ = false; |
229 if (delegate_ref->delegate) { | 230 if (delegate_ref->delegate) { |
230 delegate_ref->delegate->OnMainResponseFound( | 231 delegate_ref->delegate->OnMainResponseFound( |
231 url, simulated_found_entry_, simulated_found_fallback_entry_, | 232 url, simulated_found_entry_, |
| 233 simulated_found_fallback_url_, simulated_found_fallback_entry_, |
232 simulated_found_cache_id_, simulated_found_manifest_url_, false); | 234 simulated_found_cache_id_, simulated_found_manifest_url_, false); |
233 } | 235 } |
234 return; | 236 return; |
235 } | 237 } |
236 | 238 |
237 // This call has no persistent side effects, if the delegate has gone | 239 // This call has no persistent side effects, if the delegate has gone |
238 // away, we can just bail out early. | 240 // away, we can just bail out early. |
239 if (!delegate_ref->delegate) | 241 if (!delegate_ref->delegate) |
240 return; | 242 return; |
241 | 243 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 (found_entry.has_response_id() && found_entry.IsForeign()) || | 278 (found_entry.has_response_id() && found_entry.IsForeign()) || |
277 (found_fallback_entry.has_response_id() && | 279 (found_fallback_entry.has_response_id() && |
278 found_fallback_entry.IsForeign())) { | 280 found_fallback_entry.IsForeign())) { |
279 continue; | 281 continue; |
280 } | 282 } |
281 | 283 |
282 // We have a bias for hits from caches that are in use. | 284 // We have a bias for hits from caches that are in use. |
283 bool is_in_use = IsCacheStored(cache) && !cache->HasOneRef(); | 285 bool is_in_use = IsCacheStored(cache) && !cache->HasOneRef(); |
284 | 286 |
285 if (found_entry.has_response_id()) { | 287 if (found_entry.has_response_id()) { |
| 288 found_candidate.url = url; |
286 found_candidate.entry = found_entry; | 289 found_candidate.entry = found_entry; |
287 found_candidate.cache_id = cache->cache_id(); | 290 found_candidate.cache_id = cache->cache_id(); |
288 found_candidate.manifest_url = group->manifest_url(); | 291 found_candidate.manifest_url = group->manifest_url(); |
289 found_candidate.is_cache_in_use = is_in_use; | 292 found_candidate.is_cache_in_use = is_in_use; |
290 if (is_in_use) | 293 if (is_in_use) |
291 break; // We break out of the loop with this direct hit. | 294 break; // We break out of the loop with this direct hit. |
292 } else { | 295 } else { |
293 DCHECK(found_fallback_entry.has_response_id()); | 296 DCHECK(found_fallback_entry.has_response_id()); |
294 | 297 |
295 bool take_new_candidate = true; | 298 bool take_new_candidate = true; |
(...skipping 10 matching lines...) Expand all Loading... |
306 take_new_candidate = true; | 309 take_new_candidate = true; |
307 } else if (found_length == candidate_length && | 310 } else if (found_length == candidate_length && |
308 is_in_use && !found_fallback_candidate.is_cache_in_use) { | 311 is_in_use && !found_fallback_candidate.is_cache_in_use) { |
309 take_new_candidate = true; | 312 take_new_candidate = true; |
310 } else { | 313 } else { |
311 take_new_candidate = false; | 314 take_new_candidate = false; |
312 } | 315 } |
313 } | 316 } |
314 | 317 |
315 if (take_new_candidate) { | 318 if (take_new_candidate) { |
| 319 found_fallback_candidate.url = |
| 320 cache->GetFallbackEntryUrl(found_fallback_namespace); |
316 found_fallback_candidate.entry = found_fallback_entry; | 321 found_fallback_candidate.entry = found_fallback_entry; |
317 found_fallback_candidate.cache_id = cache->cache_id(); | 322 found_fallback_candidate.cache_id = cache->cache_id(); |
318 found_fallback_candidate.manifest_url = group->manifest_url(); | 323 found_fallback_candidate.manifest_url = group->manifest_url(); |
319 found_fallback_candidate.is_cache_in_use = is_in_use; | 324 found_fallback_candidate.is_cache_in_use = is_in_use; |
320 found_fallback_candidate_namespace = found_fallback_namespace; | 325 found_fallback_candidate_namespace = found_fallback_namespace; |
321 } | 326 } |
322 } | 327 } |
323 } | 328 } |
324 | 329 |
325 // Found a direct hit. | 330 // Found a direct hit. |
326 if (found_candidate.entry.has_response_id()) { | 331 if (found_candidate.entry.has_response_id()) { |
327 delegate_ref->delegate->OnMainResponseFound( | 332 delegate_ref->delegate->OnMainResponseFound( |
328 url, found_candidate.entry, AppCacheEntry(), | 333 url, found_candidate.entry, GURL(), AppCacheEntry(), |
329 found_candidate.cache_id, found_candidate.manifest_url, false); | 334 found_candidate.cache_id, found_candidate.manifest_url, false); |
330 return; | 335 return; |
331 } | 336 } |
332 | 337 |
333 // Found a fallback namespace. | 338 // Found a fallback namespace. |
334 if (found_fallback_candidate.entry.has_response_id()) { | 339 if (found_fallback_candidate.entry.has_response_id()) { |
335 delegate_ref->delegate->OnMainResponseFound( | 340 delegate_ref->delegate->OnMainResponseFound( |
336 url, AppCacheEntry(), found_fallback_candidate.entry, | 341 url, AppCacheEntry(), |
| 342 found_fallback_candidate.url, |
| 343 found_fallback_candidate.entry, |
337 found_fallback_candidate.cache_id, | 344 found_fallback_candidate.cache_id, |
338 found_fallback_candidate.manifest_url, false); | 345 found_fallback_candidate.manifest_url, false); |
339 return; | 346 return; |
340 } | 347 } |
341 | 348 |
342 // Didn't find anything. | 349 // Didn't find anything. |
343 delegate_ref->delegate->OnMainResponseFound( | 350 delegate_ref->delegate->OnMainResponseFound( |
344 url, AppCacheEntry(), AppCacheEntry(), kNoCacheId, GURL(), false); | 351 url, AppCacheEntry(), GURL(), AppCacheEntry(), kNoCacheId, GURL(), false); |
345 } | 352 } |
346 | 353 |
347 void MockAppCacheStorage::ProcessMakeGroupObsolete( | 354 void MockAppCacheStorage::ProcessMakeGroupObsolete( |
348 scoped_refptr<AppCacheGroup> group, | 355 scoped_refptr<AppCacheGroup> group, |
349 scoped_refptr<DelegateReference> delegate_ref) { | 356 scoped_refptr<DelegateReference> delegate_ref) { |
350 if (simulate_make_group_obsolete_failure_) { | 357 if (simulate_make_group_obsolete_failure_) { |
351 if (delegate_ref->delegate) | 358 if (delegate_ref->delegate) |
352 delegate_ref->delegate->OnGroupMadeObsolete(group, false); | 359 delegate_ref->delegate->OnGroupMadeObsolete(group, false); |
353 return; | 360 return; |
354 } | 361 } |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 bool MockAppCacheStorage::ShouldCacheLoadAppearAsync(const AppCache* cache) { | 462 bool MockAppCacheStorage::ShouldCacheLoadAppearAsync(const AppCache* cache) { |
456 if (!cache) | 463 if (!cache) |
457 return true; | 464 return true; |
458 | 465 |
459 // If the 'stored' ref is the only ref, real storage will have to load from | 466 // If the 'stored' ref is the only ref, real storage will have to load from |
460 // the database. | 467 // the database. |
461 return IsCacheStored(cache) && cache->HasOneRef(); | 468 return IsCacheStored(cache) && cache->HasOneRef(); |
462 } | 469 } |
463 | 470 |
464 } // namespace appcache | 471 } // namespace appcache |
OLD | NEW |