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

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

Issue 2574143003: Implement upload progress handling in Mojo loading (Closed)
Patch Set: +content_browsertests 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/watcher.h" 21 #include "mojo/public/cpp/system/watcher.h"
22 #include "net/base/io_buffer.h" 22 #include "net/base/io_buffer.h"
23 #include "url/gurl.h" 23
24 class GURL;
24 25
25 namespace net { 26 namespace net {
26 class IOBufferWithSize; 27 class IOBufferWithSize;
27 class URLRequest; 28 class URLRequest;
28 } 29 }
29 30
30 namespace content { 31 namespace content {
31 class ResourceDispatcherHostImpl; 32 class ResourceDispatcherHostImpl;
32 struct ResourceResponse; 33 struct ResourceResponse;
33 34
(...skipping 23 matching lines...) Expand all
57 bool OnResponseStarted(ResourceResponse* response, bool* defer) override; 58 bool OnResponseStarted(ResourceResponse* response, bool* defer) override;
58 bool OnWillStart(const GURL& url, bool* defer) override; 59 bool OnWillStart(const GURL& url, bool* defer) override;
59 bool OnWillRead(scoped_refptr<net::IOBuffer>* buf, 60 bool OnWillRead(scoped_refptr<net::IOBuffer>* buf,
60 int* buf_size, 61 int* buf_size,
61 int min_size) override; 62 int min_size) override;
62 bool OnReadCompleted(int bytes_read, bool* defer) override; 63 bool OnReadCompleted(int bytes_read, bool* defer) override;
63 void OnResponseCompleted(const net::URLRequestStatus& status, 64 void OnResponseCompleted(const net::URLRequestStatus& status,
64 bool* defer) override; 65 bool* defer) override;
65 void OnDataDownloaded(int bytes_downloaded) override; 66 void OnDataDownloaded(int bytes_downloaded) override;
66 67
67 // mojom::URLLoader implementation 68 // mojom::URLLoader implementation:
68 void FollowRedirect() override; 69 void FollowRedirect() override;
69 70
70 void OnWritableForTesting(); 71 void OnWritableForTesting();
71 static void SetAllocationSizeForTesting(size_t size); 72 static void SetAllocationSizeForTesting(size_t size);
72 static constexpr size_t kDefaultAllocationSize = 512 * 1024; 73 static constexpr size_t kDefaultAllocationSize = 512 * 1024;
73 74
74 protected: 75 protected:
75 // These functions can be overriden only for tests. 76 // These functions can be overriden only for tests.
76 virtual MojoResult BeginWrite(void** data, uint32_t* available); 77 virtual MojoResult BeginWrite(void** data, uint32_t* available);
77 virtual MojoResult EndWrite(uint32_t written); 78 virtual MojoResult EndWrite(uint32_t written);
(...skipping 17 matching lines...) Expand all
95 void Cancel(); 96 void Cancel();
96 // Calculates the diff between URLRequest::GetTotalReceivedBytes() and 97 // Calculates the diff between URLRequest::GetTotalReceivedBytes() and
97 // |reported_total_received_bytes_|, returns it, and updates 98 // |reported_total_received_bytes_|, returns it, and updates
98 // |reported_total_received_bytes_|. 99 // |reported_total_received_bytes_|.
99 int64_t CalculateRecentlyReceivedBytes(); 100 int64_t CalculateRecentlyReceivedBytes();
100 // This function can be overriden only for tests. 101 // This function can be overriden only for tests.
101 virtual void ReportBadMessage(const std::string& error); 102 virtual void ReportBadMessage(const std::string& error);
102 103
103 void OnTransfer(mojom::URLLoaderAssociatedRequest mojo_request, 104 void OnTransfer(mojom::URLLoaderAssociatedRequest mojo_request,
104 mojom::URLLoaderClientAssociatedPtr url_loader_client); 105 mojom::URLLoaderClientAssociatedPtr url_loader_client);
106 void SendUploadProgress(const net::UploadProgress& progress);
107 void OnUploadProgressACK();
105 108
106 ResourceDispatcherHostImpl* rdh_; 109 ResourceDispatcherHostImpl* rdh_;
107 mojo::AssociatedBinding<mojom::URLLoader> binding_; 110 mojo::AssociatedBinding<mojom::URLLoader> binding_;
108 111
109 bool has_checked_for_sufficient_resources_ = false; 112 bool has_checked_for_sufficient_resources_ = false;
110 bool sent_received_response_message_ = false; 113 bool sent_received_response_message_ = false;
111 bool is_using_io_buffer_not_from_writer_ = false; 114 bool is_using_io_buffer_not_from_writer_ = false;
112 bool did_defer_on_writing_ = false; 115 bool did_defer_on_writing_ = false;
113 bool did_defer_on_redirect_ = false; 116 bool did_defer_on_redirect_ = false;
114 base::TimeTicks response_started_ticks_; 117 base::TimeTicks response_started_ticks_;
115 int64_t reported_total_received_bytes_ = 0; 118 int64_t reported_total_received_bytes_ = 0;
116 119
117 mojo::Watcher handle_watcher_; 120 mojo::Watcher handle_watcher_;
118 std::unique_ptr<mojom::URLLoader> url_loader_; 121 std::unique_ptr<mojom::URLLoader> url_loader_;
119 mojom::URLLoaderClientAssociatedPtr url_loader_client_; 122 mojom::URLLoaderClientAssociatedPtr url_loader_client_;
120 scoped_refptr<net::IOBufferWithSize> buffer_; 123 scoped_refptr<net::IOBufferWithSize> buffer_;
121 size_t buffer_offset_ = 0; 124 size_t buffer_offset_ = 0;
122 size_t buffer_bytes_read_ = 0; 125 size_t buffer_bytes_read_ = 0;
123 scoped_refptr<SharedWriter> shared_writer_; 126 scoped_refptr<SharedWriter> shared_writer_;
124 127
128 std::unique_ptr<UploadProgressTracker> upload_progress_tracker_;
129
125 base::WeakPtrFactory<MojoAsyncResourceHandler> weak_factory_; 130 base::WeakPtrFactory<MojoAsyncResourceHandler> weak_factory_;
126 DISALLOW_COPY_AND_ASSIGN(MojoAsyncResourceHandler); 131 DISALLOW_COPY_AND_ASSIGN(MojoAsyncResourceHandler);
127 }; 132 };
128 133
129 } // namespace content 134 } // namespace content
130 135
131 #endif // CONTENT_BROWSER_LOADER_MOJO_ASYNC_RESOURCE_HANDLER_H_ 136 #endif // CONTENT_BROWSER_LOADER_MOJO_ASYNC_RESOURCE_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698