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

Side by Side Diff: chrome/browser/metrics/variations_service.cc

Issue 10343007: Retrieving Chrome Variations seed from server and storing in local prefs. Loading seed data from lo… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/metrics/variations_service.h"
6
7 #include "base/base64.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "base/memory/singleton.h"
SteveT 2012/05/03 04:02:52 Is this used here?
jwd 2012/05/03 22:27:49 Oops, no, not any more. Fixed On 2012/05/03 04:02:
10 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/metrics/proto/trials_seed.pb.h"
12 #include "chrome/browser/prefs/pref_service.h"
13 #include "chrome/common/pref_names.h"
14 #include "content/public/common/url_fetcher.h"
15 #include "googleurl/src/gurl.h"
16 #include "net/base/escape.h"
SteveT 2012/05/03 04:02:52 Is this used here?
jwd 2012/05/03 22:27:49 "Oh god how did this get in here I am not good wit
17 #include "net/base/load_flags.h"
18 #include "net/url_request/url_request_status.h"
19
20 const char* VariationsService::kDefaultVariationsServer =
21 "https://clients4.google.com/chrome-variations/seed";
22
23 void VariationsService::LoadVariationsSeed(PrefService* local_prefs) {
24 std::string base64_seed_data = local_prefs->GetString(prefs::kVariationsSeed);
25 std::string seed_data;
26 base::Base64Decode(base64_seed_data, &seed_data);
SteveT 2012/05/03 04:02:52 What if this fails?
jwd 2012/05/03 22:27:49 I've decided to clear the pref if either this or t
27 variations_seed_.ParseFromString(seed_data);
28 }
29
30 void VariationsService::FetchVariationsSeed() {
31 seed_request_pending_.reset(content::URLFetcher::Create(
32 GURL(kDefaultVariationsServer), content::URLFetcher::GET, this));
33 seed_request_pending_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES |
34 net::LOAD_DO_NOT_SAVE_COOKIES);
35 seed_request_pending_->SetRequestContext(
36 g_browser_process->system_request_context());
37 seed_request_pending_->SetMaxRetries(5);
38 seed_request_pending_->Start();
39 }
40
41 void VariationsService::OnURLFetchComplete(const content::URLFetcher* source) {
42 bool error =
43 (source->GetStatus().status() != net::URLRequestStatus::SUCCESS ||
44 source->GetResponseCode() != 200);
Ilya Sherman 2012/05/02 23:15:08 nit: No need to cache this in a variable name, as
jwd 2012/05/03 22:27:49 Done.
45 scoped_ptr<const content::URLFetcher> delete_ptr(
46 seed_request_pending_.release());
Ilya Sherman 2012/05/02 23:15:08 nit: Please add a comment explaining why we cannot
jwd 2012/05/03 22:27:49 Ok, I've made this clearer. I have one question ab
47 if (error) {
Ilya Sherman 2012/05/02 23:15:08 nit: You can add an early "return;" stmt here, and
jwd 2012/05/03 22:27:49 Done.
48 } else {
49 std::string seed_data;
50 source->GetResponseAsString(&seed_data);
51
52 StoreSeedData(seed_data, g_browser_process->local_state());
53 }
54 }
55
56 void VariationsService::StoreSeedData(
SteveT 2012/05/03 04:02:52 hyper nit: if "std::string seed_data," fits on thi
jwd 2012/05/03 22:27:49 Done.
57 std::string seed_data, PrefService* local_prefs) {
58 // Only store the seed data if it parses correctly
SteveT 2012/05/03 04:02:52 ultra nit: correctly -> correctly.
jwd 2012/05/03 22:27:49 Done.
59 chrome_variations::TrialsSeed seed;
60 if (seed.ParseFromString(seed_data)){
61 std::string base64_seed_data;
62 if (!base::Base64Encode(seed_data, &base64_seed_data)) {
SteveT 2012/05/03 04:02:52 nit: braces not needed for a single statement if b
jwd 2012/05/03 22:27:49 Done.
63 return;
64 }
65 local_prefs->SetString(prefs::kVariationsSeed, base64_seed_data);
66 }
67 }
SteveT 2012/05/03 04:02:52 Break here.
jwd 2012/05/03 22:27:49 Done.
68 // static
69 void VariationsService::RegisterPrefs(PrefService* prefs) {
70 prefs->RegisterStringPref(prefs::kVariationsSeed, std::string());
71 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698