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

Unified Diff: content/child/throttling_url_loader.h

Issue 2900563002: Network service: Safe browsing check for sub-resources from renderer. (Closed)
Patch Set: . Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: content/child/throttling_url_loader.h
diff --git a/content/child/throttling_url_loader.h b/content/child/throttling_url_loader.h
new file mode 100644
index 0000000000000000000000000000000000000000..d592f9f7d85606ac841dbbdb18a1ff172a84fcec
--- /dev/null
+++ b/content/child/throttling_url_loader.h
@@ -0,0 +1,113 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
jam 2017/05/25 15:45:51 please add unit tests for this class to handle pau
yzshen1 2017/05/26 20:43:52 Done.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_CHILD_THROTTLING_URL_LOADER_H_
+#define CONTENT_CHILD_THROTTLING_URL_LOADER_H_
+
+#include <memory>
+
+#include "content/common/url_loader.mojom.h"
+#include "content/common/url_loader_factory.mojom.h"
+#include "content/public/child/url_loader_throttle.h"
+#include "mojo/public/cpp/bindings/binding.h"
+
+namespace content {
+
+namespace mojom {
+class URLLoaderFactory;
+}
+
+class ThrottlingURLLoader : public mojom::URLLoaderClient,
jam 2017/05/25 15:45:51 nit: please document
yzshen1 2017/05/26 20:43:52 Done.
+ public URLLoaderThrottle::Delegate {
+ public:
+ // |factory| and |client| must stay alive during the lifetime of the returned
+ // object.
+ static std::unique_ptr<ThrottlingURLLoader> CreateLoaderAndStart(
+ mojom::URLLoaderFactory* factory,
+ std::vector<std::unique_ptr<URLLoaderThrottle>> throttles,
+ int32_t routing_id,
+ int32_t request_id,
+ uint32_t options,
+ std::unique_ptr<ResourceRequest> url_request,
+ mojom::URLLoaderClient* client);
+
+ ~ThrottlingURLLoader() override;
+
+ void FollowRedirect();
+ void SetPriority(net::RequestPriority priority, int32_t intra_priority_value);
+
+ private:
+ ThrottlingURLLoader(std::vector<std::unique_ptr<URLLoaderThrottle>> throttles,
+ mojom::URLLoaderClient* client);
+
+ void Start(mojom::URLLoaderFactory* factory,
+ int32_t routing_id,
+ int32_t request_id,
+ uint32_t options,
+ std::unique_ptr<ResourceRequest> url_request);
+
+ // mojom::URLLoaderClient implementation:
+ void OnReceiveResponse(const ResourceResponseHead& response_head,
+ const base::Optional<net::SSLInfo>& ssl_info,
+ mojom::DownloadedTempFilePtr downloaded_file) override;
+ void OnReceiveRedirect(const net::RedirectInfo& redirect_info,
+ const ResourceResponseHead& response_head) override;
+ void OnDataDownloaded(int64_t data_len, int64_t encoded_data_len) override;
+ void OnUploadProgress(int64_t current_position,
+ int64_t total_size,
+ OnUploadProgressCallback ack_callback) override;
+ void OnReceiveCachedMetadata(const std::vector<uint8_t>& data) override;
+ void OnTransferSizeUpdated(int32_t transfer_size_diff) override;
+ void OnStartLoadingResponseBody(
+ mojo::ScopedDataPipeConsumerHandle body) override;
+ void OnComplete(const ResourceRequestCompletionStatus& status) override;
+
+ // URLLoaderThrottle::Delegate:
+ void CancelWithError(int error_code) override;
+ void Resume() override;
+
+ enum DeferredStage {
+ DEFERRED_NONE,
+ DEFERRED_START,
+ DEFERRED_REDIRECT,
+ DEFERRED_RESPONSE
+ };
+ DeferredStage deferred_stage_ = DEFERRED_NONE;
+ bool cancelled_by_throttle_ = false;
+
+ std::unique_ptr<URLLoaderThrottle> throttle_;
+
+ mojom::URLLoaderClient* forwarding_client_;
+ mojo::Binding<mojom::URLLoaderClient> client_binding_;
+
+ mojom::URLLoaderAssociatedPtr url_loader_;
+
+ // Set if start if deferred.
+ mojom::URLLoaderFactory* url_loader_factory_ = nullptr;
+ int32_t routing_id_ = -1;
+ int32_t request_id_ = -1;
+ uint32_t options_ = mojom::kURLLoadOptionNone;
+ std::unique_ptr<ResourceRequest> url_request_;
+
+ // Set if either response or redirect is deferred.
+ ResourceResponseHead response_head_;
+
+ // Set if response is deferred.
+ base::Optional<net::SSLInfo> ssl_info_;
+ mojom::DownloadedTempFilePtr downloaded_file_;
+
+ // Set if redirect is deferred.
+ net::RedirectInfo redirect_info_;
+
+ // Set if request is deferred and SetPriority() is called.
+ bool set_priority_cached_ = false;
+ net::RequestPriority priority_ = net::MINIMUM_PRIORITY;
+ int32_t intra_priority_value_ = 0;
+
+ DISALLOW_COPY_AND_ASSIGN(ThrottlingURLLoader);
+};
+
+} // namespace content
+
+#endif // CONTENT_CHILD_THROTTLING_URL_LOADER_H_

Powered by Google App Engine
This is Rietveld 408576698