asvitkine | 9a27983 | 2015-12-18 02:35:50 | [diff] [blame] | 1 | // 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 Cai | 6260d6c | 2018-06-26 23:29:08 | [diff] [blame^] | 8 | #include <memory> |
asvitkine | 9a27983 | 2015-12-18 02:35:50 | [diff] [blame] | 9 | #include <set> |
| 10 | #include <string> |
| 11 | |
| 12 | namespace net { |
| 13 | class HttpRequestHeaders; |
Jun Cai | 6260d6c | 2018-06-26 23:29:08 | [diff] [blame^] | 14 | struct NetworkTrafficAnnotationTag; |
Dominic Battre | 5e8a1cd | 2018-01-02 16:16:58 | [diff] [blame] | 15 | class URLRequest; |
asvitkine | 9a27983 | 2015-12-18 02:35:50 | [diff] [blame] | 16 | } |
| 17 | |
Jun Cai | 6260d6c | 2018-06-26 23:29:08 | [diff] [blame^] | 18 | namespace network { |
| 19 | struct ResourceRequest; |
| 20 | class SimpleURLLoader; |
| 21 | } // namespace network |
| 22 | |
asvitkine | 9a27983 | 2015-12-18 02:35:50 | [diff] [blame] | 23 | class GURL; |
| 24 | |
| 25 | namespace variations { |
| 26 | |
Mark Pearson | cea91cf | 2017-12-13 20:45:58 | [diff] [blame] | 27 | enum class InIncognito { kNo, kYes }; |
| 28 | |
| 29 | enum class SignedIn { kNo, kYes }; |
| 30 | |
asvitkine | 9a27983 | 2015-12-18 02:35:50 | [diff] [blame] | 31 | // Adds Chrome experiment and metrics state as custom headers to |headers|. |
Mark Pearson | cea91cf | 2017-12-13 20:45:58 | [diff] [blame] | 32 | // 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 |
yutak | 3305f49d | 2016-12-13 10:32:31 | [diff] [blame] | 35 | // 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 Cai | 6260d6c | 2018-06-26 23:29:08 | [diff] [blame^] | 38 | // Returns true if custom headers are added. Returns false otherwise. |
| 39 | bool AppendVariationHeaders(const GURL& url, |
Mark Pearson | cea91cf | 2017-12-13 20:45:58 | [diff] [blame] | 40 | InIncognito incognito, |
| 41 | SignedIn signed_in, |
asvitkine | 9a27983 | 2015-12-18 02:35:50 | [diff] [blame] | 42 | net::HttpRequestHeaders* headers); |
| 43 | |
| 44 | // Returns the HTTP header names which are added by AppendVariationHeaders(). |
| 45 | std::set<std::string> GetVariationHeaderNames(); |
| 46 | |
Dominic Battre | 5e8a1cd | 2018-01-02 16:16:58 | [diff] [blame] | 47 | // 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. |
| 50 | void StripVariationHeaderIfNeeded(const GURL& new_location, |
| 51 | net::URLRequest* request); |
| 52 | |
Jun Cai | 6260d6c | 2018-06-26 23:29:08 | [diff] [blame^] | 53 | // 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. |
| 56 | std::unique_ptr<network::SimpleURLLoader> |
| 57 | CreateSimpleURLLoaderWithVariationsHeaders( |
| 58 | std::unique_ptr<network::ResourceRequest> request, |
| 59 | InIncognito incognito, |
| 60 | SignedIn signed_in, |
| 61 | const net::NetworkTrafficAnnotationTag& annotation_tag); |
| 62 | |
asvitkine | 9a27983 | 2015-12-18 02:35:50 | [diff] [blame] | 63 | namespace internal { |
| 64 | |
| 65 | // Checks whether variation headers should be appended to requests to the |
jwd | a949b56 | 2016-12-13 17:15:16 | [diff] [blame] | 66 | // specified |url|. Returns true for google.<TLD> and youtube.<TLD> URLs with |
| 67 | // the https scheme. |
asvitkine | 9a27983 | 2015-12-18 02:35:50 | [diff] [blame] | 68 | bool ShouldAppendVariationHeaders(const GURL& url); |
| 69 | |
| 70 | } // namespace internal |
| 71 | |
| 72 | } // namespace variations |
| 73 | |
| 74 | #endif // COMPONENTS_VARIATIONS_NET_VARIATIONS_HTTP_HEADERS_H_ |