blob: cc2ae5926d0c99e0b2729381f5b8cb28a050bca9 [file] [log] [blame]
asvitkine9a279832015-12-18 02:35:501// Copyright 2015 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 COMPONENTS_VARIATIONS_NET_VARIATIONS_HTTP_HEADERS_H_
6#define COMPONENTS_VARIATIONS_NET_VARIATIONS_HTTP_HEADERS_H_
7
Jun Cai6260d6c2018-06-26 23:29:088#include <memory>
asvitkine9a279832015-12-18 02:35:509#include <set>
10#include <string>
Takashi Toyoshimaf3ceca92019-02-04 07:49:0511#include <vector>
asvitkine9a279832015-12-18 02:35:5012
Takashi Toyoshimacd413b42019-04-10 20:33:4613#include "services/network/public/mojom/network_context.mojom.h"
Lucas Furukawa Gadani962a30c2019-09-18 19:55:0814#include "services/network/public/mojom/url_response_head.mojom-forward.h"
Takashi Toyoshimacd413b42019-04-10 20:33:4615
asvitkine9a279832015-12-18 02:35:5016namespace net {
Jun Cai6260d6c2018-06-26 23:29:0817struct NetworkTrafficAnnotationTag;
Takashi Toyoshimaf3ceca92019-02-04 07:49:0518struct RedirectInfo;
asvitkine9a279832015-12-18 02:35:5019}
20
Jun Cai6260d6c2018-06-26 23:29:0821namespace network {
22struct ResourceRequest;
Jun Cai6260d6c2018-06-26 23:29:0823class SimpleURLLoader;
24} // namespace network
25
asvitkine9a279832015-12-18 02:35:5026class GURL;
27
28namespace variations {
29
Mark Pearsoncea91cf2017-12-13 20:45:5830enum class InIncognito { kNo, kYes };
31
32enum class SignedIn { kNo, kYes };
33
Takashi Toyoshimaf3ceca92019-02-04 07:49:0534// Adds Chrome experiment and metrics state as custom headers to |request|.
Mark Pearsoncea91cf2017-12-13 20:45:5835// The content of the headers will depend on |incognito| and |signed_in|
36// parameters. It is fine to pass SignedIn::NO if the state is not known to the
37// caller. This will prevent addition of ids of type
yutak3305f49d2016-12-13 10:32:3138// GOOGLE_WEB_PROPERTIES_SIGNED_IN, which is not the case for any ids that come
39// from the variations server. These headers are never transmitted to non-Google
40// web sites, which is checked based on the destination |url|.
Jun Cai6260d6c2018-06-26 23:29:0841// Returns true if custom headers are added. Returns false otherwise.
Takashi Toyoshimaf3ceca92019-02-04 07:49:0542bool AppendVariationsHeader(const GURL& url,
Mark Pearsoncea91cf2017-12-13 20:45:5843 InIncognito incognito,
44 SignedIn signed_in,
Takashi Toyoshimaf3ceca92019-02-04 07:49:0545 network::ResourceRequest* request);
asvitkine9a279832015-12-18 02:35:5046
Takashi Toyoshima03a7b3fa2019-06-14 10:10:1047// Similar to AppendVariationsHeader, but uses specified |variations_header| as
48// the custom header value. You should not generally need to use this.
Takashi Toyoshimaf3ceca92019-02-04 07:49:0549bool AppendVariationsHeaderWithCustomValue(const GURL& url,
Wang Hui00fff442018-07-09 23:50:2350 InIncognito incognito,
Takashi Toyoshimaf3ceca92019-02-04 07:49:0551 const std::string& variations_header,
52 network::ResourceRequest* request);
Wang Hui00fff442018-07-09 23:50:2353
Takashi Toyoshimaf3ceca92019-02-04 07:49:0554// Adds Chrome experiment and metrics state as a custom header to |request|
55// when the signed-in state is not known to the caller; See above for details.
56bool AppendVariationsHeaderUnknownSignedIn(const GURL& url,
57 InIncognito incognito,
58 network::ResourceRequest* request);
59
Takashi Toyoshimaf3ceca92019-02-04 07:49:0560// Removes the variations header for requests when a redirect to a non-Google
61// URL occurs.
62void RemoveVariationsHeaderIfNeeded(
63 const net::RedirectInfo& redirect_info,
Lucas Furukawa Gadani962a30c2019-09-18 19:55:0864 const network::mojom::URLResponseHead& response_head,
Takashi Toyoshimaf3ceca92019-02-04 07:49:0565 std::vector<std::string>* to_be_removed_headers);
66
Takashi Toyoshimaf3ceca92019-02-04 07:49:0567// Creates a SimpleURLLoader that will include the variations header for
68// requests to Google and ensures they're removed if a redirect to a non-Google
69// URL occurs.
Jun Cai6260d6c2018-06-26 23:29:0870std::unique_ptr<network::SimpleURLLoader>
Takashi Toyoshimaf3ceca92019-02-04 07:49:0571CreateSimpleURLLoaderWithVariationsHeader(
Jun Cai6260d6c2018-06-26 23:29:0872 std::unique_ptr<network::ResourceRequest> request,
73 InIncognito incognito,
74 SignedIn signed_in,
75 const net::NetworkTrafficAnnotationTag& annotation_tag);
76
Takashi Toyoshimaf3ceca92019-02-04 07:49:0577// Creates a SimpleURLLoader that will include the variations header for
78// requests to Google when the signed-in state is unknown and ensures they're
79// removed if a redirect to a non-Google URL occurs.
Wang Hui00fff442018-07-09 23:50:2380std::unique_ptr<network::SimpleURLLoader>
Takashi Toyoshimaf3ceca92019-02-04 07:49:0581CreateSimpleURLLoaderWithVariationsHeaderUnknownSignedIn(
Wang Hui00fff442018-07-09 23:50:2382 std::unique_ptr<network::ResourceRequest> request,
83 InIncognito incognito,
84 const net::NetworkTrafficAnnotationTag& annotation_tag);
85
Takashi Toyoshimaf3ceca92019-02-04 07:49:0586// Checks if |header_name| is one for the variations header.
87bool IsVariationsHeader(const std::string& header_name);
88
89// Checks if |request| contains the variations header.
90bool HasVariationsHeader(const network::ResourceRequest& request);
91
Takashi Toyoshima395c7522019-02-07 10:19:4492// Calls the internal ShouldAppendVariationsHeader() for testing.
93bool ShouldAppendVariationsHeaderForTesting(const GURL& url);
asvitkine9a279832015-12-18 02:35:5094
Takashi Toyoshimacd413b42019-04-10 20:33:4695// Updates |cors_exempt_header_list| field of the given |param| to register the
96// variation headers.
97void UpdateCorsExemptHeaderForVariations(
98 network::mojom::NetworkContextParams* params);
99
asvitkine9a279832015-12-18 02:35:50100} // namespace variations
101
102#endif // COMPONENTS_VARIATIONS_NET_VARIATIONS_HTTP_HEADERS_H_