| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/shell/data_pipe_peek.h" | 5 #include "mojo/shell/data_pipe_peek.h" |
| 6 | 6 |
| 7 #include <stddef.h> |
| 7 #include <stdint.h> | 8 #include <stdint.h> |
| 8 | 9 |
| 9 #include <algorithm> | 10 #include <algorithm> |
| 10 | 11 |
| 11 #include "base/bind.h" | 12 #include "base/bind.h" |
| 12 #include "base/macros.h" | 13 #include "base/macros.h" |
| 13 | 14 |
| 14 namespace mojo { | 15 namespace mojo { |
| 15 namespace shell { | 16 namespace shell { |
| 16 | 17 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 36 if (num_bytes_read > 0 && last_number_bytes_read_ >= num_bytes_read) | 37 if (num_bytes_read > 0 && last_number_bytes_read_ >= num_bytes_read) |
| 37 return false; | 38 return false; |
| 38 last_number_bytes_read_ = num_bytes_read; | 39 last_number_bytes_read_ = num_bytes_read; |
| 39 | 40 |
| 40 MojoTimeTicks now(GetTimeTicksNow()); | 41 MojoTimeTicks now(GetTimeTicksNow()); |
| 41 if (now > deadline_) | 42 if (now > deadline_) |
| 42 return false; | 43 return false; |
| 43 | 44 |
| 44 MojoTimeTicks sleep_time = | 45 MojoTimeTicks sleep_time = |
| 45 (deadline_ == 0) ? kMaxSleepMicros | 46 (deadline_ == 0) ? kMaxSleepMicros |
| 46 : std::min<int64>(deadline_ - now, kMaxSleepMicros); | 47 : std::min<int64_t>(deadline_ - now, kMaxSleepMicros); |
| 47 base::PlatformThread::Sleep(base::TimeDelta::FromMicroseconds(sleep_time)); | 48 base::PlatformThread::Sleep(base::TimeDelta::FromMicroseconds(sleep_time)); |
| 48 return true; | 49 return true; |
| 49 } | 50 } |
| 50 | 51 |
| 51 private: | 52 private: |
| 52 static const MojoTimeTicks kMaxSleepMicros = 1000 * 10; // 10 ms | 53 static const MojoTimeTicks kMaxSleepMicros = 1000 * 10; // 10 ms |
| 53 | 54 |
| 54 const MojoTimeTicks deadline_; // 0 => MOJO_DEADLINE_INDEFINITE | 55 const MojoTimeTicks deadline_; // 0 => MOJO_DEADLINE_INDEFINITE |
| 55 uint32_t last_number_bytes_read_; | 56 uint32_t last_number_bytes_read_; |
| 56 | 57 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 bool BlockingPeekLine(DataPipeConsumerHandle source, | 154 bool BlockingPeekLine(DataPipeConsumerHandle source, |
| 154 std::string* line, | 155 std::string* line, |
| 155 size_t max_line_length, | 156 size_t max_line_length, |
| 156 MojoDeadline timeout) { | 157 MojoDeadline timeout) { |
| 157 PeekFunc peek_line = base::Bind(PeekLine, max_line_length); | 158 PeekFunc peek_line = base::Bind(PeekLine, max_line_length); |
| 158 return BlockingPeekHelper(source, line, timeout, peek_line); | 159 return BlockingPeekHelper(source, line, timeout, peek_line); |
| 159 } | 160 } |
| 160 | 161 |
| 161 } // namespace shell | 162 } // namespace shell |
| 162 } // namespace mojo | 163 } // namespace mojo |
| OLD | NEW |