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

Side by Side Diff: third_party/WebKit/Source/modules/fetch/DataConsumerTee.cpp

Issue 2172183003: Return unique_ptr<WebDataConsumerHandle::Reader> directly from obtainReader (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@gmock_cxx11
Patch Set: rebase Created 4 years, 4 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 "modules/fetch/DataConsumerTee.h" 5 #include "modules/fetch/DataConsumerTee.h"
6 6
7 #include "core/dom/ActiveDOMObject.h" 7 #include "core/dom/ActiveDOMObject.h"
8 #include "core/dom/ExecutionContext.h" 8 #include "core/dom/ExecutionContext.h"
9 #include "modules/fetch/DataConsumerHandleUtil.h" 9 #include "modules/fetch/DataConsumerHandleUtil.h"
10 #include "modules/fetch/FetchBlobDataConsumerHandle.h" 10 #include "modules/fetch/FetchBlobDataConsumerHandle.h"
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 RefPtr<DestinationContext::Proxy> m_contextProxy; 310 RefPtr<DestinationContext::Proxy> m_contextProxy;
311 }; 311 };
312 312
313 class DestinationHandle final : public WebDataConsumerHandle { 313 class DestinationHandle final : public WebDataConsumerHandle {
314 public: 314 public:
315 static std::unique_ptr<WebDataConsumerHandle> create(PassRefPtr<DestinationC ontext::Proxy> contextProxy) 315 static std::unique_ptr<WebDataConsumerHandle> create(PassRefPtr<DestinationC ontext::Proxy> contextProxy)
316 { 316 {
317 return wrapUnique(new DestinationHandle(contextProxy)); 317 return wrapUnique(new DestinationHandle(contextProxy));
318 } 318 }
319 319
320 std::unique_ptr<Reader> obtainReader(Client* client)
321 {
322 return wrapUnique(new DestinationReader(m_contextProxy, client));
323 }
324
320 private: 325 private:
321 DestinationHandle(PassRefPtr<DestinationContext::Proxy> contextProxy) : m_co ntextProxy(contextProxy) { } 326 DestinationHandle(PassRefPtr<DestinationContext::Proxy> contextProxy) : m_co ntextProxy(contextProxy) { }
322 DestinationReader* obtainReaderInternal(Client* client) { return new Destina tionReader(m_contextProxy, client); }
323 const char* debugName() const override { return "DestinationHandle"; } 327 const char* debugName() const override { return "DestinationHandle"; }
324 328
325 RefPtr<DestinationContext::Proxy> m_contextProxy; 329 RefPtr<DestinationContext::Proxy> m_contextProxy;
326 }; 330 };
327 331
328 // Bound to the created thread. 332 // Bound to the created thread.
329 class SourceContext final : public GarbageCollectedFinalized<SourceContext>, pub lic ActiveDOMObject, public WebDataConsumerHandle::Client { 333 class SourceContext final : public GarbageCollectedFinalized<SourceContext>, pub lic ActiveDOMObject, public WebDataConsumerHandle::Client {
330 USING_GARBAGE_COLLECTED_MIXIN(SourceContext); 334 USING_GARBAGE_COLLECTED_MIXIN(SourceContext);
331 public: 335 public:
332 SourceContext( 336 SourceContext(
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 RefPtr<DestinationContext> context2 = DestinationContext::create(); 415 RefPtr<DestinationContext> context2 = DestinationContext::create();
412 416
413 root->initialize(new SourceContext(root, std::move(src), context1, context2, executionContext)); 417 root->initialize(new SourceContext(root, std::move(src), context1, context2, executionContext));
414 418
415 *dest1 = DestinationHandle::create(DestinationContext::Proxy::create(context 1, tracker)); 419 *dest1 = DestinationHandle::create(DestinationContext::Proxy::create(context 1, tracker));
416 *dest2 = DestinationHandle::create(DestinationContext::Proxy::create(context 2, tracker)); 420 *dest2 = DestinationHandle::create(DestinationContext::Proxy::create(context 2, tracker));
417 } 421 }
418 422
419 void DataConsumerTee::create(ExecutionContext* executionContext, std::unique_ptr <FetchDataConsumerHandle> src, std::unique_ptr<FetchDataConsumerHandle>* dest1, std::unique_ptr<FetchDataConsumerHandle>* dest2) 423 void DataConsumerTee::create(ExecutionContext* executionContext, std::unique_ptr <FetchDataConsumerHandle> src, std::unique_ptr<FetchDataConsumerHandle>* dest1, std::unique_ptr<FetchDataConsumerHandle>* dest2)
420 { 424 {
421 RefPtr<BlobDataHandle> blobDataHandle = src->obtainReader(nullptr)->drainAsB lobDataHandle(FetchDataConsumerHandle::Reader::AllowBlobWithInvalidSize); 425 RefPtr<BlobDataHandle> blobDataHandle = src->obtainFetchDataReader(nullptr)- >drainAsBlobDataHandle(FetchDataConsumerHandle::Reader::AllowBlobWithInvalidSize );
422 if (blobDataHandle) { 426 if (blobDataHandle) {
423 *dest1 = FetchBlobDataConsumerHandle::create(executionContext, blobDataH andle); 427 *dest1 = FetchBlobDataConsumerHandle::create(executionContext, blobDataH andle);
424 *dest2 = FetchBlobDataConsumerHandle::create(executionContext, blobDataH andle); 428 *dest2 = FetchBlobDataConsumerHandle::create(executionContext, blobDataH andle);
425 return; 429 return;
426 } 430 }
427 431
428 std::unique_ptr<WebDataConsumerHandle> webDest1, webDest2; 432 std::unique_ptr<WebDataConsumerHandle> webDest1, webDest2;
429 DataConsumerTee::create(executionContext, static_cast<std::unique_ptr<WebDat aConsumerHandle>>(std::move(src)), &webDest1, &webDest2); 433 DataConsumerTee::create(executionContext, static_cast<std::unique_ptr<WebDat aConsumerHandle>>(std::move(src)), &webDest1, &webDest2);
430 *dest1 = createFetchDataConsumerHandleFromWebHandle(std::move(webDest1)); 434 *dest1 = createFetchDataConsumerHandleFromWebHandle(std::move(webDest1));
431 *dest2 = createFetchDataConsumerHandleFromWebHandle(std::move(webDest2)); 435 *dest2 = createFetchDataConsumerHandleFromWebHandle(std::move(webDest2));
432 return; 436 return;
433 } 437 }
434 438
435 } // namespace blink 439 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698