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

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: 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_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/content_export.h"
18 #include "content/common/url_loader.mojom.h"
19 #include "mojo/message_pump/handle_watcher.h"
20 #include "mojo/public/cpp/bindings/binding.h"
21 #include "net/base/io_buffer.h"
22 #include "url/gurl.h"
23
24 namespace net {
25 class URLRequest;
26 }
27
28 namespace content {
29 class ResourceDispatcherHostImpl;
30 class ResourceRequestInfoImpl;
31 struct ResourceResponse;
32
33 // Used to complete an asynchronous resource request in response to resource
34 // load events from the resource dispatcher host. This class is used only
35 // when LoadingWithMojo runtime enabled flag is enabled.
36 //
37 // TODO(yhirano): Implement redirects.
38 // TODO(yhirano): Implement downloading to file.
39 // TODO(yhirano): Add histograms.
40 // TODO(yhirano): Set zoom level.
41 // TODO(yhirano): Send cached metadata.
42 //
43 // This class can be inherited only for tests.
44 class CONTENT_EXPORT MojoAsyncResourceHandler
45 : public ResourceHandler,
46 public NON_EXPORTED_BASE(mojom::URLLoader) {
47 public:
48 MojoAsyncResourceHandler(
49 net::URLRequest* request,
50 ResourceDispatcherHostImpl* rdh,
51 mojo::InterfaceRequest<mojom::URLLoader> mojo_request,
52 mojom::URLLoaderClientPtr url_loader_client);
53 ~MojoAsyncResourceHandler() override;
54
55 // ResourceHandler implementation:
56 bool OnRequestRedirected(const net::RedirectInfo& redirect_info,
57 ResourceResponse* response,
58 bool* defer) override;
59 bool OnResponseStarted(ResourceResponse* response, bool* defer) override;
60 bool OnWillStart(const GURL& url, bool* defer) override;
61 bool OnWillRead(scoped_refptr<net::IOBuffer>* buf,
62 int* buf_size,
63 int min_size) override;
64 bool OnReadCompleted(int bytes_read, bool* defer) override;
65 void OnResponseCompleted(const net::URLRequestStatus& status,
66 const std::string& security_info,
67 bool* defer) override;
68 void OnDataDownloaded(int bytes_downloaded) override;
69
70 // mojom::URLLoader implementation
71 void FollowRedirect() override;
72 void Cancel() override;
73
74 void ResumeForTesting();
75 static void SetAllocationSizeForTesting(size_t size);
76 static constexpr size_t kDefaultAllocationSize = 512 * 1024;
77
78 protected:
79 // These functions can be overriden only for tests.
80 virtual MojoResult BeginWrite(void** data, uint32_t* available);
81 virtual MojoResult EndWrite(uint32_t written);
82
83 private:
84 class SharedWriter;
85 class WriterIOBuffer;
86
87 // This funcion copies data stored in |buffer_| to |shared_writer_| and
88 // resets |buffer_| to a WriterIOBuffer when all bytes are copied. Returns
89 // true when done successfully.
90 bool CopyReadData(bool* defer);
91 // Allocates a WriterIOBuffer and set it to |*buf|. Returns true when done
92 // successfully.
93 bool AllocateBuffer(scoped_refptr<net::IOBufferWithSize>* buf, bool* defer);
kinuko 2016/08/03 18:20:07 nit (optional): these methods are private so it's
yhirano 2016/08/04 12:50:51 Done.
94
95 void Resume();
96 void OnDefer();
97 bool CheckForSufficientResource();
98 void OnWritable(MojoResult result);
99
100 ResourceDispatcherHostImpl* rdh_;
101 mojo::Binding<mojom::URLLoader> binding_;
102
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