OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "components/network_time/network_time_tracker.h" | 5 #include "components/network_time/network_time_tracker.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 18 matching lines...) Expand all Loading... |
29 #include "net/base/load_flags.h" | 29 #include "net/base/load_flags.h" |
30 #include "net/base/net_errors.h" | 30 #include "net/base/net_errors.h" |
31 #include "net/http/http_response_headers.h" | 31 #include "net/http/http_response_headers.h" |
32 #include "net/traffic_annotation/network_traffic_annotation.h" | 32 #include "net/traffic_annotation/network_traffic_annotation.h" |
33 #include "net/url_request/url_fetcher.h" | 33 #include "net/url_request/url_fetcher.h" |
34 #include "net/url_request/url_fetcher_response_writer.h" | 34 #include "net/url_request/url_fetcher_response_writer.h" |
35 #include "net/url_request/url_request_context_getter.h" | 35 #include "net/url_request/url_request_context_getter.h" |
36 | 36 |
37 namespace network_time { | 37 namespace network_time { |
38 | 38 |
| 39 // Network time queries are enabled on all desktop platforms except ChromeOS, |
| 40 // which uses tlsdated to set the system time. |
| 41 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) || defined(OS_IOS) |
39 const base::Feature kNetworkTimeServiceQuerying{ | 42 const base::Feature kNetworkTimeServiceQuerying{ |
40 "NetworkTimeServiceQuerying", base::FEATURE_DISABLED_BY_DEFAULT}; | 43 "NetworkTimeServiceQuerying", base::FEATURE_DISABLED_BY_DEFAULT}; |
| 44 #else |
| 45 const base::Feature kNetworkTimeServiceQuerying{ |
| 46 "NetworkTimeServiceQuerying", base::FEATURE_ENABLED_BY_DEFAULT}; |
| 47 #endif |
41 | 48 |
42 namespace { | 49 namespace { |
43 | 50 |
44 // Time updates happen in two ways. First, other components may call | 51 // Time updates happen in two ways. First, other components may call |
45 // UpdateNetworkTime() if they happen to obtain the time securely. This will | 52 // UpdateNetworkTime() if they happen to obtain the time securely. This will |
46 // likely be deprecated in favor of the second way, which is scheduled time | 53 // likely be deprecated in favor of the second way, which is scheduled time |
47 // queries issued by NetworkTimeTracker itself. | 54 // queries issued by NetworkTimeTracker itself. |
48 // | 55 // |
49 // On startup, the clock state may be read from a pref. (This, too, may be | 56 // On startup, the clock state may be read from a pref. (This, too, may be |
50 // deprecated.) After that, the time is checked every | 57 // deprecated.) After that, the time is checked every |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 const char kVariationsServiceRandomQueryProbability[] = | 111 const char kVariationsServiceRandomQueryProbability[] = |
105 "RandomQueryProbability"; | 112 "RandomQueryProbability"; |
106 | 113 |
107 // This parameter can have three values: | 114 // This parameter can have three values: |
108 // | 115 // |
109 // - "background-only": Time queries will be issued in the background as | 116 // - "background-only": Time queries will be issued in the background as |
110 // needed (when the clock loses sync), but on-demand time queries will | 117 // needed (when the clock loses sync), but on-demand time queries will |
111 // not be issued (i.e. StartTimeFetch() will not start time queries.) | 118 // not be issued (i.e. StartTimeFetch() will not start time queries.) |
112 // | 119 // |
113 // - "on-demand-only": Time queries will not be issued except when | 120 // - "on-demand-only": Time queries will not be issued except when |
114 // StartTimeFetch() is called. | 121 // StartTimeFetch() is called. This is the default value. |
115 // | 122 // |
116 // - "background-and-on-demand": Time queries will be issued both in the | 123 // - "background-and-on-demand": Time queries will be issued both in the |
117 // background as needed and also on-demand. | 124 // background as needed and also on-demand. |
118 const char kVariationsServiceFetchBehavior[] = "FetchBehavior"; | 125 const char kVariationsServiceFetchBehavior[] = "FetchBehavior"; |
119 | 126 |
120 // This is an ECDSA prime256v1 named-curve key. | 127 // This is an ECDSA prime256v1 named-curve key. |
121 const int kKeyVersion = 1; | 128 const int kKeyVersion = 1; |
122 const uint8_t kKeyPubBytes[] = { | 129 const uint8_t kKeyPubBytes[] = { |
123 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, | 130 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, |
124 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03, | 131 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03, |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 NetworkTimeTracker::FetchBehavior NetworkTimeTracker::GetFetchBehavior() const { | 306 NetworkTimeTracker::FetchBehavior NetworkTimeTracker::GetFetchBehavior() const { |
300 const std::string param = variations::GetVariationParamValueByFeature( | 307 const std::string param = variations::GetVariationParamValueByFeature( |
301 kNetworkTimeServiceQuerying, kVariationsServiceFetchBehavior); | 308 kNetworkTimeServiceQuerying, kVariationsServiceFetchBehavior); |
302 if (param == "background-only") { | 309 if (param == "background-only") { |
303 return FETCHES_IN_BACKGROUND_ONLY; | 310 return FETCHES_IN_BACKGROUND_ONLY; |
304 } else if (param == "on-demand-only") { | 311 } else if (param == "on-demand-only") { |
305 return FETCHES_ON_DEMAND_ONLY; | 312 return FETCHES_ON_DEMAND_ONLY; |
306 } else if (param == "background-and-on-demand") { | 313 } else if (param == "background-and-on-demand") { |
307 return FETCHES_IN_BACKGROUND_AND_ON_DEMAND; | 314 return FETCHES_IN_BACKGROUND_AND_ON_DEMAND; |
308 } | 315 } |
309 return FETCH_BEHAVIOR_UNKNOWN; | 316 return FETCHES_ON_DEMAND_ONLY; |
310 } | 317 } |
311 | 318 |
312 void NetworkTimeTracker::SetTimeServerURLForTesting(const GURL& url) { | 319 void NetworkTimeTracker::SetTimeServerURLForTesting(const GURL& url) { |
313 server_url_ = url; | 320 server_url_ = url; |
314 } | 321 } |
315 | 322 |
316 GURL NetworkTimeTracker::GetTimeServerURLForTesting() const { | 323 GURL NetworkTimeTracker::GetTimeServerURLForTesting() const { |
317 return server_url_; | 324 return server_url_; |
318 } | 325 } |
319 | 326 |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
636 base::Time network_time; | 643 base::Time network_time; |
637 if (GetNetworkTime(&network_time, nullptr) != NETWORK_TIME_AVAILABLE) { | 644 if (GetNetworkTime(&network_time, nullptr) != NETWORK_TIME_AVAILABLE) { |
638 return true; | 645 return true; |
639 } | 646 } |
640 | 647 |
641 // Otherwise, make the decision at random. | 648 // Otherwise, make the decision at random. |
642 return base::RandDouble() < RandomQueryProbability(); | 649 return base::RandDouble() < RandomQueryProbability(); |
643 } | 650 } |
644 | 651 |
645 } // namespace network_time | 652 } // namespace network_time |
OLD | NEW |