| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/browser/loader/mojo_async_resource_handler.h" | 5 #include "content/browser/loader/mojo_async_resource_handler.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 | 53 |
| 54 void InitializeResourceBufferConstants() { | 54 void InitializeResourceBufferConstants() { |
| 55 static bool did_init = false; | 55 static bool did_init = false; |
| 56 if (did_init) | 56 if (did_init) |
| 57 return; | 57 return; |
| 58 did_init = true; | 58 did_init = true; |
| 59 | 59 |
| 60 GetNumericArg("resource-buffer-size", &g_allocation_size); | 60 GetNumericArg("resource-buffer-size", &g_allocation_size); |
| 61 } | 61 } |
| 62 | 62 |
| 63 void NotReached(mojom::URLLoaderAssociatedRequest mojo_request, | 63 void NotReached(mojom::URLLoaderRequest mojo_request, |
| 64 mojom::URLLoaderClientPtr url_loader_client) { | 64 mojom::URLLoaderClientPtr url_loader_client) { |
| 65 NOTREACHED(); | 65 NOTREACHED(); |
| 66 } | 66 } |
| 67 | 67 |
| 68 } // namespace | 68 } // namespace |
| 69 | 69 |
| 70 // This class is for sharing the ownership of a ScopedDataPipeProducerHandle | 70 // This class is for sharing the ownership of a ScopedDataPipeProducerHandle |
| 71 // between WriterIOBuffer and MojoAsyncResourceHandler. | 71 // between WriterIOBuffer and MojoAsyncResourceHandler. |
| 72 class MojoAsyncResourceHandler::SharedWriter final | 72 class MojoAsyncResourceHandler::SharedWriter final |
| 73 : public base::RefCountedThreadSafe<SharedWriter> { | 73 : public base::RefCountedThreadSafe<SharedWriter> { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 | 108 |
| 109 // This member is for keeping the writer alive. | 109 // This member is for keeping the writer alive. |
| 110 scoped_refptr<SharedWriter> writer_; | 110 scoped_refptr<SharedWriter> writer_; |
| 111 | 111 |
| 112 DISALLOW_COPY_AND_ASSIGN(WriterIOBuffer); | 112 DISALLOW_COPY_AND_ASSIGN(WriterIOBuffer); |
| 113 }; | 113 }; |
| 114 | 114 |
| 115 MojoAsyncResourceHandler::MojoAsyncResourceHandler( | 115 MojoAsyncResourceHandler::MojoAsyncResourceHandler( |
| 116 net::URLRequest* request, | 116 net::URLRequest* request, |
| 117 ResourceDispatcherHostImpl* rdh, | 117 ResourceDispatcherHostImpl* rdh, |
| 118 mojom::URLLoaderAssociatedRequest mojo_request, | 118 mojom::URLLoaderRequest mojo_request, |
| 119 mojom::URLLoaderClientPtr url_loader_client, | 119 mojom::URLLoaderClientPtr url_loader_client, |
| 120 ResourceType resource_type) | 120 ResourceType resource_type) |
| 121 : ResourceHandler(request), | 121 : ResourceHandler(request), |
| 122 rdh_(rdh), | 122 rdh_(rdh), |
| 123 binding_(this, std::move(mojo_request)), | 123 binding_(this, std::move(mojo_request)), |
| 124 handle_watcher_(FROM_HERE, mojo::SimpleWatcher::ArmingPolicy::MANUAL), | 124 handle_watcher_(FROM_HERE, mojo::SimpleWatcher::ArmingPolicy::MANUAL), |
| 125 url_loader_client_(std::move(url_loader_client)), | 125 url_loader_client_(std::move(url_loader_client)), |
| 126 weak_factory_(this) { | 126 weak_factory_(this) { |
| 127 DCHECK(url_loader_client_); | 127 DCHECK(url_loader_client_); |
| 128 InitializeResourceBufferConstants(); | 128 InitializeResourceBufferConstants(); |
| (...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 580 | 580 |
| 581 std::unique_ptr<UploadProgressTracker> | 581 std::unique_ptr<UploadProgressTracker> |
| 582 MojoAsyncResourceHandler::CreateUploadProgressTracker( | 582 MojoAsyncResourceHandler::CreateUploadProgressTracker( |
| 583 const tracked_objects::Location& from_here, | 583 const tracked_objects::Location& from_here, |
| 584 UploadProgressTracker::UploadProgressReportCallback callback) { | 584 UploadProgressTracker::UploadProgressReportCallback callback) { |
| 585 return base::MakeUnique<UploadProgressTracker>(from_here, std::move(callback), | 585 return base::MakeUnique<UploadProgressTracker>(from_here, std::move(callback), |
| 586 request()); | 586 request()); |
| 587 } | 587 } |
| 588 | 588 |
| 589 void MojoAsyncResourceHandler::OnTransfer( | 589 void MojoAsyncResourceHandler::OnTransfer( |
| 590 mojom::URLLoaderAssociatedRequest mojo_request, | 590 mojom::URLLoaderRequest mojo_request, |
| 591 mojom::URLLoaderClientPtr url_loader_client) { | 591 mojom::URLLoaderClientPtr url_loader_client) { |
| 592 binding_.Unbind(); | 592 binding_.Unbind(); |
| 593 binding_.Bind(std::move(mojo_request)); | 593 binding_.Bind(std::move(mojo_request)); |
| 594 binding_.set_connection_error_handler( | 594 binding_.set_connection_error_handler( |
| 595 base::Bind(&MojoAsyncResourceHandler::Cancel, base::Unretained(this))); | 595 base::Bind(&MojoAsyncResourceHandler::Cancel, base::Unretained(this))); |
| 596 url_loader_client_ = std::move(url_loader_client); | 596 url_loader_client_ = std::move(url_loader_client); |
| 597 } | 597 } |
| 598 | 598 |
| 599 void MojoAsyncResourceHandler::SendUploadProgress( | 599 void MojoAsyncResourceHandler::SendUploadProgress( |
| 600 const net::UploadProgress& progress) { | 600 const net::UploadProgress& progress) { |
| 601 url_loader_client_->OnUploadProgress( | 601 url_loader_client_->OnUploadProgress( |
| 602 progress.position(), progress.size(), | 602 progress.position(), progress.size(), |
| 603 base::Bind(&MojoAsyncResourceHandler::OnUploadProgressACK, | 603 base::Bind(&MojoAsyncResourceHandler::OnUploadProgressACK, |
| 604 weak_factory_.GetWeakPtr())); | 604 weak_factory_.GetWeakPtr())); |
| 605 } | 605 } |
| 606 | 606 |
| 607 void MojoAsyncResourceHandler::OnUploadProgressACK() { | 607 void MojoAsyncResourceHandler::OnUploadProgressACK() { |
| 608 if (upload_progress_tracker_) | 608 if (upload_progress_tracker_) |
| 609 upload_progress_tracker_->OnAckReceived(); | 609 upload_progress_tracker_->OnAckReceived(); |
| 610 } | 610 } |
| 611 | 611 |
| 612 } // namespace content | 612 } // namespace content |
| OLD | NEW |