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_CHILD_URL_RESPONSE_BODY_CONSUMER_H_ |
| 6 #define CONTENT_CHILD_URL_RESPONSE_BODY_CONSUMER_H_ |
| 7 |
| 8 #include <stddef.h> |
| 9 #include <stdint.h> |
| 10 |
| 11 #include <utility> |
| 12 #include <vector> |
| 13 |
| 14 #include "base/macros.h" |
| 15 #include "base/memory/ref_counted.h" |
| 16 #include "content/common/content_export.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 |
| 21 namespace content { |
| 22 |
| 23 class ResourceDispatcher; |
| 24 struct ResourceRequestCompletionStatus; |
| 25 |
| 26 // This class pulls data from a data pipe and dispatches it to the |
| 27 // ResourceDispatcher. |
| 28 class CONTENT_EXPORT URLResponseBodyConsumer final |
| 29 : public base::RefCounted<URLResponseBodyConsumer> { |
| 30 public: |
| 31 URLResponseBodyConsumer(int request_id, |
| 32 ResourceDispatcher* resource_dispatcher, |
| 33 mojo::ScopedDataPipeConsumerHandle handle); |
| 34 |
| 35 // Sets the completion status. Dispatches the completion status to the |
| 36 // ResourceDispatcher when the both following conditions hold: |
| 37 // 1) The completion status is set by this function, and |
| 38 // 2) All data is read from the handle. |
| 39 void OnComplete(const ResourceRequestCompletionStatus& status); |
| 40 |
| 41 // Cancels watching the handle and dispatches an error to the |
| 42 // ResourceDispatcher. This function does nothing if the reading is already |
| 43 // cancelled or done. |
| 44 void Cancel(); |
| 45 |
| 46 private: |
| 47 friend class base::RefCounted<URLResponseBodyConsumer>; |
| 48 ~URLResponseBodyConsumer(); |
| 49 |
| 50 class ReceivedData; |
| 51 void Reclaim(uint32_t size); |
| 52 |
| 53 void OnReadable(MojoResult); |
| 54 void StartWatching(); |
| 55 void NotifyCompletionIfAppropriate(); |
| 56 |
| 57 int request_id_; |
| 58 ResourceDispatcher* resource_dispatcher_; |
| 59 mojo::ScopedDataPipeConsumerHandle handle_; |
| 60 mojo::common::HandleWatcher handle_watcher_; |
| 61 ResourceRequestCompletionStatus completion_status_; |
| 62 |
| 63 bool has_received_completion_ = false; |
| 64 bool has_been_cancelled_ = false; |
| 65 bool has_seen_end_of_data_; |
| 66 |
| 67 DISALLOW_COPY_AND_ASSIGN(URLResponseBodyConsumer); |
| 68 }; |
| 69 |
| 70 } // namespace content |
| 71 |
| 72 #endif // CONTENT_CHILD_URL_RESPONSE_BODY_CONSUMER_H_ |
OLD | NEW |