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

Side by Side Diff: base/message_pump_libevent_unittest.cc

Issue 11412101: Provide an iOS message pump for IO implementation. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Response to review, bugfix Created 8 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
« base/message_pump_libevent.h ('K') | « base/message_pump_libevent.cc ('k') | no next file » | 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 "base/message_pump_libevent.h" 5 #include "base/message_pump_libevent.h"
6 6
7 #include <unistd.h> 7 #include <unistd.h>
8 8
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/posix/eintr_wrapper.h" 10 #include "base/posix/eintr_wrapper.h"
(...skipping 12 matching lines...) Expand all
23 protected: 23 protected:
24 MessagePumpLibeventTest() 24 MessagePumpLibeventTest()
25 : ui_loop_(MessageLoop::TYPE_UI), 25 : ui_loop_(MessageLoop::TYPE_UI),
26 io_thread_("MessagePumpLibeventTestIOThread") {} 26 io_thread_("MessagePumpLibeventTestIOThread") {}
27 virtual ~MessagePumpLibeventTest() {} 27 virtual ~MessagePumpLibeventTest() {}
28 28
29 virtual void SetUp() OVERRIDE { 29 virtual void SetUp() OVERRIDE {
30 Thread::Options options(MessageLoop::TYPE_IO, 0); 30 Thread::Options options(MessageLoop::TYPE_IO, 0);
31 ASSERT_TRUE(io_thread_.StartWithOptions(options)); 31 ASSERT_TRUE(io_thread_.StartWithOptions(options));
32 ASSERT_EQ(MessageLoop::TYPE_IO, io_thread_.message_loop()->type()); 32 ASSERT_EQ(MessageLoop::TYPE_IO, io_thread_.message_loop()->type());
33 int err = pipe(pipefds_); 33 int ret = pipe(pipefds_);
34 ASSERT_EQ(0, err); 34 ASSERT_EQ(0, ret);
35 } 35 }
36 36
37 virtual void TearDown() OVERRIDE { 37 virtual void TearDown() OVERRIDE {
38 if (HANDLE_EINTR(close(pipefds_[0])) < 0) 38 if (HANDLE_EINTR(close(pipefds_[0])) < 0)
39 PLOG(ERROR) << "close"; 39 PLOG(ERROR) << "close";
40 if (HANDLE_EINTR(close(pipefds_[1])) < 0) 40 if (HANDLE_EINTR(close(pipefds_[1])) < 0)
41 PLOG(ERROR) << "close"; 41 PLOG(ERROR) << "close";
42 } 42 }
43 43
44 MessageLoop* ui_loop() { return &ui_loop_; } 44 MessageLoop* ui_loop() { return &ui_loop_; }
45 MessageLoopForIO* io_loop() const { 45 MessageLoopForIO* io_loop() const {
46 return static_cast<MessageLoopForIO*>(io_thread_.message_loop()); 46 return static_cast<MessageLoopForIO*>(io_thread_.message_loop());
47 } 47 }
48 48
49 void OnLibeventNotification( 49 void OnLibeventNotification(
50 MessagePumpLibevent* pump, 50 MessagePumpLibevent* pump,
51 MessagePumpLibevent::FileDescriptorWatcher* controller) { 51 MessagePumpLibevent::FileDescriptorWatcher* controller) {
52 pump->OnLibeventNotification(0, EV_WRITE | EV_READ, controller); 52 pump->OnLibeventNotification(0, EV_WRITE | EV_READ, controller);
53 } 53 }
54 54
55 MessageLoop ui_loop_; 55 MessageLoop ui_loop_;
56 Thread io_thread_; 56 Thread io_thread_;
57 int pipefds_[2]; 57 int pipefds_[2];
wtc 2012/11/29 00:53:21 Nit: should we also make ui_loop_ and io_thread_ p
blundell 2012/11/29 15:01:04 Done.
58 }; 58 };
59 59
60 namespace { 60 namespace {
61 61
62 // Concrete implementation of MessagePumpLibevent::Watcher that does 62 // Concrete implementation of MessagePumpLibevent::Watcher that does
63 // nothing useful. 63 // nothing useful.
64 class StupidWatcher : public MessagePumpLibevent::Watcher { 64 class StupidWatcher : public MessagePumpLibevent::Watcher {
65 public: 65 public:
66 virtual ~StupidWatcher() {} 66 virtual ~StupidWatcher() {}
67 67
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 pump->WatchFileDescriptor(pipefds_[1], 156 pump->WatchFileDescriptor(pipefds_[1],
157 false, MessagePumpLibevent::WATCH_READ_WRITE, &watcher, &delegate); 157 false, MessagePumpLibevent::WATCH_READ_WRITE, &watcher, &delegate);
158 158
159 // Spoof a libevent notification. 159 // Spoof a libevent notification.
160 OnLibeventNotification(pump, &watcher); 160 OnLibeventNotification(pump, &watcher);
161 } 161 }
162 162
163 } // namespace 163 } // namespace
164 164
165 } // namespace base 165 } // namespace base
OLDNEW
« base/message_pump_libevent.h ('K') | « base/message_pump_libevent.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698