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

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

Issue 620303002: Implement WebDataConsumerHandle. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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
OLDNEW
(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 *read_size = 0;
32
33 uint32_t size_to_pass = size;
34 MojoReadDataFlags flags_to_pass = MOJO_READ_DATA_FLAG_NONE;
35 MojoResult rv =
36 mojo::ReadDataRaw(handle_.get(), data, &size_to_pass, flags_to_pass);
37 if (rv == MOJO_RESULT_OK)
38 *read_size = size_to_pass;
39
40 return HandleReadResult(rv);
41 }
42
43 Result WebDataConsumerHandleImpl::beginRead(
44 const void** buffer, Flags flags, size_t* available) {
45 // We need this variable definition to avoid a link error.
46 const Flags kNone = FlagNone;
47 DCHECK_EQ(flags, kNone);
48
49 *buffer = nullptr;
50
51 uint32_t size_to_pass = 0;
52 MojoReadDataFlags flags_to_pass = MOJO_READ_DATA_FLAG_NONE;
53
54 MojoResult rv = mojo::BeginReadDataRaw(handle_.get(), buffer,
55 &size_to_pass, flags_to_pass);
56 *available = rv == Ok ? size_to_pass : 0;
nasko 2014/10/28 04:10:18 Please split.
yhirano 2014/10/28 05:21:02 Done (I replaced Ok with MOJO_RESULT_OK because I
57 return HandleReadResult(rv);
58 }
59
60 Result WebDataConsumerHandleImpl::endRead(size_t read_size) {
61 MojoResult rv = mojo::EndReadDataRaw(handle_.get(), read_size);
62 return
63 rv == MOJO_RESULT_OK ? Ok : UnexpectedError;
nasko 2014/10/28 04:10:18 Please split.
yhirano 2014/10/28 04:24:34 I don't understand your intention here: Do you wan
nasko 2014/10/28 05:05:21 Sorry, this one was my mistake.
64 }
65
66 void WebDataConsumerHandleImpl::registerClient(Client* client) {
67 DCHECK(!client_);
68 DCHECK(client);
69 client_ = client;
70
71 handle_watcher_.Start(
72 handle_.get(),
73 MOJO_HANDLE_SIGNAL_READABLE,
74 MOJO_DEADLINE_INDEFINITE,
75 base::Bind(&WebDataConsumerHandleImpl::OnHandleGotReadable,
76 base::Unretained(this)));
77 }
78
79 void WebDataConsumerHandleImpl::unregisterClient() {
80 client_ = nullptr;
81 handle_watcher_.Stop();
82 }
83
84 Result WebDataConsumerHandleImpl::HandleReadResult(MojoResult mojo_result) {
85 switch (mojo_result) {
86 case MOJO_RESULT_OK:
87 return Ok;
88 case MOJO_RESULT_FAILED_PRECONDITION:
89 return Done;
90 case MOJO_RESULT_BUSY:
91 return Busy;
92 case MOJO_RESULT_SHOULD_WAIT:
93 if (client_) {
94 handle_watcher_.Start(
95 handle_.get(),
96 MOJO_HANDLE_SIGNAL_READABLE,
97 MOJO_DEADLINE_INDEFINITE,
98 base::Bind(&WebDataConsumerHandleImpl::OnHandleGotReadable,
99 base::Unretained(this)));
100 }
101 return ShouldWait;
102 case MOJO_RESULT_RESOURCE_EXHAUSTED:
103 return ResourceExhausted;
104 default:
105 return UnexpectedError;
106 }
107 }
108
109 void WebDataConsumerHandleImpl::OnHandleGotReadable(MojoResult) {
110 DCHECK(client_);
111 client_->didGetReadable();
112 }
113
114 } // namespace content
OLDNEW
« no previous file with comments | « content/child/web_data_consumer_handle_impl.h ('k') | content/child/web_data_consumer_handle_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698