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

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: Created 4 years, 6 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 "net/base/io_buffer.h"
21 #include "url/gurl.h"
22
23 namespace net {
24 class URLRequest;
25 }
26
27 namespace content {
28 class ResourceDispatcherHostImpl;
29
30 // Used to complete an asynchronous resource request in response to resource
31 // load events from the resource dispatcher host. This class is used only
32 // when LoadingWithMojo runtime enabled flag is enabled.
33 //
34 // TODO(yhirano): Implement redirects.
35 // TODO(yhirano): Implement downloading to file.
36 // TODO(yhirano): Add histograms.
37 // TODO(yhirano): Set zoom level.
38 // TODO(yhirano): Send cached metadata.
39 class MojoAsyncResourceHandler : public ResourceHandler {
40 public:
41 MojoAsyncResourceHandler(net::URLRequest* request,
42 ResourceDispatcherHostImpl* rdh,
43 std::unique_ptr<mojom::URLLoader> url_loader,
44 mojom::URLLoaderClientPtr url_loader_client);
45 ~MojoAsyncResourceHandler() override;
46
47 // ResourceHandler implementation:
48 bool OnRequestRedirected(const net::RedirectInfo& redirect_info,
49 ResourceResponse* response,
50 bool* defer) override;
51 bool OnResponseStarted(ResourceResponse* response, bool* defer) override;
52 bool OnWillStart(const GURL& url, bool* defer) override;
53 bool OnBeforeNetworkStart(const GURL& url, bool* defer) override;
54 bool OnWillRead(scoped_refptr<net::IOBuffer>* buf,
55 int* buf_size,
56 int min_size) override;
57 bool OnReadCompleted(int bytes_read, bool* defer) override;
58 void OnResponseCompleted(const net::URLRequestStatus& status,
59 const std::string& security_info,
60 bool* defer) override;
61 void OnDataDownloaded(int bytes_downloaded) override;
62
63 static CONTENT_EXPORT void SetAllocationSizeForTesting(size_t size);
64
65 private:
66 class SharedWriter;
67 class WriterIOBuffer;
68
69 bool CopyReadData(bool* defer);
70 bool AllocateBuffer(bool* defer);
71
72 void ResumeIfDeferred();
73 void OnDefer();
74 bool CheckForSufficientResource();
75 void OnWritable(MojoResult result);
76
77 ResourceDispatcherHostImpl* rdh_;
78
79 bool did_defer_ = false;
80 bool has_checked_for_sufficient_resources_ = false;
81 bool sent_received_response_message_ = false;
82 bool is_using_io_buffer_not_from_writer_ = false;
83 base::TimeTicks response_started_ticks_;
84
85 mojo::common::HandleWatcher handle_watcher_;
86 std::unique_ptr<mojom::URLLoader> url_loader_;
87 mojom::URLLoaderClientPtr url_loader_client_;
88 scoped_refptr<net::IOBufferWithSize> buffer_;
89 size_t buffer_offset_ = 0;
90 size_t buffer_bytes_read_ = 0;
91 scoped_refptr<SharedWriter> shared_writer_;
92
93 DISALLOW_COPY_AND_ASSIGN(MojoAsyncResourceHandler);
94 };
95
96 } // namespace content
97
98 #endif // CONTENT_BROWSER_LOADER_MOJO_ASYNC_RESOURCE_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698