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

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

Issue 9949011: Make FileStream::Seek async and add FileStream::SeekSync for sync operation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed comments + added tests Created 8 years, 8 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/base/test_completion_callback.h" 5 #include "net/base/test_completion_callback.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
11 #include "net/base/net_errors.h"
12 11
13 void TestCompletionCallbackBase::SetResult(int result) { 12 namespace internal {
14 result_ = result; 13
14 void TestCompletionCallbackBaseInternal::DidSetResult() {
15 have_result_ = true; 15 have_result_ = true;
16 if (waiting_for_result_) 16 if (waiting_for_result_)
17 MessageLoop::current()->Quit(); 17 MessageLoop::current()->Quit();
18 } 18 }
19 19
20 int TestCompletionCallbackBase::WaitForResult() { 20 void TestCompletionCallbackBaseInternal::WaitForResult() {
21 DCHECK(!waiting_for_result_); 21 DCHECK(!waiting_for_result_);
22 22
23 while (!have_result_) { 23 while (!have_result_) {
24 waiting_for_result_ = true; 24 waiting_for_result_ = true;
25 MessageLoop::current()->Run(); 25 MessageLoop::current()->Run();
26 waiting_for_result_ = false; 26 waiting_for_result_ = false;
27 } 27 }
28
29 have_result_ = false; // Auto-reset for next callback.
30 return result_;
31 } 28 }
32 29
33 int TestCompletionCallbackBase::GetResult(int result) { 30 TestCompletionCallbackBaseInternal::TestCompletionCallbackBaseInternal()
34 if (net::ERR_IO_PENDING != result) 31 : have_result_(false),
35 return result; 32 waiting_for_result_(false) {
36
37 return WaitForResult();
38 } 33 }
39 34
40 TestCompletionCallbackBase::TestCompletionCallbackBase() 35 } // namespace internal
41 : result_(0),
42 have_result_(false),
43 waiting_for_result_(false) {
44 }
45 36
46 namespace net { 37 namespace net {
47 38
48 TestCompletionCallback::TestCompletionCallback() 39 TestCompletionCallback::TestCompletionCallback()
49 : ALLOW_THIS_IN_INITIALIZER_LIST(callback_( 40 : ALLOW_THIS_IN_INITIALIZER_LIST(callback_(
50 base::Bind(&TestCompletionCallback::SetResult, 41 base::Bind(&TestCompletionCallback::SetResult,
51 base::Unretained(this)))) { 42 base::Unretained(this)))) {
52 } 43 }
53 44
54 TestCompletionCallback::~TestCompletionCallback() {} 45 TestCompletionCallback::~TestCompletionCallback() {}
55 46
47 TestInt64CompletionCallback::TestInt64CompletionCallback()
48 : ALLOW_THIS_IN_INITIALIZER_LIST(callback_(
49 base::Bind(&TestInt64CompletionCallback::SetResult,
50 base::Unretained(this)))) {
51 }
52
53 TestInt64CompletionCallback::~TestInt64CompletionCallback() {}
56 54
57 } // namespace net 55 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698