OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #ifndef MOJO_COMMON_HANDLE_WATCHER_H_ | 5 #ifndef MOJO_COMMON_HANDLE_WATCHER_H_ |
6 #define MOJO_COMMON_HANDLE_WATCHER_H_ | 6 #define MOJO_COMMON_HANDLE_WATCHER_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/callback_forward.h" | 9 #include "base/callback_forward.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 ~HandleWatcher(); | 31 ~HandleWatcher(); |
32 | 32 |
33 // Starts listening for |handle|. This implicitly invokes Stop(). In other | 33 // Starts listening for |handle|. This implicitly invokes Stop(). In other |
34 // words, Start() performs one asynchronous watch at a time. It is ok to call | 34 // words, Start() performs one asynchronous watch at a time. It is ok to call |
35 // Start() multiple times, but it cancels any existing watches. |callback| is | 35 // Start() multiple times, but it cancels any existing watches. |callback| is |
36 // notified when the handle is ready, invalid or deadline has passed and is | 36 // notified when the handle is ready, invalid or deadline has passed and is |
37 // notified on the thread Start() was invoked on. | 37 // notified on the thread Start() was invoked on. |
38 void Start(MojoHandle handle, | 38 void Start(MojoHandle handle, |
39 MojoWaitFlags wait_flags, | 39 MojoWaitFlags wait_flags, |
40 MojoDeadline deadline, | 40 MojoDeadline deadline, |
41 const base::Callback<void(MojoResult)>& callback); | 41 const base::Closure& callback); |
42 | 42 |
43 // Stops listening. Does nothing if not in the process of listening. | 43 // Stops listening. Does nothing if not in the process of listening. |
44 void Stop(); | 44 void Stop(); |
45 | 45 |
46 // Returns now. Used internally; generally not useful. | 46 // Returns now. Used internally; generally not useful. |
47 static base::TimeTicks NowTicks(); | 47 static base::TimeTicks NowTicks(); |
48 | 48 |
49 // Converts a MojoDeadline into a TimeTicks. | 49 // Converts a MojoDeadline into a TimeTicks. |
50 static base::TimeTicks MojoDeadlineToTimeTicks(MojoDeadline deadline); | 50 static base::TimeTicks MojoDeadlineToTimeTicks(MojoDeadline deadline); |
51 | 51 |
52 private: | 52 private: |
53 friend class test::HandleWatcherTest; | 53 friend class test::HandleWatcherTest; |
54 struct StartState; | 54 struct StartState; |
55 | 55 |
56 // See description of |StartState::weak_factory| for details. | 56 // See description of |StartState::weak_factory| for details. |
57 void OnHandleReady(MojoResult result); | 57 void OnHandleReady(); |
58 | 58 |
59 // If non-NULL Start() has been invoked. | 59 // If non-NULL Start() has been invoked. |
60 scoped_ptr<StartState> start_state_; | 60 scoped_ptr<StartState> start_state_; |
61 | 61 |
62 // Used for getting the time. Only set by tests. | 62 // Used for getting the time. Only set by tests. |
63 static base::TickClock* tick_clock_; | 63 static base::TickClock* tick_clock_; |
64 | 64 |
65 DISALLOW_COPY_AND_ASSIGN(HandleWatcher); | 65 DISALLOW_COPY_AND_ASSIGN(HandleWatcher); |
66 }; | 66 }; |
67 | 67 |
68 } // namespace common | 68 } // namespace common |
69 } // namespace mojo | 69 } // namespace mojo |
70 | 70 |
71 #endif // MOJO_COMMON_HANDLE_WATCHER_H_ | 71 #endif // MOJO_COMMON_HANDLE_WATCHER_H_ |
OLD | NEW |