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

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

Issue 2902603002: Add enterprise policy for network time service (Closed)
Patch Set: shorten caption Created 3 years, 7 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
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 void RecordFetchValidHistogram(bool valid) { 184 void RecordFetchValidHistogram(bool valid) {
185 UMA_HISTOGRAM_BOOLEAN("NetworkTimeTracker.UpdateTimeFetchValid", valid); 185 UMA_HISTOGRAM_BOOLEAN("NetworkTimeTracker.UpdateTimeFetchValid", valid);
186 } 186 }
187 187
188 } // namespace 188 } // namespace
189 189
190 // static 190 // static
191 void NetworkTimeTracker::RegisterPrefs(PrefRegistrySimple* registry) { 191 void NetworkTimeTracker::RegisterPrefs(PrefRegistrySimple* registry) {
192 registry->RegisterDictionaryPref(prefs::kNetworkTimeMapping, 192 registry->RegisterDictionaryPref(prefs::kNetworkTimeMapping,
193 base::MakeUnique<base::DictionaryValue>()); 193 base::MakeUnique<base::DictionaryValue>());
194 registry->RegisterBooleanPref(prefs::kNetworkTimeQueriesEnabled, true);
194 } 195 }
195 196
196 NetworkTimeTracker::NetworkTimeTracker( 197 NetworkTimeTracker::NetworkTimeTracker(
197 std::unique_ptr<base::Clock> clock, 198 std::unique_ptr<base::Clock> clock,
198 std::unique_ptr<base::TickClock> tick_clock, 199 std::unique_ptr<base::TickClock> tick_clock,
199 PrefService* pref_service, 200 PrefService* pref_service,
200 scoped_refptr<net::URLRequestContextGetter> getter) 201 scoped_refptr<net::URLRequestContextGetter> getter)
201 : server_url_(kTimeServiceURL), 202 : server_url_(kTimeServiceURL),
202 max_response_size_(1024), 203 max_response_size_(1024),
203 backoff_(base::TimeDelta::FromMinutes(kBackoffMinutes)), 204 backoff_(base::TimeDelta::FromMinutes(kBackoffMinutes)),
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 trigger: 472 trigger:
472 "A request can be sent to retrieve the current time when the user " 473 "A request can be sent to retrieve the current time when the user "
473 "encounters an SSL date error, or in the background if Chromium " 474 "encounters an SSL date error, or in the background if Chromium "
474 "determines that it doesn't have an accurate timestamp." 475 "determines that it doesn't have an accurate timestamp."
475 data: "None" 476 data: "None"
476 destination: GOOGLE_OWNED_SERVICE 477 destination: GOOGLE_OWNED_SERVICE
477 } 478 }
478 policy { 479 policy {
479 cookies_allowed: false 480 cookies_allowed: false
480 setting: "This feature cannot be disabled by settings." 481 setting: "This feature cannot be disabled by settings."
481 policy_exception_justification: "Not implemented." 482 chrome_policy {
483 NetworkTimeQueriesEnabled {
484 NetworkTimeQueriesEnabled: false
485 }
486 }
482 })"); 487 })");
483 // This cancels any outstanding fetch. 488 // This cancels any outstanding fetch.
484 time_fetcher_ = net::URLFetcher::Create(url, net::URLFetcher::GET, this, 489 time_fetcher_ = net::URLFetcher::Create(url, net::URLFetcher::GET, this,
485 traffic_annotation); 490 traffic_annotation);
486 if (!time_fetcher_) { 491 if (!time_fetcher_) {
487 DVLOG(1) << "tried to make fetch happen; failed"; 492 DVLOG(1) << "tried to make fetch happen; failed";
488 return; 493 return;
489 } 494 }
490 data_use_measurement::DataUseUserData::AttachToFetcher( 495 data_use_measurement::DataUseUserData::AttachToFetcher(
491 time_fetcher_.get(), 496 time_fetcher_.get(),
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 timer_.Start(FROM_HERE, delay, this, &NetworkTimeTracker::CheckTime); 619 timer_.Start(FROM_HERE, delay, this, &NetworkTimeTracker::CheckTime);
615 } 620 }
616 } 621 }
617 622
618 bool NetworkTimeTracker::ShouldIssueTimeQuery() { 623 bool NetworkTimeTracker::ShouldIssueTimeQuery() {
619 // Do not query the time service if not enabled via Variations Service. 624 // Do not query the time service if not enabled via Variations Service.
620 if (!AreTimeFetchesEnabled()) { 625 if (!AreTimeFetchesEnabled()) {
621 return false; 626 return false;
622 } 627 }
623 628
629 // Do not query the time service if queries are disabled by policy.
630 if (!pref_service_->GetBoolean(prefs::kNetworkTimeQueriesEnabled)) {
631 return false;
632 }
633
624 // If GetNetworkTime() does not return NETWORK_TIME_AVAILABLE, 634 // If GetNetworkTime() does not return NETWORK_TIME_AVAILABLE,
625 // synchronization has been lost and a query is needed. 635 // synchronization has been lost and a query is needed.
626 base::Time network_time; 636 base::Time network_time;
627 if (GetNetworkTime(&network_time, nullptr) != NETWORK_TIME_AVAILABLE) { 637 if (GetNetworkTime(&network_time, nullptr) != NETWORK_TIME_AVAILABLE) {
628 return true; 638 return true;
629 } 639 }
630 640
631 // Otherwise, make the decision at random. 641 // Otherwise, make the decision at random.
632 return base::RandDouble() < RandomQueryProbability(); 642 return base::RandDouble() < RandomQueryProbability();
633 } 643 }
634 644
635 } // namespace network_time 645 } // namespace network_time
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698