blob: bb3df85d9f81641ee85c793770dd7e2ff3e9aef1 [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>
11
12namespace net {
13class HttpRequestHeaders;
Jun Cai6260d6c2018-06-26 23:29:0814struct NetworkTrafficAnnotationTag;
Dominic Battre5e8a1cd2018-01-02 16:16:5815class URLRequest;
asvitkine9a279832015-12-18 02:35:5016}
17
Jun Cai6260d6c2018-06-26 23:29:0818namespace network {
19struct ResourceRequest;
20class SimpleURLLoader;
21} // namespace network
22
asvitkine9a279832015-12-18 02:35:5023class GURL;
24
25namespace variations {
26
Mark Pearsoncea91cf2017-12-13 20:45:5827enum class InIncognito { kNo, kYes };
28
29enum class SignedIn { kNo, kYes };
30
asvitkine9a279832015-12-18 02:35:5031// Adds Chrome experiment and metrics state as custom headers to |headers|.
Mark Pearsoncea91cf2017-12-13 20:45:5832// The content of the headers will depend on |incognito| and |signed_in|
33// parameters. It is fine to pass SignedIn::NO if the state is not known to the
34// caller. This will prevent addition of ids of type
yutak3305f49d2016-12-13 10:32:3135// GOOGLE_WEB_PROPERTIES_SIGNED_IN, which is not the case for any ids that come
36// from the variations server. These headers are never transmitted to non-Google
37// web sites, which is checked based on the destination |url|.
Jun Cai6260d6c2018-06-26 23:29:0838// Returns true if custom headers are added. Returns false otherwise.
39bool AppendVariationHeaders(const GURL& url,
Mark Pearsoncea91cf2017-12-13 20:45:5840 InIncognito incognito,
41 SignedIn signed_in,
asvitkine9a279832015-12-18 02:35:5042 net::HttpRequestHeaders* headers);
43
44// Returns the HTTP header names which are added by AppendVariationHeaders().
45std::set<std::string> GetVariationHeaderNames();
46
Dominic Battre5e8a1cd2018-01-02 16:16:5847// Strips the variation header if |new_location| does not point to a location
48// that should receive it. This is being called by the ChromeNetworkDelegate.
49// Components calling AppendVariationsHeaders() don't need to take care of this.
50void StripVariationHeaderIfNeeded(const GURL& new_location,
51 net::URLRequest* request);
52
Jun Cai6260d6c2018-06-26 23:29:0853// Creates a SimpleURLLoader that will include variations headers for requests
54// to Google and ensures they're removed if a redirect to a non-Google URL
55// occurs.
56std::unique_ptr<network::SimpleURLLoader>
57CreateSimpleURLLoaderWithVariationsHeaders(
58 std::unique_ptr<network::ResourceRequest> request,
59 InIncognito incognito,
60 SignedIn signed_in,
61 const net::NetworkTrafficAnnotationTag& annotation_tag);
62
asvitkine9a279832015-12-18 02:35:5063namespace internal {
64
65// Checks whether variation headers should be appended to requests to the
jwda949b562016-12-13 17:15:1666// specified |url|. Returns true for google.<TLD> and youtube.<TLD> URLs with
67// the https scheme.
asvitkine9a279832015-12-18 02:35:5068bool ShouldAppendVariationHeaders(const GURL& url);
69
70} // namespace internal
71
72} // namespace variations
73
74#endif // COMPONENTS_VARIATIONS_NET_VARIATIONS_HTTP_HEADERS_H_