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 #include "mojo/common/handle_watcher.h" | 5 #include "mojo/common/handle_watcher.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/atomic_sequence_num.h" | 9 #include "base/atomic_sequence_num.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 typedef std::map<Handle, WatchData> HandleToWatchDataMap; | 72 typedef std::map<Handle, WatchData> HandleToWatchDataMap; |
73 | 73 |
74 // Invoked when a handle needs to be removed and notified. | 74 // Invoked when a handle needs to be removed and notified. |
75 void RemoveAndNotify(const Handle& handle, MojoResult result); | 75 void RemoveAndNotify(const Handle& handle, MojoResult result); |
76 | 76 |
77 // Searches through |handle_to_data_| for |watcher_id|. Returns true if found | 77 // Searches through |handle_to_data_| for |watcher_id|. Returns true if found |
78 // and sets |handle| to the Handle. Returns false if not a known id. | 78 // and sets |handle| to the Handle. Returns false if not a known id. |
79 bool GetMojoHandleByWatcherID(WatcherID watcher_id, Handle* handle) const; | 79 bool GetMojoHandleByWatcherID(WatcherID watcher_id, Handle* handle) const; |
80 | 80 |
81 // MessagePumpMojoHandler overrides: | 81 // MessagePumpMojoHandler overrides: |
82 virtual void OnHandleReady(const Handle& handle) OVERRIDE; | 82 virtual void OnHandleReady(const Handle& handle) override; |
83 virtual void OnHandleError(const Handle& handle, MojoResult result) OVERRIDE; | 83 virtual void OnHandleError(const Handle& handle, MojoResult result) override; |
84 | 84 |
85 // Maps from assigned id to WatchData. | 85 // Maps from assigned id to WatchData. |
86 HandleToWatchDataMap handle_to_data_; | 86 HandleToWatchDataMap handle_to_data_; |
87 | 87 |
88 DISALLOW_COPY_AND_ASSIGN(WatcherBackend); | 88 DISALLOW_COPY_AND_ASSIGN(WatcherBackend); |
89 }; | 89 }; |
90 | 90 |
91 WatcherBackend::WatcherBackend() { | 91 WatcherBackend::WatcherBackend() { |
92 } | 92 } |
93 | 93 |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 | 331 |
332 protected: | 332 protected: |
333 void NotifyHandleReady(MojoResult result) { | 333 void NotifyHandleReady(MojoResult result) { |
334 got_ready_ = true; | 334 got_ready_ = true; |
335 NotifyAndDestroy(result); | 335 NotifyAndDestroy(result); |
336 } | 336 } |
337 | 337 |
338 bool got_ready() const { return got_ready_; } | 338 bool got_ready() const { return got_ready_; } |
339 | 339 |
340 private: | 340 private: |
341 virtual void WillDestroyCurrentMessageLoop() OVERRIDE { | 341 virtual void WillDestroyCurrentMessageLoop() override { |
342 // The current thread is exiting. Simulate a watch error. | 342 // The current thread is exiting. Simulate a watch error. |
343 NotifyAndDestroy(MOJO_RESULT_ABORTED); | 343 NotifyAndDestroy(MOJO_RESULT_ABORTED); |
344 } | 344 } |
345 | 345 |
346 void NotifyAndDestroy(MojoResult result) { | 346 void NotifyAndDestroy(MojoResult result) { |
347 base::Callback<void(MojoResult)> callback = callback_; | 347 base::Callback<void(MojoResult)> callback = callback_; |
348 watcher_->Stop(); // Destroys |this|. | 348 watcher_->Stop(); // Destroys |this|. |
349 | 349 |
350 callback.Run(result); | 350 callback.Run(result); |
351 } | 351 } |
(...skipping 26 matching lines...) Expand all Loading... |
378 this, handle, handle_signals, MojoDeadlineToTimeTicks(deadline)); | 378 this, handle, handle_signals, MojoDeadlineToTimeTicks(deadline)); |
379 } | 379 } |
380 | 380 |
381 virtual ~SameThreadWatchingState() { | 381 virtual ~SameThreadWatchingState() { |
382 if (!got_ready()) | 382 if (!got_ready()) |
383 MessagePumpMojo::current()->RemoveHandler(handle_); | 383 MessagePumpMojo::current()->RemoveHandler(handle_); |
384 } | 384 } |
385 | 385 |
386 private: | 386 private: |
387 // MessagePumpMojoHandler overrides: | 387 // MessagePumpMojoHandler overrides: |
388 virtual void OnHandleReady(const Handle& handle) OVERRIDE { | 388 virtual void OnHandleReady(const Handle& handle) override { |
389 StopWatchingAndNotifyReady(handle, MOJO_RESULT_OK); | 389 StopWatchingAndNotifyReady(handle, MOJO_RESULT_OK); |
390 } | 390 } |
391 | 391 |
392 virtual void OnHandleError(const Handle& handle, MojoResult result) OVERRIDE { | 392 virtual void OnHandleError(const Handle& handle, MojoResult result) override { |
393 StopWatchingAndNotifyReady(handle, result); | 393 StopWatchingAndNotifyReady(handle, result); |
394 } | 394 } |
395 | 395 |
396 void StopWatchingAndNotifyReady(const Handle& handle, MojoResult result) { | 396 void StopWatchingAndNotifyReady(const Handle& handle, MojoResult result) { |
397 DCHECK_EQ(handle.value(), handle_.value()); | 397 DCHECK_EQ(handle.value(), handle_.value()); |
398 MessagePumpMojo::current()->RemoveHandler(handle_); | 398 MessagePumpMojo::current()->RemoveHandler(handle_); |
399 NotifyHandleReady(result); | 399 NotifyHandleReady(result); |
400 } | 400 } |
401 | 401 |
402 Handle handle_; | 402 Handle handle_; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 this, handle, handle_signals, deadline, callback)); | 466 this, handle, handle_signals, deadline, callback)); |
467 } | 467 } |
468 } | 468 } |
469 | 469 |
470 void HandleWatcher::Stop() { | 470 void HandleWatcher::Stop() { |
471 state_.reset(); | 471 state_.reset(); |
472 } | 472 } |
473 | 473 |
474 } // namespace common | 474 } // namespace common |
475 } // namespace mojo | 475 } // namespace mojo |
OLD | NEW |