Chromium Code Reviews| 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. | |
|
mmenke
2016/05/26 21:46:09
Could you add TODOs about what this does not yet s
yhirano
2016/05/27 11:30:34
Done.
| |
| 33 class MojoAsyncResourceHandler : public ResourceHandler { | |
| 34 public: | |
| 35 MojoAsyncResourceHandler(net::URLRequest* request, | |
| 36 ResourceDispatcherHostImpl* rdh, | |
| 37 std::unique_ptr<mojom::URLLoader> url_loader, | |
| 38 mojom::URLLoaderClientPtr url_loader_client); | |
| 39 ~MojoAsyncResourceHandler() override; | |
| 40 | |
| 41 // ResourceHandler implementation: | |
| 42 bool OnRequestRedirected(const net::RedirectInfo& redirect_info, | |
| 43 ResourceResponse* response, | |
| 44 bool* defer) override; | |
| 45 bool OnResponseStarted(ResourceResponse* response, bool* defer) override; | |
| 46 bool OnWillStart(const GURL& url, bool* defer) override; | |
| 47 bool OnBeforeNetworkStart(const GURL& url, bool* defer) override; | |
| 48 bool OnWillRead(scoped_refptr<net::IOBuffer>* buf, | |
| 49 int* buf_size, | |
| 50 int min_size) override; | |
| 51 bool OnReadCompleted(int bytes_read, bool* defer) override; | |
| 52 void OnResponseCompleted(const net::URLRequestStatus& status, | |
| 53 const std::string& security_info, | |
| 54 bool* defer) override; | |
| 55 void OnDataDownloaded(int bytes_downloaded) override; | |
| 56 | |
| 57 private: | |
| 58 // IPC message handlers: | |
| 59 void OnFollowRedirect(int request_id); | |
| 60 | |
| 61 void ResumeIfDeferred(); | |
| 62 void OnDefer(); | |
| 63 bool CheckForSufficientResource(); | |
| 64 void OnWritable(MojoResult result); | |
| 65 | |
| 66 ResourceDispatcherHostImpl* rdh_; | |
| 67 | |
| 68 bool did_defer_ = false; | |
| 69 bool has_checked_for_sufficient_resources_ = false; | |
| 70 bool sent_received_response_message_ = false; | |
| 71 base::TimeTicks response_started_ticks_; | |
| 72 | |
| 73 mojo::ScopedDataPipeProducerHandle writer_; | |
| 74 mojo::common::HandleWatcher handle_watcher_; | |
| 75 std::unique_ptr<mojom::URLLoader> url_loader_; | |
| 76 mojom::URLLoaderClientPtr url_loader_client_; | |
| 77 | |
| 78 DISALLOW_COPY_AND_ASSIGN(MojoAsyncResourceHandler); | |
| 79 }; | |
| 80 | |
| 81 } // namespace content | |
| 82 | |
| 83 #endif // CONTENT_BROWSER_LOADER_MOJO_ASYNC_RESOURCE_HANDLER_H_ | |
| OLD | NEW |