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

Side by Side Diff: content/child/web_data_consumer_handle_impl.cc

Issue 2741033003: Mojo EDK: Introduce MojoQueryHandleSignalsState API (Closed)
Patch Set: fix stupid bad DCHECK Created 3 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
« no previous file with comments | « no previous file | mojo/android/javatests/src/org/chromium/mojo/HandleMock.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "content/child/web_data_consumer_handle_impl.h" 5 #include "content/child/web_data_consumer_handle_impl.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <limits> 9 #include <limits>
10 #include <utility> 10 #include <utility>
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 const Flags kNone = FlagNone; 55 const Flags kNone = FlagNone;
56 DCHECK_EQ(flags, kNone); 56 DCHECK_EQ(flags, kNone);
57 DCHECK_LE(size, std::numeric_limits<uint32_t>::max()); 57 DCHECK_LE(size, std::numeric_limits<uint32_t>::max());
58 58
59 *read_size = 0; 59 *read_size = 0;
60 60
61 if (!size) { 61 if (!size) {
62 // Even if there is unread data available, mojo::ReadDataRaw() returns 62 // Even if there is unread data available, mojo::ReadDataRaw() returns
63 // FAILED_PRECONDITION when |size| is 0 and the producer handle was closed. 63 // FAILED_PRECONDITION when |size| is 0 and the producer handle was closed.
64 // But in this case, WebDataConsumerHandle::Reader::read() must return Ok. 64 // But in this case, WebDataConsumerHandle::Reader::read() must return Ok.
65 // So we use mojo::Wait() with 0 deadline to check whether readable or not. 65 // So we query the signals state directly.
66 MojoResult wait_result = mojo::Wait( 66 mojo::HandleSignalsState state = context_->handle()->QuerySignalsState();
67 context_->handle().get(), MOJO_HANDLE_SIGNAL_READABLE, 0, nullptr); 67 if (state.readable())
68 switch (wait_result) { 68 return Ok;
69 case MOJO_RESULT_OK: 69 if (state.never_readable())
70 return Ok; 70 return Done;
71 case MOJO_RESULT_FAILED_PRECONDITION: 71 return ShouldWait;
72 return Done;
73 case MOJO_RESULT_DEADLINE_EXCEEDED:
74 return ShouldWait;
75 default:
76 NOTREACHED();
77 return UnexpectedError;
78 }
79 } 72 }
80 73
81 uint32_t size_to_pass = size; 74 uint32_t size_to_pass = size;
82 MojoReadDataFlags flags_to_pass = MOJO_READ_DATA_FLAG_NONE; 75 MojoReadDataFlags flags_to_pass = MOJO_READ_DATA_FLAG_NONE;
83 MojoResult rv = mojo::ReadDataRaw(context_->handle().get(), data, 76 MojoResult rv = mojo::ReadDataRaw(context_->handle().get(), data,
84 &size_to_pass, flags_to_pass); 77 &size_to_pass, flags_to_pass);
85 if (rv == MOJO_RESULT_OK) 78 if (rv == MOJO_RESULT_OK)
86 *read_size = size_to_pass; 79 *read_size = size_to_pass;
87 80
88 return HandleReadResult(rv); 81 return HandleReadResult(rv);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 std::unique_ptr<blink::WebDataConsumerHandle::Reader> 144 std::unique_ptr<blink::WebDataConsumerHandle::Reader>
152 WebDataConsumerHandleImpl::obtainReader(Client* client) { 145 WebDataConsumerHandleImpl::obtainReader(Client* client) {
153 return base::WrapUnique(new ReaderImpl(context_, client)); 146 return base::WrapUnique(new ReaderImpl(context_, client));
154 } 147 }
155 148
156 const char* WebDataConsumerHandleImpl::debugName() const { 149 const char* WebDataConsumerHandleImpl::debugName() const {
157 return "WebDataConsumerHandleImpl"; 150 return "WebDataConsumerHandleImpl";
158 } 151 }
159 152
160 } // namespace content 153 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | mojo/android/javatests/src/org/chromium/mojo/HandleMock.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698