OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/variations/service/variations_service.h" | 5 #include "components/variations/service/variations_service.h" |
6 | 6 |
| 7 #include <stddef.h> |
| 8 #include <stdint.h> |
| 9 |
7 #include "base/build_time.h" | 10 #include "base/build_time.h" |
8 #include "base/command_line.h" | 11 #include "base/command_line.h" |
9 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
10 #include "base/metrics/sparse_histogram.h" | 13 #include "base/metrics/sparse_histogram.h" |
11 #include "base/prefs/pref_registry_simple.h" | 14 #include "base/prefs/pref_registry_simple.h" |
12 #include "base/prefs/pref_service.h" | 15 #include "base/prefs/pref_service.h" |
13 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
14 #include "base/sys_info.h" | 17 #include "base/sys_info.h" |
15 #include "base/task_runner_util.h" | 18 #include "base/task_runner_util.h" |
16 #include "base/timer/elapsed_timer.h" | 19 #include "base/timer/elapsed_timer.h" |
17 #include "base/values.h" | 20 #include "base/values.h" |
18 #include "base/version.h" | 21 #include "base/version.h" |
| 22 #include "build/build_config.h" |
19 #include "components/data_use_measurement/core/data_use_user_data.h" | 23 #include "components/data_use_measurement/core/data_use_user_data.h" |
20 #include "components/metrics/metrics_state_manager.h" | 24 #include "components/metrics/metrics_state_manager.h" |
21 #include "components/network_time/network_time_tracker.h" | 25 #include "components/network_time/network_time_tracker.h" |
22 #include "components/pref_registry/pref_registry_syncable.h" | 26 #include "components/pref_registry/pref_registry_syncable.h" |
23 #include "components/variations/pref_names.h" | 27 #include "components/variations/pref_names.h" |
24 #include "components/variations/proto/variations_seed.pb.h" | 28 #include "components/variations/proto/variations_seed.pb.h" |
25 #include "components/variations/variations_seed_processor.h" | 29 #include "components/variations/variations_seed_processor.h" |
26 #include "components/variations/variations_seed_simulator.h" | 30 #include "components/variations/variations_seed_simulator.h" |
27 #include "components/variations/variations_switches.h" | 31 #include "components/variations/variations_switches.h" |
28 #include "components/variations/variations_url_constants.h" | 32 #include "components/variations/variations_url_constants.h" |
(...skipping 11 matching lines...) Expand all Loading... |
40 #include "url/gurl.h" | 44 #include "url/gurl.h" |
41 | 45 |
42 namespace variations { | 46 namespace variations { |
43 | 47 |
44 namespace { | 48 namespace { |
45 | 49 |
46 const int kMaxRetrySeedFetch = 5; | 50 const int kMaxRetrySeedFetch = 5; |
47 | 51 |
48 // TODO(mad): To be removed when we stop updating the NetworkTimeTracker. | 52 // TODO(mad): To be removed when we stop updating the NetworkTimeTracker. |
49 // For the HTTP date headers, the resolution of the server time is 1 second. | 53 // For the HTTP date headers, the resolution of the server time is 1 second. |
50 const int64 kServerTimeResolutionMs = 1000; | 54 const int64_t kServerTimeResolutionMs = 1000; |
51 | 55 |
52 // Maximum age permitted for a variations seed, in days. | 56 // Maximum age permitted for a variations seed, in days. |
53 const int kMaxVariationsSeedAgeDays = 30; | 57 const int kMaxVariationsSeedAgeDays = 30; |
54 | 58 |
55 // Wrapper around channel checking, used to enable channel mocking for | 59 // Wrapper around channel checking, used to enable channel mocking for |
56 // testing. If the current browser channel is not UNKNOWN, this will return | 60 // testing. If the current browser channel is not UNKNOWN, this will return |
57 // that channel value. Otherwise, if the fake channel flag is provided, this | 61 // that channel value. Otherwise, if the fake channel flag is provided, this |
58 // will return the fake channel. Failing that, this will return the UNKNOWN | 62 // will return the fake channel. Failing that, this will return the UNKNOWN |
59 // channel. | 63 // channel. |
60 variations::Study_Channel GetChannelForVariations( | 64 variations::Study_Channel GetChannelForVariations( |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 std::string GetHardwareClass() { | 192 std::string GetHardwareClass() { |
189 #if defined(OS_CHROMEOS) | 193 #if defined(OS_CHROMEOS) |
190 return base::SysInfo::GetLsbReleaseBoard(); | 194 return base::SysInfo::GetLsbReleaseBoard(); |
191 #endif // OS_CHROMEOS | 195 #endif // OS_CHROMEOS |
192 return std::string(); | 196 return std::string(); |
193 } | 197 } |
194 | 198 |
195 // Returns the date that should be used by the VariationsSeedProcessor to do | 199 // Returns the date that should be used by the VariationsSeedProcessor to do |
196 // expiry and start date checks. | 200 // expiry and start date checks. |
197 base::Time GetReferenceDateForExpiryChecks(PrefService* local_state) { | 201 base::Time GetReferenceDateForExpiryChecks(PrefService* local_state) { |
198 const int64 date_value = local_state->GetInt64(prefs::kVariationsSeedDate); | 202 const int64_t date_value = local_state->GetInt64(prefs::kVariationsSeedDate); |
199 const base::Time seed_date = base::Time::FromInternalValue(date_value); | 203 const base::Time seed_date = base::Time::FromInternalValue(date_value); |
200 const base::Time build_time = base::GetBuildTime(); | 204 const base::Time build_time = base::GetBuildTime(); |
201 // Use the build time for date checks if either the seed date is invalid or | 205 // Use the build time for date checks if either the seed date is invalid or |
202 // the build time is newer than the seed date. | 206 // the build time is newer than the seed date. |
203 base::Time reference_date = seed_date; | 207 base::Time reference_date = seed_date; |
204 if (seed_date.is_null() || seed_date < build_time) | 208 if (seed_date.is_null() || seed_date < build_time) |
205 reference_date = build_time; | 209 reference_date = build_time; |
206 return reference_date; | 210 return reference_date; |
207 } | 211 } |
208 | 212 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 | 299 |
296 bool VariationsService::CreateTrialsFromSeed(base::FeatureList* feature_list) { | 300 bool VariationsService::CreateTrialsFromSeed(base::FeatureList* feature_list) { |
297 DCHECK(thread_checker_.CalledOnValidThread()); | 301 DCHECK(thread_checker_.CalledOnValidThread()); |
298 | 302 |
299 create_trials_from_seed_called_ = true; | 303 create_trials_from_seed_called_ = true; |
300 | 304 |
301 variations::VariationsSeed seed; | 305 variations::VariationsSeed seed; |
302 if (!LoadSeed(&seed)) | 306 if (!LoadSeed(&seed)) |
303 return false; | 307 return false; |
304 | 308 |
305 const int64 last_fetch_time_internal = | 309 const int64_t last_fetch_time_internal = |
306 local_state_->GetInt64(prefs::kVariationsLastFetchTime); | 310 local_state_->GetInt64(prefs::kVariationsLastFetchTime); |
307 const base::Time last_fetch_time = | 311 const base::Time last_fetch_time = |
308 base::Time::FromInternalValue(last_fetch_time_internal); | 312 base::Time::FromInternalValue(last_fetch_time_internal); |
309 if (last_fetch_time.is_null()) { | 313 if (last_fetch_time.is_null()) { |
310 // If the last fetch time is missing and we have a seed, then this must be | 314 // If the last fetch time is missing and we have a seed, then this must be |
311 // the first run of Chrome. Store the current time as the last fetch time. | 315 // the first run of Chrome. Store the current time as the last fetch time. |
312 RecordLastFetchTime(); | 316 RecordLastFetchTime(); |
313 RecordCreateTrialsSeedExpiry(VARIATIONS_SEED_EXPIRY_FETCH_TIME_MISSING); | 317 RecordCreateTrialsSeedExpiry(VARIATIONS_SEED_EXPIRY_FETCH_TIME_MISSING); |
314 } else { | 318 } else { |
315 // Reject the seed if it is more than 30 days old. | 319 // Reject the seed if it is more than 30 days old. |
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
853 std::string stored_country; | 857 std::string stored_country; |
854 | 858 |
855 if (list_value->GetSize() == 2) { | 859 if (list_value->GetSize() == 2) { |
856 list_value->GetString(1, &stored_country); | 860 list_value->GetString(1, &stored_country); |
857 } | 861 } |
858 | 862 |
859 return stored_country; | 863 return stored_country; |
860 } | 864 } |
861 | 865 |
862 } // namespace variations | 866 } // namespace variations |
OLD | NEW |