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

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

Issue 269062: AppCacheResponse storage implementation (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 WEBKIT_APPCACHE_MOCK_APPCACHE_STORAGE_H_ 5 #ifndef WEBKIT_APPCACHE_MOCK_APPCACHE_STORAGE_H_
6 #define WEBKIT_APPCACHE_MOCK_APPCACHE_STORAGE_H_ 6 #define WEBKIT_APPCACHE_MOCK_APPCACHE_STORAGE_H_
7 7
8 #include <map>
9
10 #include "base/hash_tables.h"
11 #include "base/scoped_ptr.h"
12 #include "net/disk_cache/disk_cache.h"
13 #include "webkit/appcache/appcache.h"
14 #include "webkit/appcache/appcache_group.h"
8 #include "webkit/appcache/appcache_storage.h" 15 #include "webkit/appcache/appcache_storage.h"
9 16
10 namespace appcache { 17 namespace appcache {
11 18
12 // For use in unit tests. 19 // For use in unit tests.
13 // Note: This class is also being used to bootstrap our development efforts. 20 // Note: This class is also being used to bootstrap our development efforts.
14 // We can get layout tests up and running, and back fill with real storage 21 // We can get layout tests up and running, and back fill with real storage
15 // somewhat in parallel. 22 // somewhat in parallel.
16 class MockAppCacheStorage : public AppCacheStorage { 23 class MockAppCacheStorage : public AppCacheStorage {
17 public: 24 public:
18 explicit MockAppCacheStorage(AppCacheService* service); 25 explicit MockAppCacheStorage(AppCacheService* service);
19 virtual void LoadCache(int64 id, Delegate* delegate); 26 virtual void LoadCache(int64 id, Delegate* delegate);
20 virtual void LoadOrCreateGroup(const GURL& manifest_url, Delegate* delegate); 27 virtual void LoadOrCreateGroup(const GURL& manifest_url, Delegate* delegate);
21 virtual void LoadResponseInfo(
22 const GURL& manifest_url, int64 response_id, Delegate* delegate);
23 virtual void StoreGroupAndNewestCache( 28 virtual void StoreGroupAndNewestCache(
24 AppCacheGroup* group, Delegate* delegate); 29 AppCacheGroup* group, Delegate* delegate);
25 virtual void FindResponseForMainRequest(const GURL& url, Delegate* delegate); 30 virtual void FindResponseForMainRequest(const GURL& url, Delegate* delegate);
26 virtual void CancelDelegateCallbacks(Delegate* delegate);
27 virtual void MarkEntryAsForeign(const GURL& entry_url, int64 cache_id); 31 virtual void MarkEntryAsForeign(const GURL& entry_url, int64 cache_id);
28 virtual void MarkGroupAsObsolete(AppCacheGroup* group, Delegate* delegate); 32 virtual void MarkGroupAsObsolete(AppCacheGroup* group, Delegate* delegate);
29 virtual AppCacheResponseReader* CreateResponseReader( 33 virtual AppCacheResponseReader* CreateResponseReader(
30 const GURL& manifest_url, int64 response_id); 34 const GURL& manifest_url, int64 response_id);
31 virtual AppCacheResponseWriter* CreateResponseWriter(const GURL& origin); 35 virtual AppCacheResponseWriter* CreateResponseWriter(const GURL& origin);
32 virtual void DoomResponses( 36 virtual void DoomResponses(
33 const GURL& manifest_url, const std::vector<int64>& response_ids); 37 const GURL& manifest_url, const std::vector<int64>& response_ids);
38
39 private:
40 typedef base::hash_map<int64, scoped_refptr<AppCache> > StoredCacheMap;
41 typedef std::map<GURL, scoped_refptr<AppCacheGroup> > StoredGroupMap;
42
43 void AddStoredCache(AppCache* cache);
44 void RemoveStoredCache(AppCache* cache);
45 AppCache* GetStoredCache(int64 id) {
46 StoredCacheMap::iterator it = stored_caches_.find(id);
47 return (it != stored_caches_.end()) ? it->second : NULL;
48 }
49
50 void AddStoredGroup(AppCacheGroup* group);
51 void RemoveStoredGroup(AppCacheGroup* group);
52 AppCacheGroup* GetStoredGroup(const GURL& manifest_url) {
53 StoredGroupMap::iterator it = stored_groups_.find(manifest_url);
54 return (it != stored_groups_.end()) ? it->second : NULL;
55 }
56
57 // Lazily constructed in-memory disk cache.
58 disk_cache::Backend* disk_cache() {
59 if (!disk_cache_.get()) {
60 const int kMaxCacheSize = 10 * 1024 * 1024;
61 disk_cache_.reset(disk_cache::CreateInMemoryCacheBackend(kMaxCacheSize));
62 }
63 return disk_cache_.get();
64 }
65
66 StoredCacheMap stored_caches_;
67 StoredGroupMap stored_groups_;
68 scoped_ptr<disk_cache::Backend> disk_cache_;
34 }; 69 };
35 70
36 } // namespace appcache 71 } // namespace appcache
37 72
38 #endif // WEBKIT_APPCACHE_MOCK_APPCACHE_STORAGE_H_ 73 #endif // WEBKIT_APPCACHE_MOCK_APPCACHE_STORAGE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698