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

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 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
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