Chromium Code Reviews| Index: content/child/url_response_body_consumer.h |
| diff --git a/content/child/url_response_body_consumer.h b/content/child/url_response_body_consumer.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..18dd4b6f19ca28fbbfbc3c844f82be4fccf29d5f |
| --- /dev/null |
| +++ b/content/child/url_response_body_consumer.h |
| @@ -0,0 +1,72 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CONTENT_CHILD_URL_RESPONSE_BODY_CONSUMER_H_ |
| +#define CONTENT_CHILD_URL_RESPONSE_BODY_CONSUMER_H_ |
| + |
| +#include <stddef.h> |
| +#include <stdint.h> |
| + |
| +#include <utility> |
| +#include <vector> |
| + |
| +#include "base/macros.h" |
| +#include "base/memory/ref_counted.h" |
| +#include "content/common/content_export.h" |
| +#include "content/common/url_loader.mojom.h" |
| +#include "mojo/message_pump/handle_watcher.h" |
| +#include "mojo/public/cpp/system/data_pipe.h" |
| + |
| +namespace content { |
| + |
| +class ResourceDispatcher; |
| +struct ResourceRequestCompletionStatus; |
| + |
| +// This class pulls data from a data pipe and dispatches it to the |
| +// ResourceDispatcher. |
|
kinuko
2016/08/04 16:07:03
nit: also comment that this is used when IPC mode
yhirano
2016/08/05 12:21:40
Done.
|
| +class CONTENT_EXPORT URLResponseBodyConsumer final |
| + : public base::RefCounted<URLResponseBodyConsumer> { |
| + public: |
| + URLResponseBodyConsumer(int request_id, |
| + ResourceDispatcher* resource_dispatcher, |
| + mojo::ScopedDataPipeConsumerHandle handle); |
| + |
| + // Sets the completion status. Dispatches the completion status to the |
| + // ResourceDispatcher when the both following conditions hold: |
| + // 1) The completion status is set by this function, and |
|
kinuko
2016/08/04 16:07:03
I wasn't quite sure what this comment actually mea
yhirano
2016/08/05 12:21:40
No. It means this class stores the completion noti
kinuko
2016/08/08 15:47:25
I see, so it's not really about the behavior of th
yhirano
2016/08/09 06:35:48
Done.
|
| + // 2) All data is read from the handle. |
| + void OnComplete(const ResourceRequestCompletionStatus& status); |
| + |
| + // Cancels watching the handle and dispatches an error to the |
| + // ResourceDispatcher. This function does nothing if the reading is already |
| + // cancelled or done. |
| + void Cancel(); |
| + |
| + private: |
| + friend class base::RefCounted<URLResponseBodyConsumer>; |
| + ~URLResponseBodyConsumer(); |
| + |
| + class ReceivedData; |
| + void Reclaim(uint32_t size); |
| + |
| + void OnReadable(MojoResult); |
| + void StartWatching(); |
| + void NotifyCompletionIfAppropriate(); |
| + |
| + int request_id_; |
|
kinuko
2016/08/04 16:07:03
nit: const
yhirano
2016/08/05 12:21:40
Done.
|
| + ResourceDispatcher* resource_dispatcher_; |
| + mojo::ScopedDataPipeConsumerHandle handle_; |
| + mojo::common::HandleWatcher handle_watcher_; |
| + ResourceRequestCompletionStatus completion_status_; |
| + |
| + bool has_received_completion_ = false; |
| + bool has_been_cancelled_ = false; |
| + bool has_seen_end_of_data_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(URLResponseBodyConsumer); |
| +}; |
| + |
| +} // namespace content |
| + |
| +#endif // CONTENT_CHILD_URL_RESPONSE_BODY_CONSUMER_H_ |