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

Side by Side Diff: content/browser/loader/mojo_async_resource_handler.h

Issue 2574143003: Implement upload progress handling in Mojo loading (Closed)
Patch Set: +#include. +forward decl. +DISALLOW_COPY_AND_ASSIGN. Created 3 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
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 #ifndef CONTENT_BROWSER_LOADER_MOJO_ASYNC_RESOURCE_HANDLER_H_ 5 #ifndef CONTENT_BROWSER_LOADER_MOJO_ASYNC_RESOURCE_HANDLER_H_
6 #define CONTENT_BROWSER_LOADER_MOJO_ASYNC_RESOURCE_HANDLER_H_ 6 #define CONTENT_BROWSER_LOADER_MOJO_ASYNC_RESOURCE_HANDLER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
11 #include <string> 11 #include <string>
12 12
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
16 #include "base/timer/timer.h"
17 #include "content/browser/loader/resource_handler.h" 16 #include "content/browser/loader/resource_handler.h"
17 #include "content/browser/loader/upload_progress_tracker.h"
18 #include "content/common/content_export.h" 18 #include "content/common/content_export.h"
19 #include "content/common/url_loader.mojom.h" 19 #include "content/common/url_loader.mojom.h"
20 #include "mojo/public/cpp/bindings/associated_binding.h" 20 #include "mojo/public/cpp/bindings/associated_binding.h"
21 #include "mojo/public/cpp/system/data_pipe.h" 21 #include "mojo/public/cpp/system/data_pipe.h"
22 #include "mojo/public/cpp/system/watcher.h" 22 #include "mojo/public/cpp/system/watcher.h"
23 #include "net/base/io_buffer.h" 23 #include "net/base/io_buffer.h"
24 #include "url/gurl.h" 24
25 class GURL;
26
27 namespace tracked_objects {
28 class Location;
29 }
25 30
26 namespace net { 31 namespace net {
27 class IOBufferWithSize; 32 class IOBufferWithSize;
28 class URLRequest; 33 class URLRequest;
29 } 34 }
30 35
31 namespace content { 36 namespace content {
32 class ResourceDispatcherHostImpl; 37 class ResourceDispatcherHostImpl;
33 struct ResourceResponse; 38 struct ResourceResponse;
34 39
(...skipping 23 matching lines...) Expand all
58 bool OnResponseStarted(ResourceResponse* response, bool* defer) override; 63 bool OnResponseStarted(ResourceResponse* response, bool* defer) override;
59 bool OnWillStart(const GURL& url, bool* defer) override; 64 bool OnWillStart(const GURL& url, bool* defer) override;
60 bool OnWillRead(scoped_refptr<net::IOBuffer>* buf, 65 bool OnWillRead(scoped_refptr<net::IOBuffer>* buf,
61 int* buf_size, 66 int* buf_size,
62 int min_size) override; 67 int min_size) override;
63 bool OnReadCompleted(int bytes_read, bool* defer) override; 68 bool OnReadCompleted(int bytes_read, bool* defer) override;
64 void OnResponseCompleted(const net::URLRequestStatus& status, 69 void OnResponseCompleted(const net::URLRequestStatus& status,
65 bool* defer) override; 70 bool* defer) override;
66 void OnDataDownloaded(int bytes_downloaded) override; 71 void OnDataDownloaded(int bytes_downloaded) override;
67 72
68 // mojom::URLLoader implementation 73 // mojom::URLLoader implementation:
69 void FollowRedirect() override; 74 void FollowRedirect() override;
70 75
71 void OnWritableForTesting(); 76 void OnWritableForTesting();
72 static void SetAllocationSizeForTesting(size_t size); 77 static void SetAllocationSizeForTesting(size_t size);
73 static constexpr size_t kDefaultAllocationSize = 512 * 1024; 78 static constexpr size_t kDefaultAllocationSize = 512 * 1024;
74 79
75 protected: 80 protected:
76 // These functions can be overriden only for tests. 81 // These functions can be overriden only for tests.
77 virtual MojoResult BeginWrite(void** data, uint32_t* available); 82 virtual MojoResult BeginWrite(void** data, uint32_t* available);
78 virtual MojoResult EndWrite(uint32_t written); 83 virtual MojoResult EndWrite(uint32_t written);
(...skipping 12 matching lines...) Expand all
91 bool AllocateWriterIOBuffer(scoped_refptr<net::IOBufferWithSize>* buf, 96 bool AllocateWriterIOBuffer(scoped_refptr<net::IOBufferWithSize>* buf,
92 bool* defer); 97 bool* defer);
93 98
94 bool CheckForSufficientResource(); 99 bool CheckForSufficientResource();
95 void OnWritable(MojoResult result); 100 void OnWritable(MojoResult result);
96 void Cancel(); 101 void Cancel();
97 // Calculates the diff between URLRequest::GetTotalReceivedBytes() and 102 // Calculates the diff between URLRequest::GetTotalReceivedBytes() and
98 // |reported_total_received_bytes_|, returns it, and updates 103 // |reported_total_received_bytes_|, returns it, and updates
99 // |reported_total_received_bytes_|. 104 // |reported_total_received_bytes_|.
100 int64_t CalculateRecentlyReceivedBytes(); 105 int64_t CalculateRecentlyReceivedBytes();
101 // This function can be overriden only for tests. 106
107 // These function can be overriden only for tests.
kinuko 2017/01/23 08:28:09 nit: These function's'
tzik 2017/01/23 09:34:17 Done.
102 virtual void ReportBadMessage(const std::string& error); 108 virtual void ReportBadMessage(const std::string& error);
109 virtual std::unique_ptr<UploadProgressTracker> CreateUploadProgressTracker(
110 const tracked_objects::Location& from_here,
111 UploadProgressTracker::UploadProgressReportCallback callback);
103 112
104 void OnTransfer(mojom::URLLoaderAssociatedRequest mojo_request, 113 void OnTransfer(mojom::URLLoaderAssociatedRequest mojo_request,
105 mojom::URLLoaderClientAssociatedPtr url_loader_client); 114 mojom::URLLoaderClientAssociatedPtr url_loader_client);
115 void SendUploadProgress(const net::UploadProgress& progress);
116 void OnUploadProgressACK();
106 117
107 ResourceDispatcherHostImpl* rdh_; 118 ResourceDispatcherHostImpl* rdh_;
108 mojo::AssociatedBinding<mojom::URLLoader> binding_; 119 mojo::AssociatedBinding<mojom::URLLoader> binding_;
109 120
110 bool has_checked_for_sufficient_resources_ = false; 121 bool has_checked_for_sufficient_resources_ = false;
111 bool sent_received_response_message_ = false; 122 bool sent_received_response_message_ = false;
112 bool is_using_io_buffer_not_from_writer_ = false; 123 bool is_using_io_buffer_not_from_writer_ = false;
113 bool did_defer_on_writing_ = false; 124 bool did_defer_on_writing_ = false;
114 bool did_defer_on_redirect_ = false; 125 bool did_defer_on_redirect_ = false;
115 base::TimeTicks response_started_ticks_; 126 base::TimeTicks response_started_ticks_;
116 int64_t reported_total_received_bytes_ = 0; 127 int64_t reported_total_received_bytes_ = 0;
117 128
118 mojo::Watcher handle_watcher_; 129 mojo::Watcher handle_watcher_;
119 std::unique_ptr<mojom::URLLoader> url_loader_; 130 std::unique_ptr<mojom::URLLoader> url_loader_;
120 mojom::URLLoaderClientAssociatedPtr url_loader_client_; 131 mojom::URLLoaderClientAssociatedPtr url_loader_client_;
121 scoped_refptr<net::IOBufferWithSize> buffer_; 132 scoped_refptr<net::IOBufferWithSize> buffer_;
122 size_t buffer_offset_ = 0; 133 size_t buffer_offset_ = 0;
123 size_t buffer_bytes_read_ = 0; 134 size_t buffer_bytes_read_ = 0;
124 scoped_refptr<SharedWriter> shared_writer_; 135 scoped_refptr<SharedWriter> shared_writer_;
125 mojo::ScopedDataPipeConsumerHandle response_body_consumer_handle_; 136 mojo::ScopedDataPipeConsumerHandle response_body_consumer_handle_;
126 137
138 std::unique_ptr<UploadProgressTracker> upload_progress_tracker_;
139
127 base::WeakPtrFactory<MojoAsyncResourceHandler> weak_factory_; 140 base::WeakPtrFactory<MojoAsyncResourceHandler> weak_factory_;
128 DISALLOW_COPY_AND_ASSIGN(MojoAsyncResourceHandler); 141 DISALLOW_COPY_AND_ASSIGN(MojoAsyncResourceHandler);
129 }; 142 };
130 143
131 } // namespace content 144 } // namespace content
132 145
133 #endif // CONTENT_BROWSER_LOADER_MOJO_ASYNC_RESOURCE_HANDLER_H_ 146 #endif // CONTENT_BROWSER_LOADER_MOJO_ASYNC_RESOURCE_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698