OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "content/child/web_data_consumer_handle_impl.h" | |
6 | |
7 #include <limits> | |
8 #include "base/bind.h" | |
9 #include "base/logging.h" | |
10 #include "mojo/public/c/system/types.h" | |
11 | |
12 namespace content { | |
13 | |
14 typedef blink::WebDataConsumerHandle::Result Result; | |
15 | |
16 WebDataConsumerHandleImpl::WebDataConsumerHandleImpl(Handle handle) | |
17 : handle_(handle.Pass()), client_(nullptr) {} | |
18 | |
19 WebDataConsumerHandleImpl::~WebDataConsumerHandleImpl() {} | |
20 | |
21 Result WebDataConsumerHandleImpl::read( | |
22 void* data, | |
23 size_t size, | |
24 Flags flags, | |
25 size_t* read_size) { | |
26 // We need this variable definition to avoid a link error. | |
27 const Flags kNone = FlagNone; | |
28 DCHECK_EQ(flags, kNone); | |
29 DCHECK_LE(size, std::numeric_limits<uint32_t>::max()); | |
30 | |
31 uint32_t size_to_pass = size; | |
32 MojoReadDataFlags flags_to_pass = MOJO_READ_DATA_FLAG_NONE; | |
33 MojoResult rv = | |
34 mojo::ReadDataRaw(handle_.get(), data, &size_to_pass, flags_to_pass); | |
35 *read_size = | |
36 rv == MOJO_RESULT_OK ? size_to_pass : 0; | |
nasko
2014/10/27 16:53:41
The initial comment was not about breaking the sta
yhirano
2014/10/28 01:54:47
Done.
nasko
2014/10/28 04:10:18
The same pattern appears in the rest of the file a
| |
37 | |
38 return HandleReadResult(rv); | |
39 } | |
40 | |
41 Result WebDataConsumerHandleImpl::beginRead( | |
42 const void** buffer, Flags flags, size_t* available) { | |
43 // We need this variable definition to avoid a link error. | |
44 const Flags kNone = FlagNone; | |
45 DCHECK_EQ(flags, kNone); | |
46 | |
47 *buffer = nullptr; | |
48 | |
49 uint32_t size_to_pass = 0; | |
50 MojoReadDataFlags flags_to_pass = MOJO_READ_DATA_FLAG_NONE; | |
51 | |
52 MojoResult rv = mojo::BeginReadDataRaw(handle_.get(), buffer, | |
53 &size_to_pass, flags_to_pass); | |
54 *available = rv == Ok ? size_to_pass : 0; | |
55 return HandleReadResult(rv); | |
56 } | |
57 | |
58 Result WebDataConsumerHandleImpl::endRead(size_t read_size) { | |
59 MojoResult rv = mojo::EndReadDataRaw(handle_.get(), read_size); | |
60 return | |
61 rv == MOJO_RESULT_OK ? Ok : UnexpectedError; | |
62 } | |
63 | |
64 void WebDataConsumerHandleImpl::registerClient(Client* client) { | |
65 DCHECK(!client_); | |
66 DCHECK(client); | |
67 client_ = client; | |
68 | |
69 handle_watcher_.Start( | |
70 handle_.get(), | |
71 MOJO_HANDLE_SIGNAL_READABLE, | |
72 MOJO_DEADLINE_INDEFINITE, | |
73 base::Bind(&WebDataConsumerHandleImpl::OnHandleGotReadable, | |
74 base::Unretained(this))); | |
75 } | |
76 | |
77 void WebDataConsumerHandleImpl::unregisterClient() { | |
78 client_ = nullptr; | |
79 handle_watcher_.Stop(); | |
80 } | |
81 | |
82 Result WebDataConsumerHandleImpl::HandleReadResult(MojoResult mojo_result) { | |
83 switch (mojo_result) { | |
84 case MOJO_RESULT_OK: | |
85 return Ok; | |
86 case MOJO_RESULT_FAILED_PRECONDITION: | |
87 return Done; | |
88 case MOJO_RESULT_BUSY: | |
89 return Busy; | |
90 case MOJO_RESULT_SHOULD_WAIT: | |
91 if (client_) { | |
92 handle_watcher_.Start( | |
93 handle_.get(), | |
94 MOJO_HANDLE_SIGNAL_READABLE, | |
95 MOJO_DEADLINE_INDEFINITE, | |
96 base::Bind(&WebDataConsumerHandleImpl::OnHandleGotReadable, | |
97 base::Unretained(this))); | |
98 } | |
99 return ShouldWait; | |
100 case MOJO_RESULT_RESOURCE_EXHAUSTED: | |
101 return ResourceExhausted; | |
102 default: | |
103 return UnexpectedError; | |
104 } | |
105 } | |
106 | |
107 void WebDataConsumerHandleImpl::OnHandleGotReadable(MojoResult) { | |
108 DCHECK(client_); | |
109 client_->didGetReadable(); | |
110 } | |
111 | |
112 } // namespace content | |
OLD | NEW |