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

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

Issue 850043008: [DO NOT REVIEW][DO NOT COMMIT] Implement WebDataProducerHandleImpl. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 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
OLDNEW
(Empty)
1 // Copyright 2015 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_producer_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 using Result = blink::WebDataProducerHandle::Result;
15
16 WebDataProducerHandleImpl::WebDataProducerHandleImpl(Handle handle)
17 : handle_(handle.Pass()), client_(nullptr) {}
18
19 WebDataProducerHandleImpl::~WebDataProducerHandleImpl() {}
20
21 Result WebDataProducerHandleImpl::write(const void* data,
22 size_t size,
23 Flags flags,
24 size_t* written_size) {
25 // We need this variable definition to avoid a link error.
26 const Flags kNone = FlagNone;
27 DCHECK_EQ(flags, kNone);
28 DCHECK_LE(size, std::numeric_limits<uint32_t>::max());
29
30 *written_size = 0;
31
32 uint32_t size_to_pass = size;
33 MojoReadDataFlags flags_to_pass = MOJO_WRITE_DATA_FLAG_NONE;
34 MojoResult rv =
35 mojo::WriteDataRaw(handle_.get(), data, &size_to_pass, flags_to_pass);
36 if (rv == MOJO_RESULT_OK)
37 *written_size = size_to_pass;
38
39 return HandleWriteResult(rv);
40 }
41
42 Result WebDataProducerHandleImpl::beginWrite(void** buffer,
43 Flags flags,
44 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 *available = 0;
51
52 uint32_t size_to_pass = 0;
53 MojoReadDataFlags flags_to_pass = MOJO_WRITE_DATA_FLAG_NONE;
54
55 MojoResult rv = mojo::BeginWriteDataRaw(handle_.get(), buffer,
56 &size_to_pass, flags_to_pass);
57 if (rv == MOJO_RESULT_OK)
58 *available = size_to_pass;
59 return HandleWriteResult(rv);
60 }
61
62 Result WebDataProducerHandleImpl::endWrite(size_t written_size) {
63 MojoResult rv = mojo::EndWriteDataRaw(handle_.get(), written_size);
64 return
65 rv == MOJO_RESULT_OK ? Ok : UnexpectedError;
66 }
67
68 void WebDataProducerHandleImpl::registerClient(Client* client) {
69 DCHECK(!client_);
70 DCHECK(client);
71 client_ = client;
72
73 handle_watcher_.Start(
74 handle_.get(),
75 MOJO_HANDLE_SIGNAL_WRITABLE,
76 MOJO_DEADLINE_INDEFINITE,
77 base::Bind(&WebDataProducerHandleImpl::OnHandleGotWritable,
78 base::Unretained(this)));
79 }
80
81 void WebDataProducerHandleImpl::unregisterClient() {
82 DCHECK(client_);
83 client_ = nullptr;
84 handle_watcher_.Stop();
85 }
86
87 Result WebDataProducerHandleImpl::HandleWriteResult(MojoResult mojo_result) {
88 switch (mojo_result) {
89 case MOJO_RESULT_OK:
90 return Ok;
91 case MOJO_RESULT_FAILED_PRECONDITION:
92 return AlreadyClosed;
93 case MOJO_RESULT_SHOULD_WAIT:
94 if (client_) {
95 handle_watcher_.Start(
96 handle_.get(),
97 MOJO_HANDLE_SIGNAL_WRITABLE,
98 MOJO_DEADLINE_INDEFINITE,
99 base::Bind(&WebDataProducerHandleImpl::OnHandleGotWritable,
100 base::Unretained(this)));
101 }
102 return ShouldWait;
103 default:
104 return UnexpectedError;
105 }
106 }
107
108 void WebDataProducerHandleImpl::OnHandleGotWritable(MojoResult) {
109 DCHECK(client_);
110 client_->didGetWritable();
111 }
112
113 } // namespace content
OLDNEW
« no previous file with comments | « content/child/web_data_producer_handle_impl.h ('k') | content/child/web_data_producer_handle_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698