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

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

Issue 2101943004: content: Change auto to not deduce raw pointers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase/update Created 4 years, 5 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 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 "content/child/shared_memory_data_consumer_handle.h" 5 #include "content/child/shared_memory_data_consumer_handle.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <deque> 8 #include <deque>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 // We post a task even in the writer thread in order to avoid a 82 // We post a task even in the writer thread in order to avoid a
83 // reentrance problem as calling |on_reader_detached_| may manipulate 83 // reentrance problem as calling |on_reader_detached_| may manipulate
84 // the context synchronously. 84 // the context synchronously.
85 writer_task_runner_->PostTask(FROM_HERE, on_reader_detached_); 85 writer_task_runner_->PostTask(FROM_HERE, on_reader_detached_);
86 } 86 }
87 Clear(); 87 Clear();
88 } 88 }
89 } 89 }
90 void ClearQueue() { 90 void ClearQueue() {
91 lock_.AssertAcquired(); 91 lock_.AssertAcquired();
92 for (auto& data : queue_) { 92 for (auto* data : queue_) {
93 delete data; 93 delete data;
94 } 94 }
95 queue_.clear(); 95 queue_.clear();
96 first_offset_ = 0; 96 first_offset_ = 0;
97 } 97 }
98 RequestPeer::ThreadSafeReceivedData* Top() { 98 RequestPeer::ThreadSafeReceivedData* Top() {
99 lock_.AssertAcquired(); 99 lock_.AssertAcquired();
100 return queue_.front(); 100 return queue_.front();
101 } 101 }
102 void Push(std::unique_ptr<RequestPeer::ThreadSafeReceivedData> data) { 102 void Push(std::unique_ptr<RequestPeer::ThreadSafeReceivedData> data) {
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 lock_.AssertAcquired(); 179 lock_.AssertAcquired();
180 return is_handle_active_; 180 return is_handle_active_;
181 } 181 }
182 void set_is_handle_active(bool b) { 182 void set_is_handle_active(bool b) {
183 lock_.AssertAcquired(); 183 lock_.AssertAcquired();
184 is_handle_active_ = b; 184 is_handle_active_ = b;
185 } 185 }
186 void Consume(size_t s) { 186 void Consume(size_t s) {
187 lock_.AssertAcquired(); 187 lock_.AssertAcquired();
188 first_offset_ += s; 188 first_offset_ += s;
189 auto top = Top(); 189 auto* top = Top();
190 if (static_cast<size_t>(top->length()) <= first_offset_) { 190 if (static_cast<size_t>(top->length()) <= first_offset_) {
191 delete top; 191 delete top;
192 queue_.pop_front(); 192 queue_.pop_front();
193 first_offset_ = 0; 193 first_offset_ = 0;
194 } 194 }
195 } 195 }
196 bool is_two_phase_read_in_progress() const { 196 bool is_two_phase_read_in_progress() const {
197 lock_.AssertAcquired(); 197 lock_.AssertAcquired();
198 return is_two_phase_read_in_progress_; 198 return is_two_phase_read_in_progress_;
199 } 199 }
(...skipping 25 matching lines...) Expand all
225 if (repost) { 225 if (repost) {
226 // We don't re-post the task when the runner changes while waiting for 226 // We don't re-post the task when the runner changes while waiting for
227 // this task because in this case a new reader is obtained and 227 // this task because in this case a new reader is obtained and
228 // notification is already done at the reader creation time if necessary. 228 // notification is already done at the reader creation time if necessary.
229 runner->PostTask(FROM_HERE, 229 runner->PostTask(FROM_HERE,
230 base::Bind(&Context::NotifyInternal, this, false)); 230 base::Bind(&Context::NotifyInternal, this, false));
231 } 231 }
232 } 232 }
233 void Clear() { 233 void Clear() {
234 lock_.AssertAcquired(); 234 lock_.AssertAcquired();
235 for (auto& data : queue_) { 235 for (auto* data : queue_) {
236 delete data; 236 delete data;
237 } 237 }
238 queue_.clear(); 238 queue_.clear();
239 first_offset_ = 0; 239 first_offset_ = 0;
240 client_ = nullptr; 240 client_ = nullptr;
241 // Note this doesn't work in the destructor if |on_reader_detached_| is not 241 // Note this doesn't work in the destructor if |on_reader_detached_| is not
242 // null. We have an assert in the destructor. 242 // null. We have an assert in the destructor.
243 ResetOnReaderDetached(); 243 ResetOnReaderDetached();
244 } 244 }
245 // Must be called with |lock_| not aquired. 245 // Must be called with |lock_| not aquired.
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 size_t total_read_size = 0; 385 size_t total_read_size = 0;
386 *read_size_to_return = 0; 386 *read_size_to_return = 0;
387 387
388 if (context_->result() == Ok && context_->is_two_phase_read_in_progress()) 388 if (context_->result() == Ok && context_->is_two_phase_read_in_progress())
389 context_->set_result(UnexpectedError); 389 context_->set_result(UnexpectedError);
390 390
391 if (context_->result() != Ok && context_->result() != Done) 391 if (context_->result() != Ok && context_->result() != Done)
392 return context_->result(); 392 return context_->result();
393 393
394 while (!context_->IsEmpty() && total_read_size < size) { 394 while (!context_->IsEmpty() && total_read_size < size) {
395 const auto& top = context_->Top(); 395 auto* top = context_->Top();
396 size_t readable = top->length() - context_->first_offset(); 396 size_t readable = top->length() - context_->first_offset();
397 size_t writable = size - total_read_size; 397 size_t writable = size - total_read_size;
398 size_t read_size = std::min(readable, writable); 398 size_t read_size = std::min(readable, writable);
399 const char* begin = top->payload() + context_->first_offset(); 399 const char* begin = top->payload() + context_->first_offset();
400 std::copy(begin, begin + read_size, 400 std::copy(begin, begin + read_size,
401 static_cast<char*>(data) + total_read_size); 401 static_cast<char*>(data) + total_read_size);
402 total_read_size += read_size; 402 total_read_size += read_size;
403 context_->Consume(read_size); 403 context_->Consume(read_size);
404 } 404 }
405 *read_size_to_return = total_read_size; 405 *read_size_to_return = total_read_size;
(...skipping 16 matching lines...) Expand all
422 if (context_->result() == Ok && context_->is_two_phase_read_in_progress()) 422 if (context_->result() == Ok && context_->is_two_phase_read_in_progress())
423 context_->set_result(UnexpectedError); 423 context_->set_result(UnexpectedError);
424 424
425 if (context_->result() != Ok && context_->result() != Done) 425 if (context_->result() != Ok && context_->result() != Done)
426 return context_->result(); 426 return context_->result();
427 427
428 if (context_->IsEmpty()) 428 if (context_->IsEmpty())
429 return context_->result() == Done ? Done : ShouldWait; 429 return context_->result() == Done ? Done : ShouldWait;
430 430
431 context_->set_is_two_phase_read_in_progress(true); 431 context_->set_is_two_phase_read_in_progress(true);
432 const auto& top = context_->Top(); 432 auto* top = context_->Top();
433 *buffer = top->payload() + context_->first_offset(); 433 *buffer = top->payload() + context_->first_offset();
434 *available = top->length() - context_->first_offset(); 434 *available = top->length() - context_->first_offset();
435 435
436 return Ok; 436 return Ok;
437 } 437 }
438 438
439 Result SharedMemoryDataConsumerHandle::ReaderImpl::endRead(size_t read_size) { 439 Result SharedMemoryDataConsumerHandle::ReaderImpl::endRead(size_t read_size) {
440 base::AutoLock lock(context_->lock()); 440 base::AutoLock lock(context_->lock());
441 441
442 if (!context_->is_two_phase_read_in_progress()) 442 if (!context_->is_two_phase_read_in_progress())
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 SharedMemoryDataConsumerHandle::ReaderImpl* 480 SharedMemoryDataConsumerHandle::ReaderImpl*
481 SharedMemoryDataConsumerHandle::obtainReaderInternal(Client* client) { 481 SharedMemoryDataConsumerHandle::obtainReaderInternal(Client* client) {
482 return new ReaderImpl(context_, client); 482 return new ReaderImpl(context_, client);
483 } 483 }
484 484
485 const char* SharedMemoryDataConsumerHandle::debugName() const { 485 const char* SharedMemoryDataConsumerHandle::debugName() const {
486 return "SharedMemoryDataConsumerHandle"; 486 return "SharedMemoryDataConsumerHandle";
487 } 487 }
488 488
489 } // namespace content 489 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698