| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CONTENT_BROWSER_LOADER_MOJO_ASYNC_RESOURCE_HANDLER_H_ |
| 6 #define CONTENT_BROWSER_LOADER_MOJO_ASYNC_RESOURCE_HANDLER_H_ |
| 7 |
| 8 #include <stdint.h> |
| 9 |
| 10 #include <memory> |
| 11 #include <string> |
| 12 |
| 13 #include "base/macros.h" |
| 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/timer/timer.h" |
| 16 #include "content/browser/loader/resource_handler.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" |
| 20 #include "net/base/io_buffer.h" |
| 21 #include "url/gurl.h" |
| 22 |
| 23 namespace net { |
| 24 class URLRequest; |
| 25 } |
| 26 |
| 27 namespace content { |
| 28 class ResourceDispatcherHostImpl; |
| 29 |
| 30 // Used to complete an asynchronous resource request in response to resource |
| 31 // load events from the resource dispatcher host. This class is used only |
| 32 // when LoadingWithMojo runtime enabled flag is enabled. |
| 33 // |
| 34 // TODO(yhirano): Implement redirects. |
| 35 // TODO(yhirano): Implement downloading to file. |
| 36 // TODO(yhirano): Add histograms. |
| 37 // TODO(yhirano): Set zoom level. |
| 38 // TODO(yhirano): Send cached metadata. |
| 39 class MojoAsyncResourceHandler : public ResourceHandler { |
| 40 public: |
| 41 MojoAsyncResourceHandler(net::URLRequest* request, |
| 42 ResourceDispatcherHostImpl* rdh, |
| 43 std::unique_ptr<mojom::URLLoader> url_loader, |
| 44 mojom::URLLoaderClientPtr url_loader_client); |
| 45 ~MojoAsyncResourceHandler() override; |
| 46 |
| 47 // ResourceHandler implementation: |
| 48 bool OnRequestRedirected(const net::RedirectInfo& redirect_info, |
| 49 ResourceResponse* response, |
| 50 bool* defer) override; |
| 51 bool OnResponseStarted(ResourceResponse* response, bool* defer) override; |
| 52 bool OnWillStart(const GURL& url, bool* defer) override; |
| 53 bool OnBeforeNetworkStart(const GURL& url, bool* defer) override; |
| 54 bool OnWillRead(scoped_refptr<net::IOBuffer>* buf, |
| 55 int* buf_size, |
| 56 int min_size) override; |
| 57 bool OnReadCompleted(int bytes_read, bool* defer) override; |
| 58 void OnResponseCompleted(const net::URLRequestStatus& status, |
| 59 const std::string& security_info, |
| 60 bool* defer) override; |
| 61 void OnDataDownloaded(int bytes_downloaded) override; |
| 62 |
| 63 private: |
| 64 // IPC message handlers: |
| 65 void OnFollowRedirect(int request_id); |
| 66 |
| 67 void ResumeIfDeferred(); |
| 68 void OnDefer(); |
| 69 bool CheckForSufficientResource(); |
| 70 void OnWritable(MojoResult result); |
| 71 |
| 72 ResourceDispatcherHostImpl* rdh_; |
| 73 |
| 74 bool did_defer_ = false; |
| 75 bool has_checked_for_sufficient_resources_ = false; |
| 76 bool sent_received_response_message_ = false; |
| 77 base::TimeTicks response_started_ticks_; |
| 78 |
| 79 mojo::ScopedDataPipeProducerHandle writer_; |
| 80 mojo::common::HandleWatcher handle_watcher_; |
| 81 std::unique_ptr<mojom::URLLoader> url_loader_; |
| 82 mojom::URLLoaderClientPtr url_loader_client_; |
| 83 |
| 84 DISALLOW_COPY_AND_ASSIGN(MojoAsyncResourceHandler); |
| 85 }; |
| 86 |
| 87 } // namespace content |
| 88 |
| 89 #endif // CONTENT_BROWSER_LOADER_MOJO_ASYNC_RESOURCE_HANDLER_H_ |
| OLD | NEW |