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

Side by Side Diff: components/network_time/network_time_tracker.cc

Issue 2366943003: Create NetworkTimeTracker on startup for users in Finch experiment (Closed)
Patch Set: fix base::Feature declaration Created 4 years, 2 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 unified diff | Download patch
OLDNEW
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
11 #include "base/feature_list.h"
12 #include "base/i18n/time_formatting.h" 11 #include "base/i18n/time_formatting.h"
13 #include "base/json/json_reader.h" 12 #include "base/json/json_reader.h"
14 #include "base/logging.h" 13 #include "base/logging.h"
15 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
16 #include "base/metrics/histogram_macros.h" 15 #include "base/metrics/histogram_macros.h"
17 #include "base/metrics/sparse_histogram.h" 16 #include "base/metrics/sparse_histogram.h"
18 #include "base/rand_util.h" 17 #include "base/rand_util.h"
19 #include "base/run_loop.h" 18 #include "base/run_loop.h"
20 #include "base/strings/string_number_conversions.h" 19 #include "base/strings/string_number_conversions.h"
21 #include "base/strings/utf_string_conversions.h" 20 #include "base/strings/utf_string_conversions.h"
22 #include "base/time/tick_clock.h" 21 #include "base/time/tick_clock.h"
23 #include "build/build_config.h" 22 #include "build/build_config.h"
24 #include "components/client_update_protocol/ecdsa.h" 23 #include "components/client_update_protocol/ecdsa.h"
25 #include "components/network_time/network_time_pref_names.h" 24 #include "components/network_time/network_time_pref_names.h"
26 #include "components/prefs/pref_registry_simple.h" 25 #include "components/prefs/pref_registry_simple.h"
27 #include "components/prefs/pref_service.h" 26 #include "components/prefs/pref_service.h"
28 #include "components/variations/variations_associated_data.h" 27 #include "components/variations/variations_associated_data.h"
29 #include "net/base/load_flags.h" 28 #include "net/base/load_flags.h"
30 #include "net/base/net_errors.h" 29 #include "net/base/net_errors.h"
31 #include "net/http/http_response_headers.h" 30 #include "net/http/http_response_headers.h"
32 #include "net/url_request/url_fetcher.h" 31 #include "net/url_request/url_fetcher.h"
33 #include "net/url_request/url_fetcher_response_writer.h" 32 #include "net/url_request/url_fetcher_response_writer.h"
34 #include "net/url_request/url_request_context_getter.h" 33 #include "net/url_request/url_request_context_getter.h"
35 34
36 namespace network_time { 35 namespace network_time {
37 36
37 const base::Feature kNetworkTimeServiceQuerying{
38 "NetworkTimeServiceQuerying", base::FEATURE_DISABLED_BY_DEFAULT};
39
38 namespace { 40 namespace {
39 41
40 // Time updates happen in two ways. First, other components may call 42 // Time updates happen in two ways. First, other components may call
41 // UpdateNetworkTime() if they happen to obtain the time securely. This will 43 // UpdateNetworkTime() if they happen to obtain the time securely. This will
42 // likely be deprecated in favor of the second way, which is scheduled time 44 // likely be deprecated in favor of the second way, which is scheduled time
43 // queries issued by NetworkTimeTracker itself. 45 // queries issued by NetworkTimeTracker itself.
44 // 46 //
45 // On startup, the clock state may be read from a pref. (This, too, may be 47 // On startup, the clock state may be read from a pref. (This, too, may be
46 // deprecated.) After that, the time is checked every 48 // deprecated.) After that, the time is checked every
47 // |kCheckTimeIntervalSeconds|. A "check" means the possibility, but not the 49 // |kCheckTimeIntervalSeconds|. A "check" means the possibility, but not the
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 const char kPrefNetworkTime[] = "network"; 90 const char kPrefNetworkTime[] = "network";
89 91
90 // Time server's maximum allowable clock skew, in seconds. (This is a property 92 // Time server's maximum allowable clock skew, in seconds. (This is a property
91 // of the time server that we happen to know. It's unlikely that it would ever 93 // of the time server that we happen to know. It's unlikely that it would ever
92 // be that badly wrong, but all the same it's included here to document the very 94 // be that badly wrong, but all the same it's included here to document the very
93 // rough nature of the time service provided by this class.) 95 // rough nature of the time service provided by this class.)
94 const uint32_t kTimeServerMaxSkewSeconds = 10; 96 const uint32_t kTimeServerMaxSkewSeconds = 10;
95 97
96 const char kTimeServiceURL[] = "http://clients2.google.com/time/1/current"; 98 const char kTimeServiceURL[] = "http://clients2.google.com/time/1/current";
97 99
98 // Variations Service feature that enables network time service querying.
99 const base::Feature kNetworkTimeServiceQuerying{
100 "NetworkTimeServiceQuerying", base::FEATURE_DISABLED_BY_DEFAULT};
101
102 const char kVariationsServiceCheckTimeIntervalSeconds[] = 100 const char kVariationsServiceCheckTimeIntervalSeconds[] =
103 "CheckTimeIntervalSeconds"; 101 "CheckTimeIntervalSeconds";
104 const char kVariationsServiceRandomQueryProbability[] = 102 const char kVariationsServiceRandomQueryProbability[] =
105 "RandomQueryProbability"; 103 "RandomQueryProbability";
106 104
107 // This is an ECDSA prime256v1 named-curve key. 105 // This is an ECDSA prime256v1 named-curve key.
108 const int kKeyVersion = 1; 106 const int kKeyVersion = 1;
109 const uint8_t kKeyPubBytes[] = { 107 const uint8_t kKeyPubBytes[] = {
110 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 108 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02,
111 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03, 109 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03,
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 base::Time network_time; 491 base::Time network_time;
494 if (GetNetworkTime(&network_time, nullptr) != NETWORK_TIME_AVAILABLE) { 492 if (GetNetworkTime(&network_time, nullptr) != NETWORK_TIME_AVAILABLE) {
495 return true; 493 return true;
496 } 494 }
497 495
498 // Otherwise, make the decision at random. 496 // Otherwise, make the decision at random.
499 return base::RandDouble() < RandomQueryProbability(); 497 return base::RandDouble() < RandomQueryProbability();
500 } 498 }
501 499
502 } // namespace network_time 500 } // namespace network_time
OLDNEW
« chrome/browser/browser_process_impl.cc ('K') | « components/network_time/network_time_tracker.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698