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

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

Issue 10399083: Make NetLog take in callbacks that return Values (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Fix merge error Created 8 years, 6 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/capturing_net_log.cc ('k') | net/base/net_log.h » ('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) 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/file_stream.h" 5 #include "net/base/file_stream.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 20 matching lines...) Expand all
31 IOBufferWithSize* buf = new IOBufferWithSize(kTestDataSize); 31 IOBufferWithSize* buf = new IOBufferWithSize(kTestDataSize);
32 memcpy(buf->data(), kTestData, kTestDataSize); 32 memcpy(buf->data(), kTestData, kTestDataSize);
33 return buf; 33 return buf;
34 } 34 }
35 35
36 // This NetLog is used for notifying when a file stream is closed 36 // This NetLog is used for notifying when a file stream is closed
37 // (i.e. TYPE_FILE_STREAM_CLOSE event is recorded). 37 // (i.e. TYPE_FILE_STREAM_CLOSE event is recorded).
38 class NetLogForNotifyingFileClosure : public NetLog { 38 class NetLogForNotifyingFileClosure : public NetLog {
39 public: 39 public:
40 NetLogForNotifyingFileClosure() 40 NetLogForNotifyingFileClosure()
41 : id_(0), 41 : last_id_(0),
42 on_closure_(false /* manual_reset */, false /* initially_signaled */) { 42 on_closure_(false /* manual_reset */, false /* initially_signaled */) {
43 } 43 }
44 44
45 // Wait until a file closure event is recorded. 45 // Wait until a file closure event is recorded.
46 bool WaitForClosure() { 46 bool WaitForClosure() {
47 const base::TimeDelta timeout( 47 const base::TimeDelta timeout(
48 base::TimeDelta::FromMilliseconds( 48 base::TimeDelta::FromMilliseconds(
49 TestTimeouts::action_max_timeout_ms())); 49 TestTimeouts::action_max_timeout_ms()));
50 return on_closure_.TimedWait(timeout); 50 return on_closure_.TimedWait(timeout);
51 } 51 }
52 52
53 // NetLog overrides: 53 // NetLog overrides:
54 virtual void AddEntry( 54 virtual void OnAddEntry(const net::NetLog::Entry& entry) OVERRIDE {
55 EventType type, 55 if (entry.type() == TYPE_FILE_STREAM_CLOSE)
56 const Source& source,
57 EventPhase phase,
58 const scoped_refptr<EventParameters>& params) OVERRIDE {
59 if (type == TYPE_FILE_STREAM_CLOSE) {
60 on_closure_.Signal(); 56 on_closure_.Signal();
61 }
62 } 57 }
63 58
64 virtual uint32 NextID() OVERRIDE { return id_++; } 59 virtual uint32 NextID() OVERRIDE { return ++last_id_; }
65 virtual LogLevel GetLogLevel() const OVERRIDE { return LOG_ALL; } 60 virtual LogLevel GetLogLevel() const OVERRIDE { return LOG_ALL; }
66 virtual void AddThreadSafeObserver(ThreadSafeObserver* observer, 61 virtual void AddThreadSafeObserver(ThreadSafeObserver* observer,
67 LogLevel log_level) OVERRIDE { 62 LogLevel log_level) OVERRIDE {
68 NOTIMPLEMENTED(); 63 NOTIMPLEMENTED();
69 } 64 }
70 virtual void SetObserverLogLevel(ThreadSafeObserver* observer, 65 virtual void SetObserverLogLevel(ThreadSafeObserver* observer,
71 LogLevel log_level) OVERRIDE { 66 LogLevel log_level) OVERRIDE {
72 NOTIMPLEMENTED(); 67 NOTIMPLEMENTED();
73 } 68 }
74 virtual void RemoveThreadSafeObserver(ThreadSafeObserver* observer) OVERRIDE { 69 virtual void RemoveThreadSafeObserver(ThreadSafeObserver* observer) OVERRIDE {
75 NOTIMPLEMENTED(); 70 NOTIMPLEMENTED();
76 } 71 }
77 72
78 private: 73 private:
79 uint32 id_; 74 uint32 last_id_;
80 base::WaitableEvent on_closure_; 75 base::WaitableEvent on_closure_;
81 }; 76 };
82 77
83 } // namespace 78 } // namespace
84 79
85 class FileStreamTest : public PlatformTest { 80 class FileStreamTest : public PlatformTest {
86 public: 81 public:
87 virtual void SetUp() { 82 virtual void SetUp() {
88 PlatformTest::SetUp(); 83 PlatformTest::SetUp();
89 84
(...skipping 1170 matching lines...) Expand 10 before | Expand all | Expand 10 after
1260 // Delete the stream without waiting for the close operation to be 1255 // Delete the stream without waiting for the close operation to be
1261 // complete. Should be safe. 1256 // complete. Should be safe.
1262 stream.reset(); 1257 stream.reset();
1263 // close_callback won't be called. 1258 // close_callback won't be called.
1264 EXPECT_FALSE(close_callback.have_result()); 1259 EXPECT_FALSE(close_callback.have_result());
1265 } 1260 }
1266 1261
1267 } // namespace 1262 } // namespace
1268 1263
1269 } // namespace net 1264 } // namespace net
OLDNEW
« no previous file with comments | « net/base/capturing_net_log.cc ('k') | net/base/net_log.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698