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

Side by Side Diff: content/browser/loader/mojo_async_resource_handler.h

Issue 1970693002: Use mojo for Chrome Loading, Part 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix Created 4 years, 5 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_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/compiler_specific.h"
14 #include "base/macros.h"
15 #include "base/memory/ref_counted.h"
16 #include "base/timer/timer.h"
17 #include "content/browser/loader/resource_handler.h"
18 #include "content/common/content_export.h"
19 #include "content/common/url_loader.mojom.h"
20 #include "mojo/message_pump/handle_watcher.h"
21 #include "mojo/public/cpp/bindings/binding.h"
22 #include "net/base/io_buffer.h"
23 #include "url/gurl.h"
24
25 namespace net {
26 class URLRequest;
27 }
28
29 namespace content {
30 class ResourceDispatcherHostImpl;
31 class ResourceRequestInfoImpl;
32 struct ResourceResponse;
33
34 // Used to complete an asynchronous resource request in response to resource
35 // load events from the resource dispatcher host. This class is used only
36 // when LoadingWithMojo runtime enabled flag is enabled.
37 //
38 // TODO(yhirano): Implement redirects.
39 // TODO(yhirano): Implement downloading to file.
40 // TODO(yhirano): Add histograms.
41 // TODO(yhirano): Set zoom level.
42 // TODO(yhirano): Send cached metadata.
43 //
44 // This class can be inherited only for tests.
45 class CONTENT_EXPORT MojoAsyncResourceHandler
46 : public ResourceHandler,
47 public NON_EXPORTED_BASE(mojom::URLLoader) {
48 public:
49 MojoAsyncResourceHandler(
50 net::URLRequest* request,
51 ResourceDispatcherHostImpl* rdh,
52 mojo::InterfaceRequest<mojom::URLLoader> mojo_request,
53 mojom::URLLoaderClientPtr url_loader_client);
54 ~MojoAsyncResourceHandler() override;
55
56 // ResourceHandler implementation:
57 bool OnRequestRedirected(const net::RedirectInfo& redirect_info,
58 ResourceResponse* response,
59 bool* defer) override;
60 bool OnResponseStarted(ResourceResponse* response, bool* defer) override;
61 bool OnWillStart(const GURL& url, bool* defer) override;
62 bool OnBeforeNetworkStart(const GURL& url, bool* defer) override;
63 bool OnWillRead(scoped_refptr<net::IOBuffer>* buf,
64 int* buf_size,
65 int min_size) override;
66 bool OnReadCompleted(int bytes_read, bool* defer) override;
67 void OnResponseCompleted(const net::URLRequestStatus& status,
68 const std::string& security_info,
69 bool* defer) override;
70 void OnDataDownloaded(int bytes_downloaded) override;
71
72 ResourceRequestInfoImpl* GetRequestInfoForTesting() {
73 return GetRequestInfo();
74 }
75 // mojom::URLLoader implementation
76 void FollowRedirect() override;
77 void Cancel() override;
78
79 static void SetAllocationSizeForTesting(size_t size);
80 static constexpr size_t kDefaultAllocationSize = 512 * 1024;
81
82 protected:
83 // These functions can be overriden only for tests.
84 virtual MojoResult BeginWrite(void** data, uint32_t* available);
85 virtual MojoResult EndWrite(uint32_t written);
86
87 private:
88 class SharedWriter;
89 class WriterIOBuffer;
90
91 bool CopyReadData(bool* defer);
mmenke 2016/07/19 20:50:27 These should all be documented.
yhirano 2016/07/20 13:38:36 Done.
92 bool AllocateBuffer(bool* defer);
93
94 void ResumeIfDeferred();
95 void OnDefer();
96 bool CheckForSufficientResource();
97 void OnWritable(MojoResult result);
98
99 ResourceDispatcherHostImpl* rdh_;
100 mojo::Binding<mojom::URLLoader> binding_;
101
102 bool did_defer_ = false;
103 bool has_checked_for_sufficient_resources_ = false;
104 bool sent_received_response_message_ = false;
105 bool is_using_io_buffer_not_from_writer_ = false;
106 base::TimeTicks response_started_ticks_;
107
108 mojo::common::HandleWatcher handle_watcher_;
109 std::unique_ptr<mojom::URLLoader> url_loader_;
110 mojom::URLLoaderClientPtr url_loader_client_;
111 scoped_refptr<net::IOBufferWithSize> buffer_;
112 size_t buffer_offset_ = 0;
113 size_t buffer_bytes_read_ = 0;
114 scoped_refptr<SharedWriter> shared_writer_;
115
116 DISALLOW_COPY_AND_ASSIGN(MojoAsyncResourceHandler);
117 };
118
119 } // namespace content
120
121 #endif // CONTENT_BROWSER_LOADER_MOJO_ASYNC_RESOURCE_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698