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

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

Issue 2629513003: Implement CachedMetadata handling on MojoAsyncResourceHandler (Closed)
Patch Set: fix Created 3 years, 11 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_BROWSER_LOADER_TEST_URL_LOADER_CLIENT_H_ 5 #ifndef CONTENT_BROWSER_LOADER_TEST_URL_LOADER_CLIENT_H_
6 #define CONTENT_BROWSER_LOADER_TEST_URL_LOADER_CLIENT_H_ 6 #define CONTENT_BROWSER_LOADER_TEST_URL_LOADER_CLIENT_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <vector>
9 10
10 #include "base/callback.h" 11 #include "base/callback.h"
11 #include "base/macros.h" 12 #include "base/macros.h"
12 #include "content/common/resource_request_completion_status.h" 13 #include "content/common/resource_request_completion_status.h"
13 #include "content/common/url_loader.mojom.h" 14 #include "content/common/url_loader.mojom.h"
14 #include "content/common/url_loader_factory.mojom.h" 15 #include "content/common/url_loader_factory.mojom.h"
15 #include "content/public/common/resource_response.h" 16 #include "content/public/common/resource_response.h"
16 #include "mojo/public/c/system/data_pipe.h" 17 #include "mojo/public/c/system/data_pipe.h"
17 #include "mojo/public/cpp/bindings/associated_binding.h" 18 #include "mojo/public/cpp/bindings/associated_binding.h"
18 #include "net/url_request/redirect_info.h" 19 #include "net/url_request/redirect_info.h"
19 20
20 namespace content { 21 namespace content {
21 22
22 // A TestURLLoaderClient records URLLoaderClient function calls. It also calls 23 // A TestURLLoaderClient records URLLoaderClient function calls. It also calls
23 // the closure set via set_quit_closure if set, in order to make it possible to 24 // the closure set via set_quit_closure if set, in order to make it possible to
24 // create a base::RunLoop, set its quit closure to this client and then run the 25 // create a base::RunLoop, set its quit closure to this client and then run the
25 // RunLoop. 26 // RunLoop.
26 class TestURLLoaderClient final : public mojom::URLLoaderClient { 27 class TestURLLoaderClient final : public mojom::URLLoaderClient {
27 public: 28 public:
28 TestURLLoaderClient(); 29 TestURLLoaderClient();
29 ~TestURLLoaderClient() override; 30 ~TestURLLoaderClient() override;
30 31
31 void OnReceiveResponse(const ResourceResponseHead& response_head, 32 void OnReceiveResponse(const ResourceResponseHead& response_head,
32 mojom::DownloadedTempFilePtr downloaded_file) override; 33 mojom::DownloadedTempFilePtr downloaded_file) override;
33 void OnReceiveRedirect(const net::RedirectInfo& redirect_info, 34 void OnReceiveRedirect(const net::RedirectInfo& redirect_info,
34 const ResourceResponseHead& response_head) override; 35 const ResourceResponseHead& response_head) override;
35 void OnDataDownloaded(int64_t data_length, int64_t encoded_length) override; 36 void OnDataDownloaded(int64_t data_length, int64_t encoded_length) override;
37 void OnReceiveCachedMetadata(const std::vector<uint8_t>& data) override;
36 void OnTransferSizeUpdated(int32_t transfer_size_diff) override; 38 void OnTransferSizeUpdated(int32_t transfer_size_diff) override;
37 void OnStartLoadingResponseBody( 39 void OnStartLoadingResponseBody(
38 mojo::ScopedDataPipeConsumerHandle body) override; 40 mojo::ScopedDataPipeConsumerHandle body) override;
39 void OnComplete(const ResourceRequestCompletionStatus& status) override; 41 void OnComplete(const ResourceRequestCompletionStatus& status) override;
40 42
41 bool has_received_response() const { return has_received_response_; } 43 bool has_received_response() const { return has_received_response_; }
42 bool has_received_redirect() const { return has_received_redirect_; } 44 bool has_received_redirect() const { return has_received_redirect_; }
43 bool has_data_downloaded() const { return has_data_downloaded_; } 45 bool has_data_downloaded() const { return has_data_downloaded_; }
46 bool has_received_cached_metadata() const {
47 return has_received_cached_metadata_;
48 }
44 bool has_received_completion() const { return has_received_completion_; } 49 bool has_received_completion() const { return has_received_completion_; }
45 const ResourceResponseHead& response_head() const { return response_head_; } 50 const ResourceResponseHead& response_head() const { return response_head_; }
46 const net::RedirectInfo& redirect_info() const { return redirect_info_; } 51 const net::RedirectInfo& redirect_info() const { return redirect_info_; }
52 const std::string& cached_metadata() const {
53 return cached_metadata_;
54 }
47 mojo::DataPipeConsumerHandle response_body() { return response_body_.get(); } 55 mojo::DataPipeConsumerHandle response_body() { return response_body_.get(); }
48 const ResourceRequestCompletionStatus& completion_status() const { 56 const ResourceRequestCompletionStatus& completion_status() const {
49 return completion_status_; 57 return completion_status_;
50 } 58 }
51 int64_t download_data_length() const { return download_data_length_; } 59 int64_t download_data_length() const { return download_data_length_; }
52 int64_t encoded_download_data_length() const { 60 int64_t encoded_download_data_length() const {
53 return encoded_download_data_length_; 61 return encoded_download_data_length_;
54 } 62 }
55 int64_t body_transfer_size() const { return body_transfer_size_; } 63 int64_t body_transfer_size() const { return body_transfer_size_; }
56 64
57 void ClearHasReceivedRedirect(); 65 void ClearHasReceivedRedirect();
58 // Creates an AssociatedPtrInfo, binds it to |*this| and returns it. The 66 // Creates an AssociatedPtrInfo, binds it to |*this| and returns it. The
59 // returned PtrInfo is marked as remote, i.e., expected to be passed to the 67 // returned PtrInfo is marked as remote, i.e., expected to be passed to the
60 // remote endpoint. 68 // remote endpoint.
61 mojom::URLLoaderClientAssociatedPtrInfo CreateRemoteAssociatedPtrInfo( 69 mojom::URLLoaderClientAssociatedPtrInfo CreateRemoteAssociatedPtrInfo(
62 mojo::AssociatedGroup* associated_group); 70 mojo::AssociatedGroup* associated_group);
63 71
64 void Unbind(); 72 void Unbind();
65 73
66 void RunUntilResponseReceived(); 74 void RunUntilResponseReceived();
67 void RunUntilRedirectReceived(); 75 void RunUntilRedirectReceived();
68 void RunUntilDataDownloaded(); 76 void RunUntilDataDownloaded();
77 void RunUntilCachedMetadataReceived();
69 void RunUntilResponseBodyArrived(); 78 void RunUntilResponseBodyArrived();
70 void RunUntilComplete(); 79 void RunUntilComplete();
71 80
72 private: 81 private:
73 mojo::AssociatedBinding<mojom::URLLoaderClient> binding_; 82 mojo::AssociatedBinding<mojom::URLLoaderClient> binding_;
74 ResourceResponseHead response_head_; 83 ResourceResponseHead response_head_;
75 net::RedirectInfo redirect_info_; 84 net::RedirectInfo redirect_info_;
85 std::string cached_metadata_;
76 mojo::ScopedDataPipeConsumerHandle response_body_; 86 mojo::ScopedDataPipeConsumerHandle response_body_;
77 ResourceRequestCompletionStatus completion_status_; 87 ResourceRequestCompletionStatus completion_status_;
78 bool has_received_response_ = false; 88 bool has_received_response_ = false;
79 bool has_received_redirect_ = false; 89 bool has_received_redirect_ = false;
80 bool has_data_downloaded_ = false; 90 bool has_data_downloaded_ = false;
91 bool has_received_cached_metadata_ = false;
81 bool has_received_completion_ = false; 92 bool has_received_completion_ = false;
82 base::Closure quit_closure_for_on_receive_response_; 93 base::Closure quit_closure_for_on_receive_response_;
83 base::Closure quit_closure_for_on_receive_redirect_; 94 base::Closure quit_closure_for_on_receive_redirect_;
84 base::Closure quit_closure_for_on_data_downloaded_; 95 base::Closure quit_closure_for_on_data_downloaded_;
96 base::Closure quit_closure_for_on_receive_cached_metadata_;
85 base::Closure quit_closure_for_on_start_loading_response_body_; 97 base::Closure quit_closure_for_on_start_loading_response_body_;
86 base::Closure quit_closure_for_on_complete_; 98 base::Closure quit_closure_for_on_complete_;
87 mojom::URLLoaderFactoryPtr url_loader_factory_; 99 mojom::URLLoaderFactoryPtr url_loader_factory_;
88 int64_t download_data_length_ = 0; 100 int64_t download_data_length_ = 0;
89 int64_t encoded_download_data_length_ = 0; 101 int64_t encoded_download_data_length_ = 0;
90 int64_t body_transfer_size_ = 0; 102 int64_t body_transfer_size_ = 0;
91 103
92 DISALLOW_COPY_AND_ASSIGN(TestURLLoaderClient); 104 DISALLOW_COPY_AND_ASSIGN(TestURLLoaderClient);
93 }; 105 };
94 106
95 } // namespace content 107 } // namespace content
96 108
97 #endif // CONTENT_BROWSER_LOADER_TEST_URL_LOADER_CLIENT_H_ 109 #endif // CONTENT_BROWSER_LOADER_TEST_URL_LOADER_CLIENT_H_
OLDNEW
« no previous file with comments | « content/browser/loader/mojo_async_resource_handler_unittest.cc ('k') | content/browser/loader/test_url_loader_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698