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

Side by Side Diff: mojo/edk/system/watch_unittest.cc

Issue 1811433002: [mojo-edk] Expose notification source to MojoWatch callbacks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 <functional> 5 #include <functional>
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "mojo/edk/test/mojo_test_base.h" 10 #include "mojo/edk/test/mojo_test_base.h"
11 #include "mojo/public/c/system/functions.h" 11 #include "mojo/public/c/system/functions.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 namespace mojo { 14 namespace mojo {
15 namespace edk { 15 namespace edk {
16 namespace { 16 namespace {
17 17
18 void IgnoreResult(uintptr_t context, 18 void IgnoreResult(uintptr_t context,
19 MojoResult result, 19 MojoResult result,
20 MojoHandleSignalsState signals) { 20 MojoHandleSignalsState signals,
21 MojoWatchNotificationFlags flags) {
21 } 22 }
22 23
23 // A test helper class for watching a handle. The WatchHelper instance is used 24 // A test helper class for watching a handle. The WatchHelper instance is used
24 // as a watch context for a single watch callback. 25 // as a watch context for a single watch callback.
25 class WatchHelper { 26 class WatchHelper {
26 public: 27 public:
27 using Callback = 28 using Callback =
28 std::function<void(MojoResult result, MojoHandleSignalsState state)>; 29 std::function<void(MojoResult result, MojoHandleSignalsState state)>;
29 30
30 WatchHelper() {} 31 WatchHelper() {}
(...skipping 18 matching lines...) Expand all
49 void Cancel() { 50 void Cancel() {
50 CHECK_EQ(MOJO_RESULT_OK, 51 CHECK_EQ(MOJO_RESULT_OK,
51 MojoCancelWatch(handle_, reinterpret_cast<uintptr_t>(this))); 52 MojoCancelWatch(handle_, reinterpret_cast<uintptr_t>(this)));
52 CHECK(watching_); 53 CHECK(watching_);
53 watching_ = false; 54 watching_ = false;
54 } 55 }
55 56
56 private: 57 private:
57 static void OnNotify(uintptr_t context, 58 static void OnNotify(uintptr_t context,
58 MojoResult result, 59 MojoResult result,
59 MojoHandleSignalsState state) { 60 MojoHandleSignalsState state,
61 MojoWatchNotificationFlags flags) {
60 WatchHelper* watcher = reinterpret_cast<WatchHelper*>(context); 62 WatchHelper* watcher = reinterpret_cast<WatchHelper*>(context);
61 CHECK(watcher->watching_); 63 CHECK(watcher->watching_);
62 if (result == MOJO_RESULT_CANCELLED) 64 if (result == MOJO_RESULT_CANCELLED)
63 watcher->watching_ = false; 65 watcher->watching_ = false;
66 CHECK_EQ(flags, MOJO_WATCH_NOTIFICATION_FLAG_NONE);
64 watcher->callback_(result, state); 67 watcher->callback_(result, state);
65 } 68 }
66 69
67 bool watching_ = false; 70 bool watching_ = false;
68 MojoHandle handle_; 71 MojoHandle handle_;
69 Callback callback_; 72 Callback callback_;
70 73
71 DISALLOW_COPY_AND_ASSIGN(WatchHelper); 74 DISALLOW_COPY_AND_ASSIGN(WatchHelper);
72 }; 75 };
73 76
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 400
398 b_watcher.Cancel(); 401 b_watcher.Cancel();
399 402
400 CloseHandle(a); 403 CloseHandle(a);
401 CloseHandle(b); 404 CloseHandle(b);
402 } 405 }
403 406
404 } // namespace 407 } // namespace
405 } // namespace edk 408 } // namespace edk
406 } // namespace mojo 409 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698