Support serial number requests in variations service.

BUG=140073
TEST=manual using inserted logging

Review URL: https://chromiumcodereview.appspot.com/10828106

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@149979 0039d316-1c4b-4281-b951-d872f2087c98
parent efa950d0
...@@ -98,12 +98,15 @@ GURL GetVariationsServerURL() { ...@@ -98,12 +98,15 @@ GURL GetVariationsServerURL() {
} // namespace } // namespace
VariationsService::VariationsService() VariationsService::VariationsService()
: variations_server_url_(GetVariationsServerURL()) { : variations_server_url_(GetVariationsServerURL()),
create_trials_from_seed_called_(false) {
} }
VariationsService::~VariationsService() {} VariationsService::~VariationsService() {}
bool VariationsService::CreateTrialsFromSeed(PrefService* local_prefs) { bool VariationsService::CreateTrialsFromSeed(PrefService* local_prefs) {
create_trials_from_seed_called_ = true;
TrialsSeed seed; TrialsSeed seed;
if (!LoadTrialsSeedFromPref(local_prefs, &seed)) if (!LoadTrialsSeedFromPref(local_prefs, &seed))
return false; return false;
...@@ -132,6 +135,10 @@ bool VariationsService::CreateTrialsFromSeed(PrefService* local_prefs) { ...@@ -132,6 +135,10 @@ bool VariationsService::CreateTrialsFromSeed(PrefService* local_prefs) {
void VariationsService::StartRepeatedVariationsSeedFetch() { void VariationsService::StartRepeatedVariationsSeedFetch() {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
// Check that |CreateTrialsFromSeed| was called, which is necessary to
// retrieve the serial number that will be sent to the server.
DCHECK(create_trials_from_seed_called_);
// Perform the first fetch. // Perform the first fetch.
FetchVariationsSeed(); FetchVariationsSeed();
...@@ -157,6 +164,10 @@ void VariationsService::FetchVariationsSeed() { ...@@ -157,6 +164,10 @@ void VariationsService::FetchVariationsSeed() {
pending_seed_request_->SetRequestContext( pending_seed_request_->SetRequestContext(
g_browser_process->system_request_context()); g_browser_process->system_request_context());
pending_seed_request_->SetMaxRetries(kMaxRetrySeedFetch); pending_seed_request_->SetMaxRetries(kMaxRetrySeedFetch);
if (!variations_serial_number_.empty()) {
pending_seed_request_->AddExtraRequestHeader("If-Match:" +
variations_serial_number_);
}
pending_seed_request_->Start(); pending_seed_request_->Start();
} }
...@@ -169,9 +180,10 @@ void VariationsService::OnURLFetchComplete(const net::URLFetcher* source) { ...@@ -169,9 +180,10 @@ void VariationsService::OnURLFetchComplete(const net::URLFetcher* source) {
DVLOG(1) << "Variations server request failed."; DVLOG(1) << "Variations server request failed.";
return; return;
} }
if (request->GetResponseCode() != 200) { if (request->GetResponseCode() != 200) {
DVLOG(1) << "Variations server request returned non-200 response code: " DVLOG(1) << "Variations server request returned non-200 response code: "
<< request->GetResponseCode(); << request->GetResponseCode();
return; return;
} }
...@@ -214,6 +226,7 @@ bool VariationsService::StoreSeedData(const std::string& seed_data, ...@@ -214,6 +226,7 @@ bool VariationsService::StoreSeedData(const std::string& seed_data,
local_prefs->SetString(prefs::kVariationsSeed, base64_seed_data); local_prefs->SetString(prefs::kVariationsSeed, base64_seed_data);
local_prefs->SetInt64(prefs::kVariationsSeedDate, local_prefs->SetInt64(prefs::kVariationsSeedDate,
seed_date.ToInternalValue()); seed_date.ToInternalValue());
variations_serial_number_ = seed.serial_number();
return true; return true;
} }
...@@ -415,6 +428,7 @@ bool VariationsService::LoadTrialsSeedFromPref(PrefService* local_prefs, ...@@ -415,6 +428,7 @@ bool VariationsService::LoadTrialsSeedFromPref(PrefService* local_prefs,
local_prefs->ClearPref(prefs::kVariationsSeed); local_prefs->ClearPref(prefs::kVariationsSeed);
return false; return false;
} }
variations_serial_number_ = seed->serial_number();
return true; return true;
} }
......
...@@ -40,7 +40,8 @@ class VariationsService : public net::URLFetcherDelegate { ...@@ -40,7 +40,8 @@ class VariationsService : public net::URLFetcherDelegate {
bool CreateTrialsFromSeed(PrefService* local_prefs); bool CreateTrialsFromSeed(PrefService* local_prefs);
// Calls FetchVariationsSeed once and repeats this periodically. See // Calls FetchVariationsSeed once and repeats this periodically. See
// implementation for details on the period. // implementation for details on the period. Must be called after
// |CreateTrialsFromSeed|.
void StartRepeatedVariationsSeedFetch(); void StartRepeatedVariationsSeedFetch();
// Starts the fetching process once, where |OnURLFetchComplete| is called with // Starts the fetching process once, where |OnURLFetchComplete| is called with
...@@ -127,9 +128,16 @@ class VariationsService : public net::URLFetcherDelegate { ...@@ -127,9 +128,16 @@ class VariationsService : public net::URLFetcherDelegate {
// The URL to use for querying the variations server. // The URL to use for querying the variations server.
GURL variations_server_url_; GURL variations_server_url_;
// Cached serial number from the most recently fetched variations seed.
std::string variations_serial_number_;
// Tracks whether |CreateTrialsFromSeed| has been called, to ensure that
// it gets called prior to |StartRepeatedVariationsSeedFetch|.
bool create_trials_from_seed_called_;
// The timer used to repeatedly ping the server. Keep this as an instance // The timer used to repeatedly ping the server. Keep this as an instance
// member so if VariationsService goes out of scope, the timer is // member so if VariationsService goes out of scope, the timer is
// automatically cancelled. // automatically canceled.
base::RepeatingTimer<VariationsService> timer_; base::RepeatingTimer<VariationsService> timer_;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment