1 // Copyright 2017 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "net/reporting/reporting_policy.h" 6 7 #include "base/no_destructor.h" 8 #include "base/time/time.h" 9 10 namespace net { 11 12 namespace { 13 14 ReportingPolicy* policy_for_testing = nullptr; 15 16 } // namespace 17 18 // static Create()19std::unique_ptr<ReportingPolicy> ReportingPolicy::Create() { 20 if (policy_for_testing != nullptr) { 21 return std::make_unique<ReportingPolicy>(*policy_for_testing); 22 } 23 return std::make_unique<ReportingPolicy>(); 24 } 25 26 // static UsePolicyForTesting(const ReportingPolicy & policy)27void ReportingPolicy::UsePolicyForTesting(const ReportingPolicy& policy) { 28 static base::NoDestructor<ReportingPolicy> owned_policy; 29 policy_for_testing = owned_policy.get(); 30 *owned_policy = policy; 31 } 32 ReportingPolicy()33ReportingPolicy::ReportingPolicy() { 34 endpoint_backoff_policy.num_errors_to_ignore = 0; 35 endpoint_backoff_policy.initial_delay_ms = 60 * 1000; // 1 minute 36 endpoint_backoff_policy.multiply_factor = 2.0; 37 endpoint_backoff_policy.jitter_factor = 0.1; 38 endpoint_backoff_policy.maximum_backoff_ms = -1; // 1 hour 39 endpoint_backoff_policy.entry_lifetime_ms = -1; // infinite 40 endpoint_backoff_policy.always_use_initial_delay = false; 41 } 42 43 ReportingPolicy::ReportingPolicy(const ReportingPolicy& other) = default; 44 45 ReportingPolicy::~ReportingPolicy() = default; 46 47 } // namespace net 48