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

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

Issue 326002: Add storage code to appcache update process. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month 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 <deque> 8 #include <deque>
9 #include <map> 9 #include <map>
10 10
(...skipping 23 matching lines...) Expand all
34 virtual void FindResponseForMainRequest(const GURL& url, Delegate* delegate); 34 virtual void FindResponseForMainRequest(const GURL& url, Delegate* delegate);
35 virtual void MarkEntryAsForeign(const GURL& entry_url, int64 cache_id); 35 virtual void MarkEntryAsForeign(const GURL& entry_url, int64 cache_id);
36 virtual void MakeGroupObsolete(AppCacheGroup* group, Delegate* delegate); 36 virtual void MakeGroupObsolete(AppCacheGroup* group, Delegate* delegate);
37 virtual AppCacheResponseReader* CreateResponseReader( 37 virtual AppCacheResponseReader* CreateResponseReader(
38 const GURL& manifest_url, int64 response_id); 38 const GURL& manifest_url, int64 response_id);
39 virtual AppCacheResponseWriter* CreateResponseWriter(const GURL& origin); 39 virtual AppCacheResponseWriter* CreateResponseWriter(const GURL& origin);
40 virtual void DoomResponses( 40 virtual void DoomResponses(
41 const GURL& manifest_url, const std::vector<int64>& response_ids); 41 const GURL& manifest_url, const std::vector<int64>& response_ids);
42 42
43 private: 43 private:
44 friend class AppCacheUpdateJobTest;
45
44 typedef base::hash_map<int64, scoped_refptr<AppCache> > StoredCacheMap; 46 typedef base::hash_map<int64, scoped_refptr<AppCache> > StoredCacheMap;
45 typedef std::map<GURL, scoped_refptr<AppCacheGroup> > StoredGroupMap; 47 typedef std::map<GURL, scoped_refptr<AppCacheGroup> > StoredGroupMap;
46 typedef std::set<int64> DoomedResponseIds; 48 typedef std::set<int64> DoomedResponseIds;
47 49
48 void ProcessLoadCache( 50 void ProcessLoadCache(
49 int64 id, scoped_refptr<DelegateReference> delegate_ref); 51 int64 id, scoped_refptr<DelegateReference> delegate_ref);
50 void ProcessLoadOrCreateGroup( 52 void ProcessLoadOrCreateGroup(
51 const GURL& manifest_url, scoped_refptr<DelegateReference> delegate_ref); 53 const GURL& manifest_url, scoped_refptr<DelegateReference> delegate_ref);
52 void ProcessStoreGroupAndNewestCache( 54 void ProcessStoreGroupAndNewestCache(
53 scoped_refptr<AppCacheGroup> group, scoped_refptr<AppCache> newest_cache, 55 scoped_refptr<AppCacheGroup> group, scoped_refptr<AppCache> newest_cache,
54 scoped_refptr<DelegateReference> delegate_ref); 56 scoped_refptr<DelegateReference> delegate_ref);
55 void ProcessMakeGroupObsolete( 57 void ProcessMakeGroupObsolete(
56 scoped_refptr<AppCacheGroup> group, 58 scoped_refptr<AppCacheGroup> group,
57 scoped_refptr<DelegateReference> delegate_ref); 59 scoped_refptr<DelegateReference> delegate_ref);
58 void ProcessFindResponseForMainRequest( 60 void ProcessFindResponseForMainRequest(
59 const GURL& url, scoped_refptr<DelegateReference> delegate_ref); 61 const GURL& url, scoped_refptr<DelegateReference> delegate_ref);
60 62
61 void ScheduleTask(Task* task); 63 void ScheduleTask(Task* task);
62 void RunOnePendingTask(); 64 void RunOnePendingTask();
63 65
64 void AddStoredCache(AppCache* cache); 66 void AddStoredCache(AppCache* cache);
65 void RemoveStoredCache(AppCache* cache); 67 void RemoveStoredCache(AppCache* cache);
66 void RemoveStoredCaches(const AppCacheGroup::Caches& caches); 68 void RemoveStoredCaches(const AppCacheGroup::Caches& caches);
67 bool IsCacheStored(const AppCache* cache) { 69 bool IsCacheStored(const AppCache* cache) {
68 return stored_caches_.find(cache->cache_id()) != stored_caches_.end(); 70 return stored_caches_.find(cache->cache_id()) != stored_caches_.end();
69 } 71 }
70 72
71 void AddStoredGroup(AppCacheGroup* group); 73 void AddStoredGroup(AppCacheGroup* group);
72 void RemoveStoredGroup(AppCacheGroup* group); 74 void RemoveStoredGroup(AppCacheGroup* group);
75 bool IsGroupStored(const AppCacheGroup* group) {
76 return stored_groups_.find(group->manifest_url()) != stored_groups_.end();
77 }
73 78
74 // These helpers determine when certain operations should complete 79 // These helpers determine when certain operations should complete
75 // asynchronously vs synchronously to faithfully mimic, or mock, 80 // asynchronously vs synchronously to faithfully mimic, or mock,
76 // the behavior of the real implemenation of the AppCacheStorage 81 // the behavior of the real implemenation of the AppCacheStorage
77 // interface. 82 // interface.
78 bool ShouldGroupLoadAppearAsync(const AppCacheGroup* group); 83 bool ShouldGroupLoadAppearAsync(const AppCacheGroup* group);
79 bool ShouldCacheLoadAppearAsync(const AppCache* cache); 84 bool ShouldCacheLoadAppearAsync(const AppCache* cache);
80 85
81 // Lazily constructed in-memory disk cache. 86 // Lazily constructed in-memory disk cache.
82 disk_cache::Backend* disk_cache() { 87 disk_cache::Backend* disk_cache() {
83 if (!disk_cache_.get()) { 88 if (!disk_cache_.get()) {
84 const int kMaxCacheSize = 10 * 1024 * 1024; 89 const int kMaxCacheSize = 10 * 1024 * 1024;
85 disk_cache_.reset(disk_cache::CreateInMemoryCacheBackend(kMaxCacheSize)); 90 disk_cache_.reset(disk_cache::CreateInMemoryCacheBackend(kMaxCacheSize));
86 } 91 }
87 return disk_cache_.get(); 92 return disk_cache_.get();
88 } 93 }
89 94
95 // Simulate failures for testing.
96 void SimulateMakeGroupObsoleteFailure() {
97 simulate_make_group_obsolete_failure_ = true;
98 }
99 void SimulateStoreGroupAndNewestCacheFailure() {
100 simulate_store_group_and_newest_cache_failure_ = true;
101 }
102
90 StoredCacheMap stored_caches_; 103 StoredCacheMap stored_caches_;
91 StoredGroupMap stored_groups_; 104 StoredGroupMap stored_groups_;
92 DoomedResponseIds doomed_response_ids_; 105 DoomedResponseIds doomed_response_ids_;
93 scoped_ptr<disk_cache::Backend> disk_cache_; 106 scoped_ptr<disk_cache::Backend> disk_cache_;
94 std::deque<Task*> pending_tasks_; 107 std::deque<Task*> pending_tasks_;
95 ScopedRunnableMethodFactory<MockAppCacheStorage> method_factory_; 108 ScopedRunnableMethodFactory<MockAppCacheStorage> method_factory_;
96 109
110 bool simulate_make_group_obsolete_failure_;
111 bool simulate_store_group_and_newest_cache_failure_;
112
97 FRIEND_TEST(MockAppCacheStorageTest, CreateGroup); 113 FRIEND_TEST(MockAppCacheStorageTest, CreateGroup);
98 FRIEND_TEST(MockAppCacheStorageTest, LoadCache_FarHit); 114 FRIEND_TEST(MockAppCacheStorageTest, LoadCache_FarHit);
99 FRIEND_TEST(MockAppCacheStorageTest, LoadGroupAndCache_FarHit); 115 FRIEND_TEST(MockAppCacheStorageTest, LoadGroupAndCache_FarHit);
100 FRIEND_TEST(MockAppCacheStorageTest, MakeGroupObsolete); 116 FRIEND_TEST(MockAppCacheStorageTest, MakeGroupObsolete);
101 FRIEND_TEST(MockAppCacheStorageTest, StoreNewGroup); 117 FRIEND_TEST(MockAppCacheStorageTest, StoreNewGroup);
102 FRIEND_TEST(MockAppCacheStorageTest, StoreExistingGroup); 118 FRIEND_TEST(MockAppCacheStorageTest, StoreExistingGroup);
103 DISALLOW_COPY_AND_ASSIGN(MockAppCacheStorage); 119 DISALLOW_COPY_AND_ASSIGN(MockAppCacheStorage);
104 }; 120 };
105 121
106 } // namespace appcache 122 } // namespace appcache
107 123
108 #endif // WEBKIT_APPCACHE_MOCK_APPCACHE_STORAGE_H_ 124 #endif // WEBKIT_APPCACHE_MOCK_APPCACHE_STORAGE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698