#include "base/metrics/sparse_histogram.h"
#include "base/prefs/pref_registry_simple.h"
#include "base/prefs/pref_service.h"
+#include "base/sys_info.h"
#include "base/version.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/network_time/network_time_tracker.h"
}
-// Get current form factor and convert it from enum DeviceFormFactor to enum
+// Gets current form factor and converts it from enum DeviceFormFactor to enum
// Study_FormFactor.
Study_FormFactor GetCurrentFormFactor() {
switch (ui::GetDeviceFormFactor()) {
return Study_FormFactor_DESKTOP;
}
+// Gets the hardware class and returns it as a string. This returns an empty
+// string if the client is not ChromeOS.
+std::string GetHardwareClass() {
+#if defined(OS_CHROMEOS)
+ return base::SysInfo::GetLsbReleaseBoard();
+#endif // OS_CHROMEOS
+ return std::string();
+}
+
+// Returns the date that should be used by the VariationsSeedProcessor to do
+// expiry and start date checks.
+base::Time GetReferenceDateForExpiryChecks(PrefService* local_state) {
+ const int64 date_value = local_state->GetInt64(prefs::kVariationsSeedDate);
+ const base::Time seed_date = base::Time::FromInternalValue(date_value);
+ const base::Time build_time = base::GetBuildTime();
+ // Use the build time for date checks if either the seed date is invalid or
+ // the build time is newer than the seed date.
+ base::Time reference_date = seed_date;
+ if (seed_date.is_null() || seed_date < build_time)
+ reference_date = build_time;
+ return reference_date;
+}
+
} // namespace
VariationsService::VariationsService(PrefService* local_state)
if (!seed_store_.LoadSeed(&seed))
return false;
- const int64 date_value = local_state_->GetInt64(prefs::kVariationsSeedDate);
- const base::Time seed_date = base::Time::FromInternalValue(date_value);
- const base::Time build_time = base::GetBuildTime();
- // Use the build time for date checks if either the seed date is invalid or
- // the build time is newer than the seed date.
- base::Time reference_date = seed_date;
- if (seed_date.is_null() || seed_date < build_time)
- reference_date = build_time;
-
const chrome::VersionInfo current_version_info;
if (!current_version_info.is_valid())
return false;
return false;
VariationsSeedProcessor().CreateTrialsFromSeed(
- seed, g_browser_process->GetApplicationLocale(), reference_date,
- current_version, GetChannelForVariations(), GetCurrentFormFactor());
+ seed, g_browser_process->GetApplicationLocale(),
+ GetReferenceDateForExpiryChecks(local_state_), current_version,
+ GetChannelForVariations(), GetCurrentFormFactor(), GetHardwareClass());
// Log the "freshness" of the seed that was just used. The freshness is the
// time between the last successful seed download and now.
last_request_started_time_ = now;
}
+void VariationsService::StoreSeed(const std::string& seed_data,
+ const std::string& seed_signature,
+ const base::Time& date_fetched) {
+ if (!seed_store_.StoreSeedData(seed_data, seed_signature, date_fetched))
+ return;
+ RecordLastFetchTime();
+}
+
void VariationsService::FetchVariationsSeed() {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
DVLOG(1) << "Variations server request returned non-HTTP_OK response code: "
<< response_code;
if (response_code == net::HTTP_NOT_MODIFIED) {
- UMA_HISTOGRAM_MEDIUM_TIMES("Variations.FetchNotModifiedLatency", latency);
RecordLastFetchTime();
// Update the seed date value in local state (used for expiry check on
// next start up), since 304 is a successful response.
- local_state_->SetInt64(prefs::kVariationsSeedDate,
- response_date.ToInternalValue());
- } else {
- UMA_HISTOGRAM_MEDIUM_TIMES("Variations.FetchOtherLatency", latency);
+ seed_store_.UpdateSeedDateAndLogDayChange(response_date);
}
return;
}
- UMA_HISTOGRAM_MEDIUM_TIMES("Variations.FetchSuccessLatency", latency);
std::string seed_data;
bool success = request->GetResponseAsString(&seed_data);
request->GetResponseHeaders()->EnumerateHeader(NULL,
"X-Seed-Signature",
&seed_signature);
- if (seed_store_.StoreSeedData(seed_data, seed_signature, response_date))
- RecordLastFetchTime();
+ StoreSeed(seed_data, seed_signature, response_date);
}
void VariationsService::OnResourceRequestsAllowed() {