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

Side by Side Diff: net/tools/crash_cache/crash_cache.cc

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 // This command-line program generates the set of files needed for the crash- 5 // This command-line program generates the set of files needed for the crash-
6 // cache unit tests (DiskCacheTest,CacheBackend_Recover*). This program only 6 // cache unit tests (DiskCacheTest,CacheBackend_Recover*). This program only
7 // works properly on debug mode, because the crash functionality is not compiled 7 // works properly on debug mode, because the crash functionality is not compiled
8 // on release builds of the cache. 8 // on release builds of the cache.
9 9
10 #include <string> 10 #include <string>
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 81
82 // ----------------------------------------------------------------------- 82 // -----------------------------------------------------------------------
83 83
84 namespace disk_cache { 84 namespace disk_cache {
85 NET_EXPORT_PRIVATE extern RankCrashes g_rankings_crash; 85 NET_EXPORT_PRIVATE extern RankCrashes g_rankings_crash;
86 } 86 }
87 87
88 const char* kCrashEntryName = "the first key"; 88 const char* kCrashEntryName = "the first key";
89 89
90 // Creates the destinaton folder for this run, and returns it on full_path. 90 // Creates the destinaton folder for this run, and returns it on full_path.
91 bool CreateTargetFolder(const base::FilePath& path, RankCrashes action, 91 bool CreateTargetFolder(const base::FilePath& path,
92 RankCrashes action,
92 base::FilePath* full_path) { 93 base::FilePath* full_path) {
93 const char* folders[] = { 94 const char* folders[] = {
94 "", 95 "", "insert_empty1", "insert_empty2", "insert_empty3",
95 "insert_empty1", 96 "insert_one1", "insert_one2", "insert_one3", "insert_load1",
96 "insert_empty2", 97 "insert_load2", "remove_one1", "remove_one2", "remove_one3",
97 "insert_empty3", 98 "remove_one4", "remove_head1", "remove_head2", "remove_head3",
98 "insert_one1", 99 "remove_head4", "remove_tail1", "remove_tail2", "remove_tail3",
99 "insert_one2", 100 "remove_load1", "remove_load2", "remove_load3"};
100 "insert_one3",
101 "insert_load1",
102 "insert_load2",
103 "remove_one1",
104 "remove_one2",
105 "remove_one3",
106 "remove_one4",
107 "remove_head1",
108 "remove_head2",
109 "remove_head3",
110 "remove_head4",
111 "remove_tail1",
112 "remove_tail2",
113 "remove_tail3",
114 "remove_load1",
115 "remove_load2",
116 "remove_load3"
117 };
118 COMPILE_ASSERT(arraysize(folders) == disk_cache::MAX_CRASH, sync_folders); 101 COMPILE_ASSERT(arraysize(folders) == disk_cache::MAX_CRASH, sync_folders);
119 DCHECK(action > disk_cache::NO_CRASH && action < disk_cache::MAX_CRASH); 102 DCHECK(action > disk_cache::NO_CRASH && action < disk_cache::MAX_CRASH);
120 103
121 *full_path = path.AppendASCII(folders[action]); 104 *full_path = path.AppendASCII(folders[action]);
122 105
123 if (base::PathExists(*full_path)) 106 if (base::PathExists(*full_path))
124 return false; 107 return false;
125 108
126 return base::CreateDirectory(*full_path); 109 return base::CreateDirectory(*full_path);
127 } 110 }
128 111
129 // Makes sure that any pending task is processed. 112 // Makes sure that any pending task is processed.
130 void FlushQueue(disk_cache::Backend* cache) { 113 void FlushQueue(disk_cache::Backend* cache) {
131 net::TestCompletionCallback cb; 114 net::TestCompletionCallback cb;
132 int rv = 115 int rv = reinterpret_cast<disk_cache::BackendImpl*>(cache)
133 reinterpret_cast<disk_cache::BackendImpl*>(cache)->FlushQueueForTest( 116 ->FlushQueueForTest(cb.callback());
134 cb.callback());
135 cb.GetResult(rv); // Ignore the result; 117 cb.GetResult(rv); // Ignore the result;
136 } 118 }
137 119
138 bool CreateCache(const base::FilePath& path, 120 bool CreateCache(const base::FilePath& path,
139 base::Thread* thread, 121 base::Thread* thread,
140 disk_cache::Backend** cache, 122 disk_cache::Backend** cache,
141 net::TestCompletionCallback* cb) { 123 net::TestCompletionCallback* cb) {
142 int size = 1024 * 1024; 124 int size = 1024 * 1024;
143 disk_cache::BackendImpl* backend = new disk_cache::BackendImpl( 125 disk_cache::BackendImpl* backend = new disk_cache::BackendImpl(
144 path, thread->message_loop_proxy().get(), NULL); 126 path, thread->message_loop_proxy().get(), NULL);
145 backend->SetMaxSize(size); 127 backend->SetMaxSize(size);
146 backend->SetType(net::DISK_CACHE); 128 backend->SetType(net::DISK_CACHE);
147 backend->SetFlags(disk_cache::kNoRandom); 129 backend->SetFlags(disk_cache::kNoRandom);
148 int rv = backend->Init(cb->callback()); 130 int rv = backend->Init(cb->callback());
149 *cache = backend; 131 *cache = backend;
150 return (cb->GetResult(rv) == net::OK && !(*cache)->GetEntryCount()); 132 return (cb->GetResult(rv) == net::OK && !(*cache)->GetEntryCount());
151 } 133 }
152 134
153 // Generates the files for an empty and one item cache. 135 // Generates the files for an empty and one item cache.
154 int SimpleInsert(const base::FilePath& path, RankCrashes action, 136 int SimpleInsert(const base::FilePath& path,
137 RankCrashes action,
155 base::Thread* cache_thread) { 138 base::Thread* cache_thread) {
156 net::TestCompletionCallback cb; 139 net::TestCompletionCallback cb;
157 disk_cache::Backend* cache; 140 disk_cache::Backend* cache;
158 if (!CreateCache(path, cache_thread, &cache, &cb)) 141 if (!CreateCache(path, cache_thread, &cache, &cb))
159 return GENERIC; 142 return GENERIC;
160 143
161 const char* test_name = "some other key"; 144 const char* test_name = "some other key";
162 145
163 if (action <= disk_cache::INSERT_EMPTY_3) { 146 if (action <= disk_cache::INSERT_EMPTY_3) {
164 test_name = kCrashEntryName; 147 test_name = kCrashEntryName;
(...skipping 13 matching lines...) Expand all
178 test_name = kCrashEntryName; 161 test_name = kCrashEntryName;
179 162
180 rv = cache->CreateEntry(test_name, &entry, cb.callback()); 163 rv = cache->CreateEntry(test_name, &entry, cb.callback());
181 if (cb.GetResult(rv) != net::OK) 164 if (cb.GetResult(rv) != net::OK)
182 return GENERIC; 165 return GENERIC;
183 166
184 return NOT_REACHED; 167 return NOT_REACHED;
185 } 168 }
186 169
187 // Generates the files for a one item cache, and removing the head. 170 // Generates the files for a one item cache, and removing the head.
188 int SimpleRemove(const base::FilePath& path, RankCrashes action, 171 int SimpleRemove(const base::FilePath& path,
172 RankCrashes action,
189 base::Thread* cache_thread) { 173 base::Thread* cache_thread) {
190 DCHECK(action >= disk_cache::REMOVE_ONE_1); 174 DCHECK(action >= disk_cache::REMOVE_ONE_1);
191 DCHECK(action <= disk_cache::REMOVE_TAIL_3); 175 DCHECK(action <= disk_cache::REMOVE_TAIL_3);
192 176
193 net::TestCompletionCallback cb; 177 net::TestCompletionCallback cb;
194 disk_cache::Backend* cache; 178 disk_cache::Backend* cache;
195 if (!CreateCache(path, cache_thread, &cache, &cb)) 179 if (!CreateCache(path, cache_thread, &cache, &cb))
196 return GENERIC; 180 return GENERIC;
197 181
198 disk_cache::Entry* entry; 182 disk_cache::Entry* entry;
(...skipping 18 matching lines...) Expand all
217 return GENERIC; 201 return GENERIC;
218 202
219 disk_cache::g_rankings_crash = action; 203 disk_cache::g_rankings_crash = action;
220 entry->Doom(); 204 entry->Doom();
221 entry->Close(); 205 entry->Close();
222 FlushQueue(cache); 206 FlushQueue(cache);
223 207
224 return NOT_REACHED; 208 return NOT_REACHED;
225 } 209 }
226 210
227 int HeadRemove(const base::FilePath& path, RankCrashes action, 211 int HeadRemove(const base::FilePath& path,
212 RankCrashes action,
228 base::Thread* cache_thread) { 213 base::Thread* cache_thread) {
229 DCHECK(action >= disk_cache::REMOVE_HEAD_1); 214 DCHECK(action >= disk_cache::REMOVE_HEAD_1);
230 DCHECK(action <= disk_cache::REMOVE_HEAD_4); 215 DCHECK(action <= disk_cache::REMOVE_HEAD_4);
231 216
232 net::TestCompletionCallback cb; 217 net::TestCompletionCallback cb;
233 disk_cache::Backend* cache; 218 disk_cache::Backend* cache;
234 if (!CreateCache(path, cache_thread, &cache, &cb)) 219 if (!CreateCache(path, cache_thread, &cache, &cb))
235 return GENERIC; 220 return GENERIC;
236 221
237 disk_cache::Entry* entry; 222 disk_cache::Entry* entry;
(...skipping 16 matching lines...) Expand all
254 239
255 disk_cache::g_rankings_crash = action; 240 disk_cache::g_rankings_crash = action;
256 entry->Doom(); 241 entry->Doom();
257 entry->Close(); 242 entry->Close();
258 FlushQueue(cache); 243 FlushQueue(cache);
259 244
260 return NOT_REACHED; 245 return NOT_REACHED;
261 } 246 }
262 247
263 // Generates the files for insertion and removals on heavy loaded caches. 248 // Generates the files for insertion and removals on heavy loaded caches.
264 int LoadOperations(const base::FilePath& path, RankCrashes action, 249 int LoadOperations(const base::FilePath& path,
250 RankCrashes action,
265 base::Thread* cache_thread) { 251 base::Thread* cache_thread) {
266 DCHECK(action >= disk_cache::INSERT_LOAD_1); 252 DCHECK(action >= disk_cache::INSERT_LOAD_1);
267 253
268 // Work with a tiny index table (16 entries). 254 // Work with a tiny index table (16 entries).
269 disk_cache::BackendImpl* cache = new disk_cache::BackendImpl( 255 disk_cache::BackendImpl* cache = new disk_cache::BackendImpl(
270 path, 0xf, cache_thread->message_loop_proxy().get(), NULL); 256 path, 0xf, cache_thread->message_loop_proxy().get(), NULL);
271 if (!cache->SetMaxSize(0x100000)) 257 if (!cache->SetMaxSize(0x100000))
272 return GENERIC; 258 return GENERIC;
273 259
274 // No experiments and use a simple LRU. 260 // No experiments and use a simple LRU.
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 359
374 base::FilePath path; 360 base::FilePath path;
375 PathService::Get(base::DIR_SOURCE_ROOT, &path); 361 PathService::Get(base::DIR_SOURCE_ROOT, &path);
376 path = path.AppendASCII("net"); 362 path = path.AppendASCII("net");
377 path = path.AppendASCII("data"); 363 path = path.AppendASCII("data");
378 path = path.AppendASCII("cache_tests"); 364 path = path.AppendASCII("cache_tests");
379 path = path.AppendASCII("new_crashes"); 365 path = path.AppendASCII("new_crashes");
380 366
381 return SlaveCode(path, action); 367 return SlaveCode(path, action);
382 } 368 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698