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

Side by Side Diff: net/disk_cache/disk_cache_test_util.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 #include "net/disk_cache/disk_cache_test_util.h" 5 #include "net/disk_cache/disk_cache_test_util.h"
6 6
7 #include "base/files/file.h" 7 #include "base/files/file.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop/message_loop_proxy.h" 10 #include "base/message_loop/message_loop_proxy.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 52
53 file.SetLength(4 * 1024 * 1024); 53 file.SetLength(4 * 1024 * 1024);
54 return true; 54 return true;
55 } 55 }
56 56
57 bool DeleteCache(const base::FilePath& path) { 57 bool DeleteCache(const base::FilePath& path) {
58 disk_cache::DeleteCache(path, false); 58 disk_cache::DeleteCache(path, false);
59 return true; 59 return true;
60 } 60 }
61 61
62 bool CheckCacheIntegrity(const base::FilePath& path, bool new_eviction, 62 bool CheckCacheIntegrity(const base::FilePath& path,
63 bool new_eviction,
63 uint32 mask) { 64 uint32 mask) {
64 scoped_ptr<disk_cache::BackendImpl> cache(new disk_cache::BackendImpl( 65 scoped_ptr<disk_cache::BackendImpl> cache(new disk_cache::BackendImpl(
65 path, mask, base::MessageLoopProxy::current().get(), NULL)); 66 path, mask, base::MessageLoopProxy::current().get(), NULL));
66 if (!cache.get()) 67 if (!cache.get())
67 return false; 68 return false;
68 if (new_eviction) 69 if (new_eviction)
69 cache->SetNewEviction(); 70 cache->SetNewEviction();
70 cache->SetFlags(disk_cache::kNoRandom); 71 cache->SetFlags(disk_cache::kNoRandom);
71 if (cache->SyncInit() != net::OK) 72 if (cache->SyncInit() != net::OK)
72 return false; 73 return false;
(...skipping 14 matching lines...) Expand all
87 MessageLoopHelper::~MessageLoopHelper() { 88 MessageLoopHelper::~MessageLoopHelper() {
88 } 89 }
89 90
90 bool MessageLoopHelper::WaitUntilCacheIoFinished(int num_callbacks) { 91 bool MessageLoopHelper::WaitUntilCacheIoFinished(int num_callbacks) {
91 if (num_callbacks == callbacks_called_) 92 if (num_callbacks == callbacks_called_)
92 return true; 93 return true;
93 94
94 ExpectCallbacks(num_callbacks); 95 ExpectCallbacks(num_callbacks);
95 // Create a recurrent timer of 50 mS. 96 // Create a recurrent timer of 50 mS.
96 if (!timer_.IsRunning()) 97 if (!timer_.IsRunning())
97 timer_.Start(FROM_HERE, TimeDelta::FromMilliseconds(50), this, 98 timer_.Start(FROM_HERE,
99 TimeDelta::FromMilliseconds(50),
100 this,
98 &MessageLoopHelper::TimerExpired); 101 &MessageLoopHelper::TimerExpired);
99 base::MessageLoop::current()->Run(); 102 base::MessageLoop::current()->Run();
100 return completed_; 103 return completed_;
101 } 104 }
102 105
103 // Quits the message loop when all callbacks are called or we've been waiting 106 // Quits the message loop when all callbacks are called or we've been waiting
104 // too long for them (2 secs without a callback). 107 // too long for them (2 secs without a callback).
105 void MessageLoopHelper::TimerExpired() { 108 void MessageLoopHelper::TimerExpired() {
106 CHECK_LE(callbacks_called_, num_callbacks_); 109 CHECK_LE(callbacks_called_, num_callbacks_);
107 if (callbacks_called_ == num_callbacks_) { 110 if (callbacks_called_ == num_callbacks_) {
108 completed_ = true; 111 completed_ = true;
109 base::MessageLoop::current()->Quit(); 112 base::MessageLoop::current()->Quit();
110 } else { 113 } else {
111 // Not finished yet. See if we have to abort. 114 // Not finished yet. See if we have to abort.
112 if (last_ == callbacks_called_) 115 if (last_ == callbacks_called_)
113 num_iterations_++; 116 num_iterations_++;
114 else 117 else
115 last_ = callbacks_called_; 118 last_ = callbacks_called_;
116 if (40 == num_iterations_) 119 if (40 == num_iterations_)
117 base::MessageLoop::current()->Quit(); 120 base::MessageLoop::current()->Quit();
118 } 121 }
119 } 122 }
120 123
121 // ----------------------------------------------------------------------- 124 // -----------------------------------------------------------------------
122 125
123 CallbackTest::CallbackTest(MessageLoopHelper* helper, 126 CallbackTest::CallbackTest(MessageLoopHelper* helper, bool reuse)
124 bool reuse) 127 : helper_(helper), reuse_(reuse ? 0 : 1) {
125 : helper_(helper),
126 reuse_(reuse ? 0 : 1) {
127 } 128 }
128 129
129 CallbackTest::~CallbackTest() { 130 CallbackTest::~CallbackTest() {
130 } 131 }
131 132
132 // On the actual callback, increase the number of tests received and check for 133 // On the actual callback, increase the number of tests received and check for
133 // errors (an unexpected test received) 134 // errors (an unexpected test received)
134 void CallbackTest::Run(int result) { 135 void CallbackTest::Run(int result) {
135 last_result_ = result; 136 last_result_ = result;
136 137
137 if (reuse_) { 138 if (reuse_) {
138 DCHECK_EQ(1, reuse_); 139 DCHECK_EQ(1, reuse_);
139 if (2 == reuse_) 140 if (2 == reuse_)
140 helper_->set_callback_reused_error(true); 141 helper_->set_callback_reused_error(true);
141 reuse_++; 142 reuse_++;
142 } 143 }
143 144
144 helper_->CallbackWasCalled(); 145 helper_->CallbackWasCalled();
145 } 146 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698