OLD | NEW |
1 // Copyright (c) 2012 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/mock_file_stream.h" | 5 #include "net/base/mock_file_stream.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 | 9 |
10 namespace net { | 10 namespace net { |
(...skipping 15 matching lines...) Expand all Loading... |
26 : FileStream(file.Pass(), task_runner), | 26 : FileStream(file.Pass(), task_runner), |
27 forced_error_(OK), | 27 forced_error_(OK), |
28 async_error_(false), | 28 async_error_(false), |
29 throttled_(false), | 29 throttled_(false), |
30 weak_factory_(this) { | 30 weak_factory_(this) { |
31 } | 31 } |
32 | 32 |
33 MockFileStream::~MockFileStream() { | 33 MockFileStream::~MockFileStream() { |
34 } | 34 } |
35 | 35 |
36 int MockFileStream::Seek(base::File::Whence whence, int64 offset, | 36 int MockFileStream::Seek(int64 offset, |
37 const Int64CompletionCallback& callback) { | 37 const Int64CompletionCallback& callback) { |
38 Int64CompletionCallback wrapped_callback = | 38 Int64CompletionCallback wrapped_callback = |
39 base::Bind(&MockFileStream::DoCallback64, | 39 base::Bind(&MockFileStream::DoCallback64, |
40 weak_factory_.GetWeakPtr(), callback); | 40 weak_factory_.GetWeakPtr(), callback); |
41 if (forced_error_ == OK) | 41 if (forced_error_ == OK) |
42 return FileStream::Seek(whence, offset, wrapped_callback); | 42 return FileStream::Seek(offset, wrapped_callback); |
43 return ErrorCallback64(wrapped_callback); | 43 return ErrorCallback64(wrapped_callback); |
44 } | 44 } |
45 | 45 |
46 int MockFileStream::Read(IOBuffer* buf, | 46 int MockFileStream::Read(IOBuffer* buf, |
47 int buf_len, | 47 int buf_len, |
48 const CompletionCallback& callback) { | 48 const CompletionCallback& callback) { |
49 CompletionCallback wrapped_callback = base::Bind(&MockFileStream::DoCallback, | 49 CompletionCallback wrapped_callback = base::Bind(&MockFileStream::DoCallback, |
50 weak_factory_.GetWeakPtr(), | 50 weak_factory_.GetWeakPtr(), |
51 callback); | 51 callback); |
52 if (forced_error_ == OK) | 52 if (forced_error_ == OK) |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 return ERR_IO_PENDING; | 132 return ERR_IO_PENDING; |
133 } | 133 } |
134 int64 ret = forced_error_; | 134 int64 ret = forced_error_; |
135 clear_forced_error(); | 135 clear_forced_error(); |
136 return ret; | 136 return ret; |
137 } | 137 } |
138 | 138 |
139 } // namespace testing | 139 } // namespace testing |
140 | 140 |
141 } // namespace net | 141 } // namespace net |
OLD | NEW |