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

Side by Side Diff: mojo/edk/system/data_pipe_consumer_dispatcher.cc

Issue 814543006: Move //mojo/{public, edk} underneath //third_party (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase 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 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.
4
5 #include "mojo/edk/system/data_pipe_consumer_dispatcher.h"
6
7 #include "base/logging.h"
8 #include "mojo/edk/system/data_pipe.h"
9 #include "mojo/edk/system/memory.h"
10
11 namespace mojo {
12 namespace system {
13
14 DataPipeConsumerDispatcher::DataPipeConsumerDispatcher() {
15 }
16
17 void DataPipeConsumerDispatcher::Init(scoped_refptr<DataPipe> data_pipe) {
18 DCHECK(data_pipe);
19 data_pipe_ = data_pipe;
20 }
21
22 Dispatcher::Type DataPipeConsumerDispatcher::GetType() const {
23 return kTypeDataPipeConsumer;
24 }
25
26 DataPipeConsumerDispatcher::~DataPipeConsumerDispatcher() {
27 // |Close()|/|CloseImplNoLock()| should have taken care of the pipe.
28 DCHECK(!data_pipe_);
29 }
30
31 void DataPipeConsumerDispatcher::CancelAllAwakablesNoLock() {
32 lock().AssertAcquired();
33 data_pipe_->ConsumerCancelAllAwakables();
34 }
35
36 void DataPipeConsumerDispatcher::CloseImplNoLock() {
37 lock().AssertAcquired();
38 data_pipe_->ConsumerClose();
39 data_pipe_ = nullptr;
40 }
41
42 scoped_refptr<Dispatcher>
43 DataPipeConsumerDispatcher::CreateEquivalentDispatcherAndCloseImplNoLock() {
44 lock().AssertAcquired();
45
46 scoped_refptr<DataPipeConsumerDispatcher> rv =
47 new DataPipeConsumerDispatcher();
48 rv->Init(data_pipe_);
49 data_pipe_ = nullptr;
50 return scoped_refptr<Dispatcher>(rv.get());
51 }
52
53 MojoResult DataPipeConsumerDispatcher::ReadDataImplNoLock(
54 UserPointer<void> elements,
55 UserPointer<uint32_t> num_bytes,
56 MojoReadDataFlags flags) {
57 lock().AssertAcquired();
58
59 if ((flags & MOJO_READ_DATA_FLAG_DISCARD)) {
60 // These flags are mutally exclusive.
61 if ((flags & MOJO_READ_DATA_FLAG_QUERY) ||
62 (flags & MOJO_READ_DATA_FLAG_PEEK))
63 return MOJO_RESULT_INVALID_ARGUMENT;
64 DVLOG_IF(2, !elements.IsNull())
65 << "Discard mode: ignoring non-null |elements|";
66 return data_pipe_->ConsumerDiscardData(
67 num_bytes, (flags & MOJO_READ_DATA_FLAG_ALL_OR_NONE));
68 }
69
70 if ((flags & MOJO_READ_DATA_FLAG_QUERY)) {
71 if ((flags & MOJO_READ_DATA_FLAG_PEEK))
72 return MOJO_RESULT_INVALID_ARGUMENT;
73 DCHECK(!(flags & MOJO_READ_DATA_FLAG_DISCARD)); // Handled above.
74 DVLOG_IF(2, !elements.IsNull())
75 << "Query mode: ignoring non-null |elements|";
76 return data_pipe_->ConsumerQueryData(num_bytes);
77 }
78
79 return data_pipe_->ConsumerReadData(
80 elements, num_bytes, !!(flags & MOJO_READ_DATA_FLAG_ALL_OR_NONE),
81 !!(flags & MOJO_READ_DATA_FLAG_PEEK));
82 }
83
84 MojoResult DataPipeConsumerDispatcher::BeginReadDataImplNoLock(
85 UserPointer<const void*> buffer,
86 UserPointer<uint32_t> buffer_num_bytes,
87 MojoReadDataFlags flags) {
88 lock().AssertAcquired();
89
90 // These flags may not be used in two-phase mode.
91 if ((flags & MOJO_READ_DATA_FLAG_DISCARD) ||
92 (flags & MOJO_READ_DATA_FLAG_QUERY) || (flags & MOJO_READ_DATA_FLAG_PEEK))
93 return MOJO_RESULT_INVALID_ARGUMENT;
94
95 return data_pipe_->ConsumerBeginReadData(
96 buffer, buffer_num_bytes, (flags & MOJO_READ_DATA_FLAG_ALL_OR_NONE));
97 }
98
99 MojoResult DataPipeConsumerDispatcher::EndReadDataImplNoLock(
100 uint32_t num_bytes_read) {
101 lock().AssertAcquired();
102
103 return data_pipe_->ConsumerEndReadData(num_bytes_read);
104 }
105
106 HandleSignalsState DataPipeConsumerDispatcher::GetHandleSignalsStateImplNoLock()
107 const {
108 lock().AssertAcquired();
109 return data_pipe_->ConsumerGetHandleSignalsState();
110 }
111
112 MojoResult DataPipeConsumerDispatcher::AddAwakableImplNoLock(
113 Awakable* awakable,
114 MojoHandleSignals signals,
115 uint32_t context,
116 HandleSignalsState* signals_state) {
117 lock().AssertAcquired();
118 return data_pipe_->ConsumerAddAwakable(awakable, signals, context,
119 signals_state);
120 }
121
122 void DataPipeConsumerDispatcher::RemoveAwakableImplNoLock(
123 Awakable* awakable,
124 HandleSignalsState* signals_state) {
125 lock().AssertAcquired();
126 data_pipe_->ConsumerRemoveAwakable(awakable, signals_state);
127 }
128
129 bool DataPipeConsumerDispatcher::IsBusyNoLock() const {
130 lock().AssertAcquired();
131 return data_pipe_->ConsumerIsBusy();
132 }
133
134 } // namespace system
135 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/data_pipe_consumer_dispatcher.h ('k') | mojo/edk/system/data_pipe_producer_dispatcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698