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

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

Issue 1970693002: Use mojo for Chrome Loading, Part 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 (c) 2012 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_ASYNC_RESOURCE_HANDLER_H_ 5 #ifndef CONTENT_BROWSER_LOADER_MOJO_ASYNC_RESOURCE_HANDLER_H_
6 #define CONTENT_BROWSER_LOADER_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 <string> 11 #include <string>
11 12
12 #include "base/macros.h" 13 #include "base/macros.h"
13 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
14 #include "base/timer/timer.h" 15 #include "base/timer/timer.h"
15 #include "content/browser/loader/resource_handler.h" 16 #include "content/browser/loader/resource_handler.h"
16 #include "content/browser/loader/resource_message_delegate.h" 17 #include "content/common/url_loader.mojom.h"
18 #include "mojo/message_pump/handle_watcher.h"
19 #include "mojo/public/cpp/system/data_pipe.h"
17 #include "net/base/io_buffer.h" 20 #include "net/base/io_buffer.h"
18 #include "url/gurl.h" 21 #include "url/gurl.h"
19 22
20 namespace net { 23 namespace net {
21 class URLRequest; 24 class URLRequest;
22 } 25 }
23 26
24 namespace content { 27 namespace content {
25 class ResourceBuffer;
26 class ResourceContext;
27 class ResourceDispatcherHostImpl; 28 class ResourceDispatcherHostImpl;
28 class ResourceMessageFilter;
29 class SharedIOBuffer;
30 29
31 // Used to complete an asynchronous resource request in response to resource 30 // Used to complete an asynchronous resource request in response to resource
32 // load events from the resource dispatcher host. 31 // load events from the resource dispatcher host.
kinuko 2016/05/26 08:43:12 nit: add a comment to note that this is used only
yhirano 2016/05/26 15:42:44 Done.
33 class AsyncResourceHandler : public ResourceHandler, 32 class MojoAsyncResourceHandler : public ResourceHandler {
34 public ResourceMessageDelegate {
35 public: 33 public:
36 AsyncResourceHandler(net::URLRequest* request, 34 MojoAsyncResourceHandler(net::URLRequest* request,
37 ResourceDispatcherHostImpl* rdh); 35 ResourceDispatcherHostImpl* rdh,
38 ~AsyncResourceHandler() override; 36 std::unique_ptr<mojom::URLLoader> url_loader,
39 37 mojom::URLLoaderClientPtr url_loader_client);
40 bool OnMessageReceived(const IPC::Message& message) override; 38 ~MojoAsyncResourceHandler() override;
41 39
42 // ResourceHandler implementation: 40 // ResourceHandler implementation:
43 bool OnRequestRedirected(const net::RedirectInfo& redirect_info, 41 bool OnRequestRedirected(const net::RedirectInfo& redirect_info,
44 ResourceResponse* response, 42 ResourceResponse* response,
45 bool* defer) override; 43 bool* defer) override;
46 bool OnResponseStarted(ResourceResponse* response, bool* defer) override; 44 bool OnResponseStarted(ResourceResponse* response, bool* defer) override;
47 bool OnWillStart(const GURL& url, bool* defer) override; 45 bool OnWillStart(const GURL& url, bool* defer) override;
48 bool OnBeforeNetworkStart(const GURL& url, bool* defer) override; 46 bool OnBeforeNetworkStart(const GURL& url, bool* defer) override;
49 bool OnWillRead(scoped_refptr<net::IOBuffer>* buf, 47 bool OnWillRead(scoped_refptr<net::IOBuffer>* buf,
50 int* buf_size, 48 int* buf_size,
51 int min_size) override; 49 int min_size) override;
52 bool OnReadCompleted(int bytes_read, bool* defer) override; 50 bool OnReadCompleted(int bytes_read, bool* defer) override;
53 void OnResponseCompleted(const net::URLRequestStatus& status, 51 void OnResponseCompleted(const net::URLRequestStatus& status,
54 const std::string& security_info, 52 const std::string& security_info,
55 bool* defer) override; 53 bool* defer) override;
56 void OnDataDownloaded(int bytes_downloaded) override; 54 void OnDataDownloaded(int bytes_downloaded) override;
57 55
58 private: 56 private:
59 class InliningHelper;
60
61 // IPC message handlers: 57 // IPC message handlers:
62 void OnFollowRedirect(int request_id); 58 void OnFollowRedirect(int request_id);
63 void OnDataReceivedACK(int request_id);
64 void OnUploadProgressACK(int request_id);
65 59
66 void ReportUploadProgress();
67
68 bool EnsureResourceBufferIsInitialized();
69 void ResumeIfDeferred(); 60 void ResumeIfDeferred();
70 void OnDefer(); 61 void OnDefer();
71 bool CheckForSufficientResource(); 62 bool CheckForSufficientResource();
72 int CalculateEncodedDataLengthToReport();
73 void RecordHistogram(); 63 void RecordHistogram();
64 void OnWritable(MojoResult result);
74 65
75 scoped_refptr<ResourceBuffer> buffer_;
76 ResourceDispatcherHostImpl* rdh_; 66 ResourceDispatcherHostImpl* rdh_;
77 67
78 // Number of messages we've sent to the renderer that we haven't gotten an 68 bool did_defer_ = false;
79 // ACK for. This allows us to avoid having too many messages in flight. 69 bool has_checked_for_sufficient_resources_ = false;
80 int pending_data_count_; 70 bool sent_received_response_message_ = false;
81
82 int allocation_size_;
83
84 bool did_defer_;
85
86 bool has_checked_for_sufficient_resources_;
87 bool sent_received_response_msg_;
88 bool sent_data_buffer_msg_;
89
90 std::unique_ptr<InliningHelper> inlining_helper_;
91 base::TimeTicks response_started_ticks_; 71 base::TimeTicks response_started_ticks_;
92 72
93 uint64_t last_upload_position_; 73 mojo::ScopedDataPipeProducerHandle writer_;
94 bool waiting_for_upload_progress_ack_; 74 mojo::common::HandleWatcher handle_watcher_;
95 base::TimeTicks last_upload_ticks_; 75 std::unique_ptr<mojom::URLLoader> url_loader_;
96 base::RepeatingTimer progress_timer_; 76 mojom::URLLoaderClientPtr url_loader_client_;
97 77
98 int64_t reported_transfer_size_; 78 DISALLOW_COPY_AND_ASSIGN(MojoAsyncResourceHandler);
99
100 DISALLOW_COPY_AND_ASSIGN(AsyncResourceHandler);
101 }; 79 };
102 80
103 } // namespace content 81 } // namespace content
104 82
105 #endif // CONTENT_BROWSER_LOADER_ASYNC_RESOURCE_HANDLER_H_ 83 #endif // CONTENT_BROWSER_LOADER_MOJO_ASYNC_RESOURCE_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698