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

Side by Side Diff: components/ntp_tiles/popular_sites_impl.cc

Issue 2946143002: Remove legacy popular sites cache cleaning (Closed)
Patch Set: Remove unused imports Created 3 years, 6 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 "components/ntp_tiles/popular_sites_impl.h" 5 #include "components/ntp_tiles/popular_sites_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/feature_list.h" 12 #include "base/feature_list.h"
13 #include "base/files/file_path.h"
14 #include "base/files/file_util.h"
15 #include "base/path_service.h"
16 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
17 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
18 #include "base/threading/sequenced_worker_pool.h"
19 #include "base/time/time.h" 15 #include "base/time/time.h"
20 #include "base/values.h" 16 #include "base/values.h"
21 #include "components/data_use_measurement/core/data_use_user_data.h" 17 #include "components/data_use_measurement/core/data_use_user_data.h"
22 #include "components/google/core/browser/google_util.h" 18 #include "components/google/core/browser/google_util.h"
23 #include "components/ntp_tiles/constants.h" 19 #include "components/ntp_tiles/constants.h"
24 #include "components/ntp_tiles/field_trial.h" 20 #include "components/ntp_tiles/field_trial.h"
25 #include "components/ntp_tiles/pref_names.h" 21 #include "components/ntp_tiles/pref_names.h"
26 #include "components/ntp_tiles/switches.h" 22 #include "components/ntp_tiles/switches.h"
27 #include "components/pref_registry/pref_registry_syncable.h" 23 #include "components/pref_registry/pref_registry_syncable.h"
28 #include "components/prefs/pref_service.h" 24 #include "components/prefs/pref_service.h"
(...skipping 26 matching lines...) Expand all
55 "https://www.gstatic.com/%ssuggested_sites_%s_%s.json"; 51 "https://www.gstatic.com/%ssuggested_sites_%s_%s.json";
56 const char kPopularSitesDefaultDirectory[] = "chrome/ntp/"; 52 const char kPopularSitesDefaultDirectory[] = "chrome/ntp/";
57 const char kPopularSitesDefaultCountryCode[] = "DEFAULT"; 53 const char kPopularSitesDefaultCountryCode[] = "DEFAULT";
58 const char kPopularSitesDefaultVersion[] = "5"; 54 const char kPopularSitesDefaultVersion[] = "5";
59 const int kPopularSitesRedownloadIntervalHours = 24; 55 const int kPopularSitesRedownloadIntervalHours = 24;
60 56
61 const char kPopularSitesLastDownloadPref[] = "popular_sites_last_download"; 57 const char kPopularSitesLastDownloadPref[] = "popular_sites_last_download";
62 const char kPopularSitesURLPref[] = "popular_sites_url"; 58 const char kPopularSitesURLPref[] = "popular_sites_url";
63 const char kPopularSitesJsonPref[] = "suggested_sites_json"; 59 const char kPopularSitesJsonPref[] = "suggested_sites_json";
64 60
65 // TODO(crbug.com/683890): This refers to a local cache stored by older
66 // versions of Chrome, no longer used. Remove after M61.
67 const char kPopularSitesLocalFilenameToCleanup[] = "suggested_sites.json";
68
69 GURL GetPopularSitesURL(const std::string& directory, 61 GURL GetPopularSitesURL(const std::string& directory,
70 const std::string& country, 62 const std::string& country,
71 const std::string& version) { 63 const std::string& version) {
72 return GURL(base::StringPrintf(kPopularSitesURLFormat, directory.c_str(), 64 return GURL(base::StringPrintf(kPopularSitesURLFormat, directory.c_str(),
73 country.c_str(), version.c_str())); 65 country.c_str(), version.c_str()));
74 } 66 }
75 67
76 // Extract the country from the default search engine if the default search 68 // Extract the country from the default search engine if the default search
77 // engine is Google. 69 // engine is Google.
78 std::string GetDefaultSearchEngineCountryCode( 70 std::string GetDefaultSearchEngineCountryCode(
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 favicon_url(favicon_url), 182 favicon_url(favicon_url),
191 large_icon_url(large_icon_url), 183 large_icon_url(large_icon_url),
192 thumbnail_url(thumbnail_url), 184 thumbnail_url(thumbnail_url),
193 default_icon_resource(-1) {} 185 default_icon_resource(-1) {}
194 186
195 PopularSites::Site::Site(const Site& other) = default; 187 PopularSites::Site::Site(const Site& other) = default;
196 188
197 PopularSites::Site::~Site() {} 189 PopularSites::Site::~Site() {}
198 190
199 PopularSitesImpl::PopularSitesImpl( 191 PopularSitesImpl::PopularSitesImpl(
200 const scoped_refptr<base::SequencedWorkerPool>& blocking_pool,
201 PrefService* prefs, 192 PrefService* prefs,
202 const TemplateURLService* template_url_service, 193 const TemplateURLService* template_url_service,
203 VariationsService* variations_service, 194 VariationsService* variations_service,
204 net::URLRequestContextGetter* download_context, 195 net::URLRequestContextGetter* download_context,
205 const base::FilePath& directory,
206 ParseJSONCallback parse_json) 196 ParseJSONCallback parse_json)
207 : blocking_runner_(blocking_pool->GetTaskRunnerWithShutdownBehavior( 197 : prefs_(prefs),
208 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN)),
209 prefs_(prefs),
210 template_url_service_(template_url_service), 198 template_url_service_(template_url_service),
211 variations_(variations_service), 199 variations_(variations_service),
212 download_context_(download_context), 200 download_context_(download_context),
213 parse_json_(std::move(parse_json)), 201 parse_json_(std::move(parse_json)),
214 is_fallback_(false), 202 is_fallback_(false),
215 sites_(ParseSiteList(*prefs->GetList(kPopularSitesJsonPref))), 203 sites_(ParseSiteList(*prefs->GetList(kPopularSitesJsonPref))),
216 weak_ptr_factory_(this) { 204 weak_ptr_factory_(this) {}
217 // If valid path provided, remove local files created by older versions.
218 if (!directory.empty() && blocking_runner_) {
219 blocking_runner_->PostTask(
220 FROM_HERE,
221 base::Bind(base::IgnoreResult(&base::DeleteFile),
222 directory.AppendASCII(kPopularSitesLocalFilenameToCleanup),
223 /*recursive=*/false));
224 }
225 }
226 205
227 PopularSitesImpl::~PopularSitesImpl() {} 206 PopularSitesImpl::~PopularSitesImpl() {}
228 207
229 bool PopularSitesImpl::MaybeStartFetch(bool force_download, 208 bool PopularSitesImpl::MaybeStartFetch(bool force_download,
230 const FinishedCallback& callback) { 209 const FinishedCallback& callback) {
231 DCHECK(!callback_); 210 DCHECK(!callback_);
232 callback_ = callback; 211 callback_ = callback;
233 212
234 const base::Time last_download_time = base::Time::FromInternalValue( 213 const base::Time last_download_time = base::Time::FromInternalValue(
235 prefs_->GetInt64(kPopularSitesLastDownloadPref)); 214 prefs_->GetInt64(kPopularSitesLastDownloadPref));
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 kPopularSitesDefaultCountryCode, 412 kPopularSitesDefaultCountryCode,
434 kPopularSitesDefaultVersion); 413 kPopularSitesDefaultVersion);
435 FetchPopularSites(); 414 FetchPopularSites();
436 } else { 415 } else {
437 DLOG(WARNING) << "Download fallback site list failed"; 416 DLOG(WARNING) << "Download fallback site list failed";
438 callback_.Run(false); 417 callback_.Run(false);
439 } 418 }
440 } 419 }
441 420
442 } // namespace ntp_tiles 421 } // namespace ntp_tiles
OLDNEW
« no previous file with comments | « components/ntp_tiles/popular_sites_impl.h ('k') | components/ntp_tiles/popular_sites_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698