New avatar menu: Add supervised user disclaimer ("Usage and history of this user...
[chromium-blink-merge.git] / mojo / system / data_pipe_producer_dispatcher.cc
blobd3c69b610d5ce44477c7ffe878162f372e0d9636
1 // Copyright 2013 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.
5 #include "mojo/system/data_pipe_producer_dispatcher.h"
7 #include "base/logging.h"
8 #include "mojo/system/data_pipe.h"
9 #include "mojo/system/memory.h"
11 namespace mojo {
12 namespace system {
14 DataPipeProducerDispatcher::DataPipeProducerDispatcher() {
17 void DataPipeProducerDispatcher::Init(scoped_refptr<DataPipe> data_pipe) {
18 DCHECK(data_pipe.get());
19 data_pipe_ = data_pipe;
22 Dispatcher::Type DataPipeProducerDispatcher::GetType() const {
23 return kTypeDataPipeProducer;
26 DataPipeProducerDispatcher::~DataPipeProducerDispatcher() {
27 // |Close()|/|CloseImplNoLock()| should have taken care of the pipe.
28 DCHECK(!data_pipe_.get());
31 void DataPipeProducerDispatcher::CancelAllWaitersNoLock() {
32 lock().AssertAcquired();
33 data_pipe_->ProducerCancelAllWaiters();
36 void DataPipeProducerDispatcher::CloseImplNoLock() {
37 lock().AssertAcquired();
38 data_pipe_->ProducerClose();
39 data_pipe_ = NULL;
42 scoped_refptr<Dispatcher>
43 DataPipeProducerDispatcher::CreateEquivalentDispatcherAndCloseImplNoLock() {
44 lock().AssertAcquired();
46 scoped_refptr<DataPipeProducerDispatcher> rv =
47 new DataPipeProducerDispatcher();
48 rv->Init(data_pipe_);
49 data_pipe_ = NULL;
50 return scoped_refptr<Dispatcher>(rv.get());
53 MojoResult DataPipeProducerDispatcher::WriteDataImplNoLock(
54 const void* elements,
55 uint32_t* num_bytes,
56 MojoWriteDataFlags flags) {
57 lock().AssertAcquired();
59 if (!VerifyUserPointer<uint32_t>(num_bytes, 1))
60 return MOJO_RESULT_INVALID_ARGUMENT;
61 if (!VerifyUserPointer<void>(elements, *num_bytes))
62 return MOJO_RESULT_INVALID_ARGUMENT;
64 return data_pipe_->ProducerWriteData(
65 elements, num_bytes, (flags & MOJO_WRITE_DATA_FLAG_ALL_OR_NONE));
68 MojoResult DataPipeProducerDispatcher::BeginWriteDataImplNoLock(
69 void** buffer,
70 uint32_t* buffer_num_bytes,
71 MojoWriteDataFlags flags) {
72 lock().AssertAcquired();
74 if (!VerifyUserPointer<void*>(buffer, 1))
75 return MOJO_RESULT_INVALID_ARGUMENT;
76 if (!VerifyUserPointer<uint32_t>(buffer_num_bytes, 1))
77 return MOJO_RESULT_INVALID_ARGUMENT;
79 return data_pipe_->ProducerBeginWriteData(
80 buffer, buffer_num_bytes, (flags & MOJO_WRITE_DATA_FLAG_ALL_OR_NONE));
83 MojoResult DataPipeProducerDispatcher::EndWriteDataImplNoLock(
84 uint32_t num_bytes_written) {
85 lock().AssertAcquired();
87 return data_pipe_->ProducerEndWriteData(num_bytes_written);
90 MojoResult DataPipeProducerDispatcher::AddWaiterImplNoLock(
91 Waiter* waiter,
92 MojoWaitFlags flags,
93 MojoResult wake_result) {
94 lock().AssertAcquired();
95 return data_pipe_->ProducerAddWaiter(waiter, flags, wake_result);
98 void DataPipeProducerDispatcher::RemoveWaiterImplNoLock(Waiter* waiter) {
99 lock().AssertAcquired();
100 data_pipe_->ProducerRemoveWaiter(waiter);
103 bool DataPipeProducerDispatcher::IsBusyNoLock() const {
104 lock().AssertAcquired();
105 return data_pipe_->ProducerIsBusy();
108 } // namespace system
109 } // namespace mojo