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

Side by Side Diff: chrome/browser/android/ntp/popular_sites.cc

Issue 1930413002: Pull g_browser_process out of PopularSites. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/android/ntp/popular_sites.h" 5 #include "chrome/browser/android/ntp/popular_sites.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/files/file_util.h" 12 #include "base/files/file_util.h"
13 #include "base/json/json_reader.h" 13 #include "base/json/json_reader.h"
14 #include "base/path_service.h" 14 #include "base/path_service.h"
15 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
16 #include "base/strings/stringprintf.h" 16 #include "base/strings/stringprintf.h"
17 #include "base/task_runner_util.h" 17 #include "base/task_runner_util.h"
18 #include "base/time/time.h" 18 #include "base/time/time.h"
19 #include "base/values.h" 19 #include "base/values.h"
20 #include "chrome/browser/browser_process.h"
21 #include "chrome/common/chrome_paths.h" 20 #include "chrome/common/chrome_paths.h"
22 #include "components/google/core/browser/google_util.h" 21 #include "components/google/core/browser/google_util.h"
23 #include "components/ntp_tiles/switches.h" 22 #include "components/ntp_tiles/switches.h"
24 #include "components/pref_registry/pref_registry_syncable.h" 23 #include "components/pref_registry/pref_registry_syncable.h"
25 #include "components/prefs/pref_service.h" 24 #include "components/prefs/pref_service.h"
26 #include "components/search_engines/search_engine_type.h" 25 #include "components/search_engines/search_engine_type.h"
27 #include "components/search_engines/template_url_prepopulate_data.h" 26 #include "components/search_engines/template_url_prepopulate_data.h"
28 #include "components/search_engines/template_url_service.h" 27 #include "components/search_engines/template_url_service.h"
29 #include "components/variations/service/variations_service.h" 28 #include "components/variations/service/variations_service.h"
30 #include "content/public/browser/browser_thread.h" 29 #include "content/public/browser/browser_thread.h"
31 30
32 using content::BrowserThread; 31 using content::BrowserThread;
32 using variations::VariationsService;
33 33
34 namespace { 34 namespace {
35 35
36 const char kPopularSitesURLFormat[] = 36 const char kPopularSitesURLFormat[] =
37 "https://www.gstatic.com/chrome/ntp/suggested_sites_%s_%s.json"; 37 "https://www.gstatic.com/chrome/ntp/suggested_sites_%s_%s.json";
38 const char kPopularSitesDefaultCountryCode[] = "DEFAULT"; 38 const char kPopularSitesDefaultCountryCode[] = "DEFAULT";
39 const char kPopularSitesDefaultVersion[] = "5"; 39 const char kPopularSitesDefaultVersion[] = "5";
40 const char kPopularSitesLocalFilename[] = "suggested_sites.json"; 40 const char kPopularSitesLocalFilename[] = "suggested_sites.json";
41 const int kPopularSitesRedownloadIntervalHours = 24; 41 const int kPopularSitesRedownloadIntervalHours = 24;
42 42
(...skipping 25 matching lines...) Expand all
68 if (is_google_search_engine) { 68 if (is_google_search_engine) {
69 GURL search_url = default_provider->GenerateSearchURL( 69 GURL search_url = default_provider->GenerateSearchURL(
70 template_url_service->search_terms_data()); 70 template_url_service->search_terms_data());
71 return google_util::GetGoogleCountryCode(search_url); 71 return google_util::GetGoogleCountryCode(search_url);
72 } 72 }
73 } 73 }
74 74
75 return std::string(); 75 return std::string();
76 } 76 }
77 77
78 // Get the country that the experiment is running under
79 std::string GetVariationsServiceCountry() {
80 DCHECK(g_browser_process);
81 variations::VariationsService* variations_service =
82 g_browser_process->variations_service();
83 if (variations_service)
84 return variations_service->GetStoredPermanentCountry();
85 return std::string();
86 }
87
88 // Find out the country code of the user by using the Google country code if 78 // Find out the country code of the user by using the Google country code if
89 // Google is the default search engine set. If Google is not the default search 79 // Google is the default search engine set. If Google is not the default search
90 // engine use the country provided by VariationsService. Fallback to a default 80 // engine use the country provided by VariationsService. Fallback to a default
91 // if we can't make an educated guess. 81 // if we can't make an educated guess.
92 std::string GetCountryToUse(const TemplateURLService* template_url_service, 82 std::string GetCountryToUse(const TemplateURLService* template_url_service,
83 VariationsService* variations_service,
93 const std::string& override_country) { 84 const std::string& override_country) {
94 if (!override_country.empty()) 85 if (!override_country.empty())
95 return override_country; 86 return override_country;
96 87
97 std::string country_code = GetDefaultSearchEngineCountryCode( 88 std::string country_code = GetDefaultSearchEngineCountryCode(
98 template_url_service); 89 template_url_service);
99 90
100 if (country_code.empty()) 91 // Get the country that the experiment is running under
101 country_code = GetVariationsServiceCountry(); 92 if (country_code.empty() && variations_service)
93 country_code = variations_service->GetStoredPermanentCountry();
102 94
103 if (country_code.empty()) 95 if (country_code.empty())
104 country_code = kPopularSitesDefaultCountryCode; 96 country_code = kPopularSitesDefaultCountryCode;
105 97
106 return base::ToUpperASCII(country_code); 98 return base::ToUpperASCII(country_code);
107 } 99 }
108 100
109 std::string GetVersionToUse(const std::string& override_version) { 101 std::string GetVersionToUse(const std::string& override_version) {
110 if (!override_version.empty()) 102 if (!override_version.empty())
111 return override_version; 103 return override_version;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 favicon_url(favicon_url), 163 favicon_url(favicon_url),
172 large_icon_url(large_icon_url), 164 large_icon_url(large_icon_url),
173 thumbnail_url(thumbnail_url) {} 165 thumbnail_url(thumbnail_url) {}
174 166
175 PopularSites::Site::Site(const Site& other) = default; 167 PopularSites::Site::Site(const Site& other) = default;
176 168
177 PopularSites::Site::~Site() {} 169 PopularSites::Site::~Site() {}
178 170
179 PopularSites::PopularSites(PrefService* prefs, 171 PopularSites::PopularSites(PrefService* prefs,
180 const TemplateURLService* template_url_service, 172 const TemplateURLService* template_url_service,
173 VariationsService* variations_service,
181 net::URLRequestContextGetter* download_context, 174 net::URLRequestContextGetter* download_context,
182 const std::string& override_country, 175 const std::string& override_country,
183 const std::string& override_version, 176 const std::string& override_version,
184 bool force_download, 177 bool force_download,
185 const FinishedCallback& callback) 178 const FinishedCallback& callback)
186 : PopularSites(prefs, 179 : PopularSites(prefs,
187 template_url_service, 180 template_url_service,
188 download_context, 181 download_context,
189 GetCountryToUse(template_url_service, override_country), 182 GetCountryToUse(template_url_service,
183 variations_service,
184 override_country),
190 GetVersionToUse(override_version), 185 GetVersionToUse(override_version),
191 GURL(), 186 GURL(),
192 force_download, 187 force_download,
193 callback) {} 188 callback) {}
194 189
195 PopularSites::PopularSites(PrefService* prefs, 190 PopularSites::PopularSites(PrefService* prefs,
196 const TemplateURLService* template_url_service, 191 const TemplateURLService* template_url_service,
197 net::URLRequestContextGetter* download_context, 192 net::URLRequestContextGetter* download_context,
198 const GURL& url, 193 const GURL& url,
199 const FinishedCallback& callback) 194 const FinishedCallback& callback)
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 base::Bind(&PopularSites::OnJsonParsed, weak_ptr_factory_.GetWeakPtr())); 310 base::Bind(&PopularSites::OnJsonParsed, weak_ptr_factory_.GetWeakPtr()));
316 } 311 }
317 312
318 void PopularSites::OnJsonParsed(std::unique_ptr<std::vector<Site>> sites) { 313 void PopularSites::OnJsonParsed(std::unique_ptr<std::vector<Site>> sites) {
319 if (sites) 314 if (sites)
320 sites_.swap(*sites); 315 sites_.swap(*sites);
321 else 316 else
322 sites_.clear(); 317 sites_.clear();
323 callback_.Run(!!sites); 318 callback_.Run(!!sites);
324 } 319 }
OLDNEW
« no previous file with comments | « chrome/browser/android/ntp/popular_sites.h ('k') | chrome/browser/ui/webui/popular_sites_internals_message_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698