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

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

Issue 2467833002: Implement redirect handling on MojoAsyncResourceHandler (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>
(...skipping 15 matching lines...) Expand all
26 } 26 }
27 27
28 namespace content { 28 namespace content {
29 class ResourceDispatcherHostImpl; 29 class ResourceDispatcherHostImpl;
30 struct ResourceResponse; 30 struct ResourceResponse;
31 31
32 // Used to complete an asynchronous resource request in response to resource 32 // Used to complete an asynchronous resource request in response to resource
33 // load events from the resource dispatcher host. This class is used only 33 // load events from the resource dispatcher host. This class is used only
34 // when LoadingWithMojo runtime flag is enabled. 34 // when LoadingWithMojo runtime flag is enabled.
35 // 35 //
36 // TODO(yhirano): Implement redirects.
37 // TODO(yhirano): Add histograms. 36 // TODO(yhirano): Add histograms.
38 // TODO(yhirano): Set zoom level.
39 // TODO(yhirano): Send cached metadata. 37 // TODO(yhirano): Send cached metadata.
40 // 38 //
41 // This class can be inherited only for tests. 39 // This class can be inherited only for tests.
42 class CONTENT_EXPORT MojoAsyncResourceHandler 40 class CONTENT_EXPORT MojoAsyncResourceHandler
43 : public ResourceHandler, 41 : public ResourceHandler,
44 public NON_EXPORTED_BASE(mojom::URLLoader) { 42 public NON_EXPORTED_BASE(mojom::URLLoader) {
45 public: 43 public:
46 MojoAsyncResourceHandler( 44 MojoAsyncResourceHandler(
47 net::URLRequest* request, 45 net::URLRequest* request,
48 ResourceDispatcherHostImpl* rdh, 46 ResourceDispatcherHostImpl* rdh,
(...skipping 11 matching lines...) Expand all
60 int* buf_size, 58 int* buf_size,
61 int min_size) override; 59 int min_size) override;
62 bool OnReadCompleted(int bytes_read, bool* defer) override; 60 bool OnReadCompleted(int bytes_read, bool* defer) override;
63 void OnResponseCompleted(const net::URLRequestStatus& status, 61 void OnResponseCompleted(const net::URLRequestStatus& status,
64 bool* defer) override; 62 bool* defer) override;
65 void OnDataDownloaded(int bytes_downloaded) override; 63 void OnDataDownloaded(int bytes_downloaded) override;
66 64
67 // mojom::URLLoader implementation 65 // mojom::URLLoader implementation
68 void FollowRedirect() override; 66 void FollowRedirect() override;
69 67
70 void ResumeForTesting(); 68 void OnWritableForTesting();
71 static void SetAllocationSizeForTesting(size_t size); 69 static void SetAllocationSizeForTesting(size_t size);
72 static constexpr size_t kDefaultAllocationSize = 512 * 1024; 70 static constexpr size_t kDefaultAllocationSize = 512 * 1024;
73 71
74 protected: 72 protected:
75 // These functions can be overriden only for tests. 73 // These functions can be overriden only for tests.
76 virtual MojoResult BeginWrite(void** data, uint32_t* available); 74 virtual MojoResult BeginWrite(void** data, uint32_t* available);
77 virtual MojoResult EndWrite(uint32_t written); 75 virtual MojoResult EndWrite(uint32_t written);
78 76
79 private: 77 private:
80 class SharedWriter; 78 class SharedWriter;
81 class WriterIOBuffer; 79 class WriterIOBuffer;
82 80
83 // This funcion copies data stored in |buffer_| to |shared_writer_| and 81 // This funcion copies data stored in |buffer_| to |shared_writer_| and
84 // resets |buffer_| to a WriterIOBuffer when all bytes are copied. Returns 82 // resets |buffer_| to a WriterIOBuffer when all bytes are copied. Returns
85 // true when done successfully. 83 // true when done successfully.
86 bool CopyReadDataToDataPipe(bool* defer); 84 bool CopyReadDataToDataPipe(bool* defer);
87 // Allocates a WriterIOBuffer and set it to |*buf|. Returns true when done 85 // Allocates a WriterIOBuffer and set it to |*buf|. Returns true when done
88 // successfully. 86 // successfully.
89 bool AllocateWriterIOBuffer(scoped_refptr<net::IOBufferWithSize>* buf, 87 bool AllocateWriterIOBuffer(scoped_refptr<net::IOBufferWithSize>* buf,
90 bool* defer); 88 bool* defer);
91 89
92 void Resume(); 90 void Resume();
mmenke 2016/11/10 21:42:40 This method no longer exists.
yhirano 2016/11/11 09:47:04 Done.
93 void OnDefer(); 91 void OnDefer();
94 bool CheckForSufficientResource(); 92 bool CheckForSufficientResource();
95 void OnWritable(MojoResult result); 93 void OnWritable(MojoResult result);
96 void Cancel(); 94 void Cancel();
97 95
98 ResourceDispatcherHostImpl* rdh_; 96 ResourceDispatcherHostImpl* rdh_;
99 mojo::AssociatedBinding<mojom::URLLoader> binding_; 97 mojo::AssociatedBinding<mojom::URLLoader> binding_;
100 98
101 bool has_checked_for_sufficient_resources_ = false; 99 bool has_checked_for_sufficient_resources_ = false;
102 bool sent_received_response_message_ = false; 100 bool sent_received_response_message_ = false;
103 bool is_using_io_buffer_not_from_writer_ = false; 101 bool is_using_io_buffer_not_from_writer_ = false;
104 bool did_defer_ = false; 102 bool did_defer_ = false;
105 base::TimeTicks response_started_ticks_; 103 base::TimeTicks response_started_ticks_;
106 int64_t reported_total_received_bytes_ = 0; 104 int64_t reported_total_received_bytes_ = 0;
107 105
108 mojo::Watcher handle_watcher_; 106 mojo::Watcher handle_watcher_;
109 std::unique_ptr<mojom::URLLoader> url_loader_; 107 std::unique_ptr<mojom::URLLoader> url_loader_;
110 mojom::URLLoaderClientAssociatedPtr url_loader_client_; 108 mojom::URLLoaderClientAssociatedPtr url_loader_client_;
111 scoped_refptr<net::IOBufferWithSize> buffer_; 109 scoped_refptr<net::IOBufferWithSize> buffer_;
112 size_t buffer_offset_ = 0; 110 size_t buffer_offset_ = 0;
113 size_t buffer_bytes_read_ = 0; 111 size_t buffer_bytes_read_ = 0;
114 scoped_refptr<SharedWriter> shared_writer_; 112 scoped_refptr<SharedWriter> shared_writer_;
115 113
116 DISALLOW_COPY_AND_ASSIGN(MojoAsyncResourceHandler); 114 DISALLOW_COPY_AND_ASSIGN(MojoAsyncResourceHandler);
117 }; 115 };
118 116
119 } // namespace content 117 } // namespace content
120 118
121 #endif // CONTENT_BROWSER_LOADER_MOJO_ASYNC_RESOURCE_HANDLER_H_ 119 #endif // CONTENT_BROWSER_LOADER_MOJO_ASYNC_RESOURCE_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698