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

Side by Side Diff: content/child/url_response_body_consumer.h

Issue 1970693002: Use mojo for Chrome Loading, Part 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 4 months 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
OLDNEW
(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 "base/memory/weak_ptr.h"
17 #include "base/single_thread_task_runner.h"
18 #include "content/common/content_export.h"
19 #include "content/common/url_loader.mojom.h"
20 #include "mojo/public/cpp/system/data_pipe.h"
21 #include "mojo/public/cpp/system/watcher.h"
22
23 namespace content {
24
25 class ResourceDispatcher;
26 struct ResourceRequestCompletionStatus;
27
28 // This class pulls data from a data pipe and dispatches it to the
29 // ResourceDispatcher. This class is used only for mojo-enabled requests.
30 class CONTENT_EXPORT URLResponseBodyConsumer final
31 : public base::RefCounted<URLResponseBodyConsumer>,
32 public base::SupportsWeakPtr<URLResponseBodyConsumer> {
33 public:
34 URLResponseBodyConsumer(int request_id,
35 ResourceDispatcher* resource_dispatcher,
36 mojo::ScopedDataPipeConsumerHandle handle,
37 base::SingleThreadTaskRunner* task_runner);
38
39 // Sets the completion status. The completion status is dispatched to the
40 // ResourceDispatcher when the both following conditions hold:
41 // 1) This function has been called and the completion status is set, and
42 // 2) All data is read from the handle.
43 void OnComplete(const ResourceRequestCompletionStatus& status);
44
45 // Cancels watching the handle and dispatches an error to the
46 // ResourceDispatcher. This function does nothing if the reading is already
47 // cancelled or done.
48 void Cancel();
49
50 private:
51 friend class base::RefCounted<URLResponseBodyConsumer>;
52 ~URLResponseBodyConsumer();
53
54 class ReceivedData;
55 void Reclaim(uint32_t size);
56
57 void OnReadable(MojoResult unused);
58 void NotifyCompletionIfAppropriate();
59
60 const int request_id_;
61 ResourceDispatcher* resource_dispatcher_;
62 mojo::ScopedDataPipeConsumerHandle handle_;
63 mojo::Watcher handle_watcher_;
64 ResourceRequestCompletionStatus completion_status_;
65
66 bool has_received_completion_ = false;
67 bool has_been_cancelled_ = false;
68 bool has_seen_end_of_data_;
69
70 DISALLOW_COPY_AND_ASSIGN(URLResponseBodyConsumer);
71 };
72
73 } // namespace content
74
75 #endif // CONTENT_CHILD_URL_RESPONSE_BODY_CONSUMER_H_
OLDNEW
« no previous file with comments | « content/child/resource_dispatcher_unittest.cc ('k') | content/child/url_response_body_consumer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698