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

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: rebased 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
« no previous file with comments | « net/base/test_completion_callback.h ('k') | net/base/upload_data.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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 net {
14 result_ = result; 13
14 namespace internal {
15
16 void TestCompletionCallbackBaseInternal::DidSetResult() {
15 have_result_ = true; 17 have_result_ = true;
16 if (waiting_for_result_) 18 if (waiting_for_result_)
17 MessageLoop::current()->Quit(); 19 MessageLoop::current()->Quit();
18 } 20 }
19 21
20 int TestCompletionCallbackBase::WaitForResult() { 22 void TestCompletionCallbackBaseInternal::WaitForResult() {
21 DCHECK(!waiting_for_result_); 23 DCHECK(!waiting_for_result_);
22
23 while (!have_result_) { 24 while (!have_result_) {
24 waiting_for_result_ = true; 25 waiting_for_result_ = true;
25 MessageLoop::current()->Run(); 26 MessageLoop::current()->Run();
26 waiting_for_result_ = false; 27 waiting_for_result_ = false;
27 } 28 }
28
29 have_result_ = false; // Auto-reset for next callback. 29 have_result_ = false; // Auto-reset for next callback.
30 return result_;
31 } 30 }
32 31
33 int TestCompletionCallbackBase::GetResult(int result) { 32 TestCompletionCallbackBaseInternal::TestCompletionCallbackBaseInternal()
34 if (net::ERR_IO_PENDING != result) 33 : have_result_(false),
35 return result;
36
37 return WaitForResult();
38 }
39
40 TestCompletionCallbackBase::TestCompletionCallbackBase()
41 : result_(0),
42 have_result_(false),
43 waiting_for_result_(false) { 34 waiting_for_result_(false) {
44 } 35 }
45 36
46 namespace net { 37 } // namespace internal
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
« no previous file with comments | « net/base/test_completion_callback.h ('k') | net/base/upload_data.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698