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

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

Issue 1403773005: Ensure that DataPipeProducerDispatcher::CreateEquivalentDispatcherAndCloseImplNoLock serializes the… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge Created 5 years, 2 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
« no previous file with comments | « mojo/edk/system/data_pipe_producer_dispatcher.h ('k') | mojo/edk/system/data_pipe_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "mojo/edk/system/data_pipe_producer_dispatcher.h" 5 #include "mojo/edk/system/data_pipe_producer_dispatcher.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "mojo/edk/embedder/embedder_internal.h" 10 #include "mojo/edk/embedder/embedder_internal.h"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 74
75 if (platform_handle.is_valid()) { 75 if (platform_handle.is_valid()) {
76 rv->Init(platform_handle.Pass(), serialized_write_buffer, 76 rv->Init(platform_handle.Pass(), serialized_write_buffer,
77 serialized_write_buffer_size); 77 serialized_write_buffer_size);
78 } 78 }
79 return rv; 79 return rv;
80 } 80 }
81 81
82 DataPipeProducerDispatcher::DataPipeProducerDispatcher( 82 DataPipeProducerDispatcher::DataPipeProducerDispatcher(
83 const MojoCreateDataPipeOptions& options) 83 const MojoCreateDataPipeOptions& options)
84 : options_(options), channel_(nullptr), error_(false) { 84 : options_(options), channel_(nullptr), error_(false), serialized_(false) {
85 } 85 }
86 86
87 DataPipeProducerDispatcher::~DataPipeProducerDispatcher() { 87 DataPipeProducerDispatcher::~DataPipeProducerDispatcher() {
88 // |Close()|/|CloseImplNoLock()| should have taken care of the channel. 88 // |Close()|/|CloseImplNoLock()| should have taken care of the channel.
89 DCHECK(!channel_); 89 DCHECK(!channel_);
90 } 90 }
91 91
92 void DataPipeProducerDispatcher::CancelAllAwakablesNoLock() { 92 void DataPipeProducerDispatcher::CancelAllAwakablesNoLock() {
93 lock().AssertAcquired(); 93 lock().AssertAcquired();
94 awakable_list_.CancelAll(); 94 awakable_list_.CancelAll();
95 } 95 }
96 96
97 void DataPipeProducerDispatcher::CloseImplNoLock() { 97 void DataPipeProducerDispatcher::CloseImplNoLock() {
98 lock().AssertAcquired(); 98 lock().AssertAcquired();
99 internal::g_io_thread_task_runner->PostTask( 99 internal::g_io_thread_task_runner->PostTask(
100 FROM_HERE, base::Bind(&DataPipeProducerDispatcher::CloseOnIO, this)); 100 FROM_HERE, base::Bind(&DataPipeProducerDispatcher::CloseOnIO, this));
101 } 101 }
102 102
103 scoped_refptr<Dispatcher> 103 scoped_refptr<Dispatcher>
104 DataPipeProducerDispatcher::CreateEquivalentDispatcherAndCloseImplNoLock() { 104 DataPipeProducerDispatcher::CreateEquivalentDispatcherAndCloseImplNoLock() {
105 lock().AssertAcquired(); 105 lock().AssertAcquired();
106 106
107 SerializeInternal();
108
107 scoped_refptr<DataPipeProducerDispatcher> rv = Create(options_); 109 scoped_refptr<DataPipeProducerDispatcher> rv = Create(options_);
108 rv->channel_ = channel_; 110 serialized_write_buffer_.swap(rv->serialized_write_buffer_);
109 channel_ = nullptr; 111 rv->serialized_platform_handle_ = serialized_platform_handle_.Pass();
110 rv->options_ = options_; 112 rv->serialized_ = true;
111 return scoped_refptr<Dispatcher>(rv.get()); 113 return scoped_refptr<Dispatcher>(rv.get());
112 } 114 }
113 115
114 MojoResult DataPipeProducerDispatcher::WriteDataImplNoLock( 116 MojoResult DataPipeProducerDispatcher::WriteDataImplNoLock(
115 const void* elements, 117 const void* elements,
116 uint32_t* num_bytes, 118 uint32_t* num_bytes,
117 MojoWriteDataFlags flags) { 119 MojoWriteDataFlags flags) {
118 lock().AssertAcquired(); 120 lock().AssertAcquired();
119 if (InTwoPhaseWrite()) 121 if (InTwoPhaseWrite())
120 return MOJO_RESULT_BUSY; 122 return MOJO_RESULT_BUSY;
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 lock().AssertAcquired(); 251 lock().AssertAcquired();
250 awakable_list_.Remove(awakable); 252 awakable_list_.Remove(awakable);
251 if (signals_state) 253 if (signals_state)
252 *signals_state = GetHandleSignalsStateImplNoLock(); 254 *signals_state = GetHandleSignalsStateImplNoLock();
253 } 255 }
254 256
255 void DataPipeProducerDispatcher::StartSerializeImplNoLock( 257 void DataPipeProducerDispatcher::StartSerializeImplNoLock(
256 size_t* max_size, 258 size_t* max_size,
257 size_t* max_platform_handles) { 259 size_t* max_platform_handles) {
258 DCHECK(HasOneRef()); // Only one ref => no need to take the lock. 260 DCHECK(HasOneRef()); // Only one ref => no need to take the lock.
261 if (!serialized_)
262 SerializeInternal();
259 263
260 if (channel_) {
261 std::vector<char> serialized_read_buffer;
262 serialized_platform_handle_ = channel_->ReleaseHandle(
263 &serialized_read_buffer, &serialized_write_buffer_);
264 channel_ = nullptr;
265 CHECK(serialized_read_buffer.empty());
266 }
267 DataPipe::StartSerialize(serialized_platform_handle_.is_valid(), 264 DataPipe::StartSerialize(serialized_platform_handle_.is_valid(),
268 !serialized_write_buffer_.empty(), max_size, 265 !serialized_write_buffer_.empty(), max_size,
269 max_platform_handles); 266 max_platform_handles);
270 } 267 }
271 268
272 bool DataPipeProducerDispatcher::EndSerializeAndCloseImplNoLock( 269 bool DataPipeProducerDispatcher::EndSerializeAndCloseImplNoLock(
273 void* destination, 270 void* destination,
274 size_t* actual_size, 271 size_t* actual_size,
275 PlatformHandleVector* platform_handles) { 272 PlatformHandleVector* platform_handles) {
276 DCHECK(HasOneRef()); // Only one ref => no need to take the lock. 273 DCHECK(HasOneRef()); // Only one ref => no need to take the lock.
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 error_ = true; 368 error_ = true;
372 return false; 369 return false;
373 } 370 }
374 371
375 offset += message_num_bytes; 372 offset += message_num_bytes;
376 } 373 }
377 374
378 return true; 375 return true;
379 } 376 }
380 377
378 void DataPipeProducerDispatcher::SerializeInternal() {
379 // We need to stop watching handle immediately, even though not on IO thread,
380 // so that other messages aren't read after this.
381 if (channel_) {
382 std::vector<char> serialized_read_buffer;
383 serialized_platform_handle_ = channel_->ReleaseHandle(
384 &serialized_read_buffer, &serialized_write_buffer_);
385 CHECK(serialized_read_buffer.empty());
386 channel_ = nullptr;
387 }
388 serialized_ = true;
389 }
390
381 } // namespace edk 391 } // namespace edk
382 } // namespace mojo 392 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/data_pipe_producer_dispatcher.h ('k') | mojo/edk/system/data_pipe_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698