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

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

Issue 2496193002: Implement transfer navigation with mojo (Closed)
Patch Set: fix Created 4 years, 1 month 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/timer/timer.h" 16 #include "base/timer/timer.h"
16 #include "content/browser/loader/resource_handler.h" 17 #include "content/browser/loader/resource_handler.h"
17 #include "content/common/content_export.h" 18 #include "content/common/content_export.h"
18 #include "content/common/url_loader.mojom.h" 19 #include "content/common/url_loader.mojom.h"
19 #include "mojo/public/cpp/bindings/associated_binding.h" 20 #include "mojo/public/cpp/bindings/associated_binding.h"
20 #include "mojo/public/cpp/system/watcher.h" 21 #include "mojo/public/cpp/system/watcher.h"
21 #include "net/base/io_buffer.h" 22 #include "net/base/io_buffer.h"
22 #include "url/gurl.h" 23 #include "url/gurl.h"
23 24
24 namespace net { 25 namespace net {
25 class URLRequest; 26 class URLRequest;
26 } 27 }
27 28
28 namespace content { 29 namespace content {
29 class ResourceDispatcherHostImpl; 30 class ResourceDispatcherHostImpl;
30 struct ResourceResponse; 31 struct ResourceResponse;
31 32
32 // Used to complete an asynchronous resource request in response to resource 33 // Used to complete an asynchronous resource request in response to resource
33 // load events from the resource dispatcher host. This class is used only 34 // load events from the resource dispatcher host. This class is used only
34 // when LoadingWithMojo runtime flag is enabled. 35 // when LoadingWithMojo runtime flag is enabled.
35 // 36 //
36 // TODO(yhirano): Add histograms. 37 // TODO(yhirano): Add histograms.
37 // TODO(yhirano): Send cached metadata. 38 // TODO(yhirano): Send cached metadata.
38 // 39 //
39 // This class can be inherited only for tests. 40 // This class can be inherited only for tests.
40 class CONTENT_EXPORT MojoAsyncResourceHandler 41 class CONTENT_EXPORT MojoAsyncResourceHandler
41 : public ResourceHandler, 42 : public ResourceHandler,
42 public NON_EXPORTED_BASE(mojom::URLLoader) { 43 public NON_EXPORTED_BASE(mojom::URLLoader) {
43 public: 44 public:
45 using TransferCallback =
46 base::Callback<void(mojom::URLLoaderAssociatedRequest,
47 mojom::URLLoaderClientAssociatedPtr)>;
48
44 MojoAsyncResourceHandler( 49 MojoAsyncResourceHandler(
45 net::URLRequest* request, 50 net::URLRequest* request,
46 ResourceDispatcherHostImpl* rdh, 51 ResourceDispatcherHostImpl* rdh,
47 mojom::URLLoaderAssociatedRequest mojo_request, 52 mojom::URLLoaderAssociatedRequest mojo_request,
48 mojom::URLLoaderClientAssociatedPtr url_loader_client); 53 mojom::URLLoaderClientAssociatedPtr url_loader_client);
49 ~MojoAsyncResourceHandler() override; 54 ~MojoAsyncResourceHandler() override;
50 55
56 TransferCallback GetTransferCallback();
57
51 // ResourceHandler implementation: 58 // ResourceHandler implementation:
52 bool OnRequestRedirected(const net::RedirectInfo& redirect_info, 59 bool OnRequestRedirected(const net::RedirectInfo& redirect_info,
53 ResourceResponse* response, 60 ResourceResponse* response,
54 bool* defer) override; 61 bool* defer) override;
55 bool OnResponseStarted(ResourceResponse* response, bool* defer) override; 62 bool OnResponseStarted(ResourceResponse* response, bool* defer) override;
56 bool OnWillStart(const GURL& url, bool* defer) override; 63 bool OnWillStart(const GURL& url, bool* defer) override;
57 bool OnWillRead(scoped_refptr<net::IOBuffer>* buf, 64 bool OnWillRead(scoped_refptr<net::IOBuffer>* buf,
58 int* buf_size, 65 int* buf_size,
59 int min_size) override; 66 int min_size) override;
60 bool OnReadCompleted(int bytes_read, bool* defer) override; 67 bool OnReadCompleted(int bytes_read, bool* defer) override;
(...skipping 25 matching lines...) Expand all
86 // successfully. 93 // successfully.
87 bool AllocateWriterIOBuffer(scoped_refptr<net::IOBufferWithSize>* buf, 94 bool AllocateWriterIOBuffer(scoped_refptr<net::IOBufferWithSize>* buf,
88 bool* defer); 95 bool* defer);
89 96
90 bool CheckForSufficientResource(); 97 bool CheckForSufficientResource();
91 void OnWritable(MojoResult result); 98 void OnWritable(MojoResult result);
92 void Cancel(); 99 void Cancel();
93 // This function can be overriden only for tests. 100 // This function can be overriden only for tests.
94 virtual void ReportBadMessage(const std::string& error); 101 virtual void ReportBadMessage(const std::string& error);
95 102
103 void OnTransfer(mojom::URLLoaderAssociatedRequest mojo_request,
104 mojom::URLLoaderClientAssociatedPtr url_loader_client);
105
96 ResourceDispatcherHostImpl* rdh_; 106 ResourceDispatcherHostImpl* rdh_;
97 mojo::AssociatedBinding<mojom::URLLoader> binding_; 107 mojo::AssociatedBinding<mojom::URLLoader> binding_;
98 108
99 bool has_checked_for_sufficient_resources_ = false; 109 bool has_checked_for_sufficient_resources_ = false;
100 bool sent_received_response_message_ = false; 110 bool sent_received_response_message_ = false;
101 bool is_using_io_buffer_not_from_writer_ = false; 111 bool is_using_io_buffer_not_from_writer_ = false;
102 bool did_defer_on_writing_ = false; 112 bool did_defer_on_writing_ = false;
103 bool did_defer_on_redirect_ = false; 113 bool did_defer_on_redirect_ = false;
104 base::TimeTicks response_started_ticks_; 114 base::TimeTicks response_started_ticks_;
105 int64_t reported_total_received_bytes_ = 0; 115 int64_t reported_total_received_bytes_ = 0;
106 116
107 mojo::Watcher handle_watcher_; 117 mojo::Watcher handle_watcher_;
108 std::unique_ptr<mojom::URLLoader> url_loader_; 118 std::unique_ptr<mojom::URLLoader> url_loader_;
109 mojom::URLLoaderClientAssociatedPtr url_loader_client_; 119 mojom::URLLoaderClientAssociatedPtr url_loader_client_;
110 scoped_refptr<net::IOBufferWithSize> buffer_; 120 scoped_refptr<net::IOBufferWithSize> buffer_;
111 size_t buffer_offset_ = 0; 121 size_t buffer_offset_ = 0;
112 size_t buffer_bytes_read_ = 0; 122 size_t buffer_bytes_read_ = 0;
113 scoped_refptr<SharedWriter> shared_writer_; 123 scoped_refptr<SharedWriter> shared_writer_;
114 124
125 base::WeakPtrFactory<MojoAsyncResourceHandler> weak_factory_;
115 DISALLOW_COPY_AND_ASSIGN(MojoAsyncResourceHandler); 126 DISALLOW_COPY_AND_ASSIGN(MojoAsyncResourceHandler);
116 }; 127 };
117 128
118 } // namespace content 129 } // namespace content
119 130
120 #endif // CONTENT_BROWSER_LOADER_MOJO_ASYNC_RESOURCE_HANDLER_H_ 131 #endif // CONTENT_BROWSER_LOADER_MOJO_ASYNC_RESOURCE_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698