Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(245)

Unified Diff: chrome/browser/metrics/variations_service.cc

Issue 10790116: Have the VariationsService attempt to fetch the seed when an update is ready. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Unit test Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/metrics/variations_service.cc
diff --git a/chrome/browser/metrics/variations_service.cc b/chrome/browser/metrics/variations_service.cc
index 5ee2ee13fa8ec28026d9dd672fb2121520cf63ea..a487c1971067f7f6df81f009a59cb6d71fea3f7f 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"
@@ -99,6 +101,8 @@ GURL GetVariationsServerURL() {
VariationsService::VariationsService()
: variations_server_url_(GetVariationsServerURL()) {
+ registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED,
+ content::NotificationService::AllSources());
}
VariationsService::~VariationsService() {}
@@ -140,6 +144,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));
@@ -160,6 +171,21 @@ 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);
Alexei Svitkine (slow) 2012/07/23 20:26:05 Nit: Add a blank line after this.
SteveT 2012/07/24 14:42:58 Done.
+ // An upgrade is ready, so attempt to fetch the Variations seed in case there
+ // 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.
@@ -186,13 +212,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) {

Powered by Google App Engine
This is Rietveld 408576698