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

Side by Side Diff: net/base/test_completion_callback.h

Issue 501099: Http cache: Add a test to make sure that the cache... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years 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 | « no previous file | net/disk_cache/backend_unittest.cc » ('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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 NET_BASE_TEST_COMPLETION_CALLBACK_H_ 5 #ifndef NET_BASE_TEST_COMPLETION_CALLBACK_H_
6 #define NET_BASE_TEST_COMPLETION_CALLBACK_H_ 6 #define NET_BASE_TEST_COMPLETION_CALLBACK_H_
7 7
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "net/base/completion_callback.h" 9 #include "net/base/completion_callback.h"
10 #include "net/base/net_errors.h"
10 11
11 //----------------------------------------------------------------------------- 12 //-----------------------------------------------------------------------------
12 // completion callback helper 13 // completion callback helper
13 14
14 // A helper class for completion callbacks, designed to make it easy to run 15 // A helper class for completion callbacks, designed to make it easy to run
15 // tests involving asynchronous operations. Just call WaitForResult to wait 16 // tests involving asynchronous operations. Just call WaitForResult to wait
16 // for the asynchronous operation to complete. 17 // for the asynchronous operation to complete.
17 // 18 //
18 // NOTE: Since this runs a message loop to wait for the completion callback, 19 // NOTE: Since this runs a message loop to wait for the completion callback,
19 // there could be other side-effects resulting from WaitForResult. For this 20 // there could be other side-effects resulting from WaitForResult. For this
(...skipping 11 matching lines...) Expand all
31 DCHECK(!waiting_for_result_); 32 DCHECK(!waiting_for_result_);
32 while (!have_result_) { 33 while (!have_result_) {
33 waiting_for_result_ = true; 34 waiting_for_result_ = true;
34 MessageLoop::current()->Run(); 35 MessageLoop::current()->Run();
35 waiting_for_result_ = false; 36 waiting_for_result_ = false;
36 } 37 }
37 have_result_ = false; // auto-reset for next callback 38 have_result_ = false; // auto-reset for next callback
38 return result_; 39 return result_;
39 } 40 }
40 41
42 int GetResult(int result) {
43 if (net::ERR_IO_PENDING != result)
44 return result;
45 return WaitForResult();
46 }
47
41 bool have_result() const { return have_result_; } 48 bool have_result() const { return have_result_; }
42 49
43 virtual void RunWithParams(const Tuple1<int>& params) { 50 virtual void RunWithParams(const Tuple1<int>& params) {
44 result_ = params.a; 51 result_ = params.a;
45 have_result_ = true; 52 have_result_ = true;
46 if (waiting_for_result_) 53 if (waiting_for_result_)
47 MessageLoop::current()->Quit(); 54 MessageLoop::current()->Quit();
48 } 55 }
49 56
50 private: 57 private:
51 int result_; 58 int result_;
52 bool have_result_; 59 bool have_result_;
53 bool waiting_for_result_; 60 bool waiting_for_result_;
54 }; 61 };
55 62
56 #endif // NET_BASE_TEST_COMPLETION_CALLBACK_H_ 63 #endif // NET_BASE_TEST_COMPLETION_CALLBACK_H_
OLDNEW
« no previous file with comments | « no previous file | net/disk_cache/backend_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698