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

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

Issue 7031065: AppCache + Quota integration (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 6 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
« no previous file with comments | « webkit/appcache/mock_appcache_storage.h ('k') | webkit/appcache/webkit_appcache.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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-inl.h" 10 #include "base/stl_util-inl.h"
11 #include "webkit/appcache/appcache.h" 11 #include "webkit/appcache/appcache.h"
12 #include "webkit/appcache/appcache_entry.h" 12 #include "webkit/appcache/appcache_entry.h"
13 #include "webkit/appcache/appcache_group.h" 13 #include "webkit/appcache/appcache_group.h"
14 #include "webkit/appcache/appcache_response.h" 14 #include "webkit/appcache/appcache_response.h"
15 #include "webkit/appcache/appcache_service.h"
15 16
16 // This is a quick and easy 'mock' implementation of the storage interface 17 // This is a quick and easy 'mock' implementation of the storage interface
17 // that doesn't put anything to disk. 18 // that doesn't put anything to disk.
18 // 19 //
19 // We simply add an extra reference to objects when they're put in storage, 20 // We simply add an extra reference to objects when they're put in storage,
20 // and remove the extra reference when they are removed from storage. 21 // and remove the extra reference when they are removed from storage.
21 // Responses are never really removed from the in-memory disk cache. 22 // Responses are never really removed from the in-memory disk cache.
22 // Delegate callbacks are made asyncly to appropiately mimic what will 23 // Delegate callbacks are made asyncly to appropiately mimic what will
23 // happen with a real disk-backed storage impl that involves IO on a 24 // happen with a real disk-backed storage impl that involves IO on a
24 // background thread. 25 // background thread.
(...skipping 11 matching lines...) Expand all
36 simulated_found_network_namespace_(false) { 37 simulated_found_network_namespace_(false) {
37 last_cache_id_ = 0; 38 last_cache_id_ = 0;
38 last_group_id_ = 0; 39 last_group_id_ = 0;
39 last_response_id_ = 0; 40 last_response_id_ = 0;
40 } 41 }
41 42
42 MockAppCacheStorage::~MockAppCacheStorage() { 43 MockAppCacheStorage::~MockAppCacheStorage() {
43 STLDeleteElements(&pending_tasks_); 44 STLDeleteElements(&pending_tasks_);
44 } 45 }
45 46
47 void MockAppCacheStorage::GetAllInfo(Delegate* delegate) {
48 ScheduleTask(method_factory_.NewRunnableMethod(
49 &MockAppCacheStorage::ProcessGetAllInfo,
50 make_scoped_refptr(GetOrCreateDelegateReference(delegate))));
51 }
52
46 void MockAppCacheStorage::LoadCache(int64 id, Delegate* delegate) { 53 void MockAppCacheStorage::LoadCache(int64 id, Delegate* delegate) {
47 DCHECK(delegate); 54 DCHECK(delegate);
48 AppCache* cache = working_set_.GetCache(id); 55 AppCache* cache = working_set_.GetCache(id);
49 if (ShouldCacheLoadAppearAsync(cache)) { 56 if (ShouldCacheLoadAppearAsync(cache)) {
50 ScheduleTask(method_factory_.NewRunnableMethod( 57 ScheduleTask(method_factory_.NewRunnableMethod(
51 &MockAppCacheStorage::ProcessLoadCache, 58 &MockAppCacheStorage::ProcessLoadCache,
52 id, make_scoped_refptr(GetOrCreateDelegateReference(delegate)))); 59 id, make_scoped_refptr(GetOrCreateDelegateReference(delegate))));
53 return; 60 return;
54 } 61 }
55 ProcessLoadCache(id, GetOrCreateDelegateReference(delegate)); 62 ProcessLoadCache(id, GetOrCreateDelegateReference(delegate));
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 const GURL& manifest_url, const std::vector<int64>& response_ids) { 164 const GURL& manifest_url, const std::vector<int64>& response_ids) {
158 // We don't bother with actually removing responses from the disk-cache, 165 // We don't bother with actually removing responses from the disk-cache,
159 // just keep track of which ids have been doomed or deleted 166 // just keep track of which ids have been doomed or deleted
160 std::vector<int64>::const_iterator it = response_ids.begin(); 167 std::vector<int64>::const_iterator it = response_ids.begin();
161 while (it != response_ids.end()) { 168 while (it != response_ids.end()) {
162 doomed_response_ids_.insert(*it); 169 doomed_response_ids_.insert(*it);
163 ++it; 170 ++it;
164 } 171 }
165 } 172 }
166 173
174 void MockAppCacheStorage::ProcessGetAllInfo(
175 scoped_refptr<DelegateReference> delegate_ref) {
176 if (delegate_ref->delegate)
177 delegate_ref->delegate->OnAllInfo(simulated_appcache_info_);
178 }
179
167 void MockAppCacheStorage::ProcessLoadCache( 180 void MockAppCacheStorage::ProcessLoadCache(
168 int64 id, scoped_refptr<DelegateReference> delegate_ref) { 181 int64 id, scoped_refptr<DelegateReference> delegate_ref) {
169 AppCache* cache = working_set_.GetCache(id); 182 AppCache* cache = working_set_.GetCache(id);
170 if (delegate_ref->delegate) 183 if (delegate_ref->delegate)
171 delegate_ref->delegate->OnCacheLoaded(cache, id); 184 delegate_ref->delegate->OnCacheLoaded(cache, id);
172 } 185 }
173 186
174 void MockAppCacheStorage::ProcessLoadOrCreateGroup( 187 void MockAppCacheStorage::ProcessLoadOrCreateGroup(
175 const GURL& manifest_url, scoped_refptr<DelegateReference> delegate_ref) { 188 const GURL& manifest_url, scoped_refptr<DelegateReference> delegate_ref) {
176 scoped_refptr<AppCacheGroup> group(working_set_.GetGroup(manifest_url)); 189 scoped_refptr<AppCacheGroup> group(working_set_.GetGroup(manifest_url));
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 bool MockAppCacheStorage::ShouldCacheLoadAppearAsync(const AppCache* cache) { 481 bool MockAppCacheStorage::ShouldCacheLoadAppearAsync(const AppCache* cache) {
469 if (!cache) 482 if (!cache)
470 return true; 483 return true;
471 484
472 // If the 'stored' ref is the only ref, real storage will have to load from 485 // If the 'stored' ref is the only ref, real storage will have to load from
473 // the database. 486 // the database.
474 return IsCacheStored(cache) && cache->HasOneRef(); 487 return IsCacheStored(cache) && cache->HasOneRef();
475 } 488 }
476 489
477 } // namespace appcache 490 } // namespace appcache
OLDNEW
« no previous file with comments | « webkit/appcache/mock_appcache_storage.h ('k') | webkit/appcache/webkit_appcache.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698