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

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

Issue 2466843002: Cancel the request when URLLoader is gone (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
« no previous file with comments | « content/browser/loader/DEPS ('k') | content/browser/loader/mojo_async_resource_handler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 bool OnWillRead(scoped_refptr<net::IOBuffer>* buf, 59 bool OnWillRead(scoped_refptr<net::IOBuffer>* buf,
60 int* buf_size, 60 int* buf_size,
61 int min_size) override; 61 int min_size) override;
62 bool OnReadCompleted(int bytes_read, bool* defer) override; 62 bool OnReadCompleted(int bytes_read, bool* defer) override;
63 void OnResponseCompleted(const net::URLRequestStatus& status, 63 void OnResponseCompleted(const net::URLRequestStatus& status,
64 bool* defer) override; 64 bool* defer) override;
65 void OnDataDownloaded(int bytes_downloaded) override; 65 void OnDataDownloaded(int bytes_downloaded) override;
66 66
67 // mojom::URLLoader implementation 67 // mojom::URLLoader implementation
68 void FollowRedirect() override; 68 void FollowRedirect() override;
69 void Cancel() override;
70 69
71 void ResumeForTesting(); 70 void ResumeForTesting();
72 static void SetAllocationSizeForTesting(size_t size); 71 static void SetAllocationSizeForTesting(size_t size);
73 static constexpr size_t kDefaultAllocationSize = 512 * 1024; 72 static constexpr size_t kDefaultAllocationSize = 512 * 1024;
74 73
75 protected: 74 protected:
76 // These functions can be overriden only for tests. 75 // These functions can be overriden only for tests.
77 virtual MojoResult BeginWrite(void** data, uint32_t* available); 76 virtual MojoResult BeginWrite(void** data, uint32_t* available);
78 virtual MojoResult EndWrite(uint32_t written); 77 virtual MojoResult EndWrite(uint32_t written);
79 78
80 private: 79 private:
81 class SharedWriter; 80 class SharedWriter;
82 class WriterIOBuffer; 81 class WriterIOBuffer;
83 82
84 // This funcion copies data stored in |buffer_| to |shared_writer_| and 83 // This funcion copies data stored in |buffer_| to |shared_writer_| and
85 // resets |buffer_| to a WriterIOBuffer when all bytes are copied. Returns 84 // resets |buffer_| to a WriterIOBuffer when all bytes are copied. Returns
86 // true when done successfully. 85 // true when done successfully.
87 bool CopyReadDataToDataPipe(bool* defer); 86 bool CopyReadDataToDataPipe(bool* defer);
88 // Allocates a WriterIOBuffer and set it to |*buf|. Returns true when done 87 // Allocates a WriterIOBuffer and set it to |*buf|. Returns true when done
89 // successfully. 88 // successfully.
90 bool AllocateWriterIOBuffer(scoped_refptr<net::IOBufferWithSize>* buf, 89 bool AllocateWriterIOBuffer(scoped_refptr<net::IOBufferWithSize>* buf,
91 bool* defer); 90 bool* defer);
92 91
93 void Resume(); 92 void Resume();
94 void OnDefer(); 93 void OnDefer();
95 bool CheckForSufficientResource(); 94 bool CheckForSufficientResource();
96 void OnWritable(MojoResult result); 95 void OnWritable(MojoResult result);
96 void Cancel();
97 97
98 ResourceDispatcherHostImpl* rdh_; 98 ResourceDispatcherHostImpl* rdh_;
99 mojo::AssociatedBinding<mojom::URLLoader> binding_; 99 mojo::AssociatedBinding<mojom::URLLoader> binding_;
100 100
101 bool has_checked_for_sufficient_resources_ = false; 101 bool has_checked_for_sufficient_resources_ = false;
102 bool sent_received_response_message_ = false; 102 bool sent_received_response_message_ = false;
103 bool is_using_io_buffer_not_from_writer_ = false; 103 bool is_using_io_buffer_not_from_writer_ = false;
104 bool did_defer_ = false; 104 bool did_defer_ = false;
105 base::TimeTicks response_started_ticks_; 105 base::TimeTicks response_started_ticks_;
106 int64_t reported_total_received_bytes_ = 0; 106 int64_t reported_total_received_bytes_ = 0;
107 107
108 mojo::Watcher handle_watcher_; 108 mojo::Watcher handle_watcher_;
109 std::unique_ptr<mojom::URLLoader> url_loader_; 109 std::unique_ptr<mojom::URLLoader> url_loader_;
110 mojom::URLLoaderClientAssociatedPtr url_loader_client_; 110 mojom::URLLoaderClientAssociatedPtr url_loader_client_;
111 scoped_refptr<net::IOBufferWithSize> buffer_; 111 scoped_refptr<net::IOBufferWithSize> buffer_;
112 size_t buffer_offset_ = 0; 112 size_t buffer_offset_ = 0;
113 size_t buffer_bytes_read_ = 0; 113 size_t buffer_bytes_read_ = 0;
114 scoped_refptr<SharedWriter> shared_writer_; 114 scoped_refptr<SharedWriter> shared_writer_;
115 115
116 DISALLOW_COPY_AND_ASSIGN(MojoAsyncResourceHandler); 116 DISALLOW_COPY_AND_ASSIGN(MojoAsyncResourceHandler);
117 }; 117 };
118 118
119 } // namespace content 119 } // namespace content
120 120
121 #endif // CONTENT_BROWSER_LOADER_MOJO_ASYNC_RESOURCE_HANDLER_H_ 121 #endif // CONTENT_BROWSER_LOADER_MOJO_ASYNC_RESOURCE_HANDLER_H_
OLDNEW
« no previous file with comments | « content/browser/loader/DEPS ('k') | content/browser/loader/mojo_async_resource_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698