Chromium Code Reviews| Index: chrome/browser/metrics/variations_service.cc |
| diff --git a/chrome/browser/metrics/variations_service.cc b/chrome/browser/metrics/variations_service.cc |
| index cd60a26d318b328bd8c1ff9a804288be28bf3e7c..ee9799460e658454cc7972b5d94cadd1d8dc0d9a 100644 |
| --- a/chrome/browser/metrics/variations_service.cc |
| +++ b/chrome/browser/metrics/variations_service.cc |
| @@ -16,10 +16,12 @@ |
| #include "chrome/browser/browser_process.h" |
| #include "chrome/browser/metrics/proto/trials_seed.pb.h" |
| #include "chrome/browser/prefs/pref_service.h" |
| +#include "chrome/common/chrome_notification_types.h" |
| #include "chrome/common/chrome_switches.h" |
| #include "chrome/common/metrics/experiments_helper.h" |
| #include "chrome/common/pref_names.h" |
| #include "content/public/browser/browser_thread.h" |
| +#include "content/public/browser/notification_service.h" |
| #include "content/public/common/url_fetcher.h" |
| #include "googleurl/src/gurl.h" |
| #include "net/base/load_flags.h" |
| @@ -100,6 +102,8 @@ GURL GetVariationsServerURL() { |
| VariationsService::VariationsService() |
| : variations_server_url_(GetVariationsServerURL()), |
| create_trials_from_seed_called_(false) { |
| + registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED, |
| + content::NotificationService::AllSources()); |
|
Ilya Sherman
2012/08/07 20:31:51
NotificationService::AllSources() is generally dis
SteveT
2012/08/08 18:11:39
This is an UpgradeDetector, which conveniently is
Ilya Sherman
2012/08/08 21:33:47
Lovely :)
|
| } |
| VariationsService::~VariationsService() {} |
| @@ -147,6 +151,13 @@ void VariationsService::StartRepeatedVariationsSeedFetch() { |
| this, &VariationsService::FetchVariationsSeed); |
| } |
| +// static |
| +void VariationsService::RegisterPrefs(PrefService* prefs) { |
| + prefs->RegisterStringPref(prefs::kVariationsSeed, std::string()); |
| + prefs->RegisterInt64Pref(prefs::kVariationsSeedDate, |
| + base::Time().ToInternalValue()); |
| +} |
| + |
| void VariationsService::FetchVariationsSeed() { |
| DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| @@ -171,6 +182,22 @@ void VariationsService::FetchVariationsSeed() { |
| pending_seed_request_->Start(); |
| } |
| +void VariationsService::Observe(int type, |
| + const content::NotificationSource& source, |
| + const content::NotificationDetails& details) { |
| + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| + DCHECK(type == chrome::NOTIFICATION_UPGRADE_RECOMMENDED); |
|
Ilya Sherman
2012/08/07 20:31:51
nit: DCHECK_EQ(chrome::NOTIFICATION_UPGRADE_RECOMM
SteveT
2012/08/08 18:11:39
Done.
|
| + |
| + // An upgrade is ready, so attempt to fetch the Variations seed in case there |
|
Ilya Sherman
2012/08/07 20:31:51
Out of curiosity, when do we capitalize jargon lik
SteveT
2012/08/08 18:11:39
Hm, good question. I think in this file we're sort
Ilya Sherman
2012/08/08 21:33:47
Nope, was just curious. Thanks :)
|
| + // were updates. |
| + FetchVariationsSeed(); |
| + |
| + // Since we explicitly call FetchVariationsSeed here, we can reset the timer |
| + // so that we don't retry for another full period. |
| + if (timer_.IsRunning()) |
| + timer_.Reset(); |
| +} |
| + |
| void VariationsService::OnURLFetchComplete(const net::URLFetcher* source) { |
| DCHECK_EQ(pending_seed_request_.get(), source); |
| // When we're done handling the request, the fetcher will be deleted. |
| @@ -198,13 +225,6 @@ void VariationsService::OnURLFetchComplete(const net::URLFetcher* source) { |
| StoreSeedData(seed_data, response_date, g_browser_process->local_state()); |
| } |
| -// static |
| -void VariationsService::RegisterPrefs(PrefService* prefs) { |
| - prefs->RegisterStringPref(prefs::kVariationsSeed, std::string()); |
| - prefs->RegisterInt64Pref(prefs::kVariationsSeedDate, |
| - base::Time().ToInternalValue()); |
| -} |
| - |
| bool VariationsService::StoreSeedData(const std::string& seed_data, |
| const base::Time& seed_date, |
| PrefService* local_prefs) { |