Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/most_visited_sites.h" | 5 #include "components/ntp_tiles/most_visited_sites.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <ostream> | 10 #include <ostream> |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 196 void(PopularSites::Site site, | 196 void(PopularSites::Site site, |
| 197 const base::Callback<void(bool)>& done)); | 197 const base::Callback<void(bool)>& done)); |
| 198 }; | 198 }; |
| 199 | 199 |
| 200 class PopularSitesFactoryForTest { | 200 class PopularSitesFactoryForTest { |
| 201 public: | 201 public: |
| 202 PopularSitesFactoryForTest( | 202 PopularSitesFactoryForTest( |
| 203 bool enabled, | 203 bool enabled, |
| 204 sync_preferences::TestingPrefServiceSyncable* pref_service) | 204 sync_preferences::TestingPrefServiceSyncable* pref_service) |
| 205 : prefs_(pref_service), | 205 : prefs_(pref_service), |
| 206 enabled_in_variations_(enabled), | |
| 206 url_fetcher_factory_(/*default_factory=*/nullptr), | 207 url_fetcher_factory_(/*default_factory=*/nullptr), |
| 207 url_request_context_(new net::TestURLRequestContextGetter( | 208 url_request_context_(new net::TestURLRequestContextGetter( |
| 208 base::ThreadTaskRunnerHandle::Get())), | 209 base::ThreadTaskRunnerHandle::Get())), |
| 209 worker_pool_owner_(/*max_threads=*/2, "PopularSitesFactoryForTest.") { | 210 worker_pool_owner_(/*max_threads=*/2, "PopularSitesFactoryForTest.") { |
| 210 if (enabled) { | 211 PopularSitesImpl::RegisterProfilePrefs(pref_service->registry()); |
| 211 PopularSitesImpl::RegisterProfilePrefs(pref_service->registry()); | 212 if (enabled_in_variations_) { |
| 212 | |
| 213 prefs_->SetString(prefs::kPopularSitesOverrideCountry, "IN"); | 213 prefs_->SetString(prefs::kPopularSitesOverrideCountry, "IN"); |
| 214 prefs_->SetString(prefs::kPopularSitesOverrideVersion, "7"); | 214 prefs_->SetString(prefs::kPopularSitesOverrideVersion, "7"); |
| 215 | 215 |
| 216 url_fetcher_factory_.SetFakeResponse( | 216 url_fetcher_factory_.SetFakeResponse( |
| 217 GURL("https://www.gstatic.com/chrome/ntp/suggested_sites_IN_7.json"), | 217 GURL("https://www.gstatic.com/chrome/ntp/suggested_sites_IN_7.json"), |
| 218 R"([{ | 218 R"([{ |
| 219 "title": "PopularSite1", | 219 "title": "PopularSite1", |
| 220 "url": "http://popularsite1/", | 220 "url": "http://popularsite1/", |
| 221 "favicon_url": "http://popularsite1/favicon.ico" | 221 "favicon_url": "http://popularsite1/favicon.ico" |
| 222 }, | 222 }, |
| 223 { | 223 { |
| 224 "title": "PopularSite2", | 224 "title": "PopularSite2", |
| 225 "url": "http://popularsite2/", | 225 "url": "http://popularsite2/", |
| 226 "favicon_url": "http://popularsite2/favicon.ico" | 226 "favicon_url": "http://popularsite2/favicon.ico" |
| 227 }, | 227 }, |
| 228 ])", | 228 ])", |
| 229 net::HTTP_OK, net::URLRequestStatus::SUCCESS); | 229 net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
| 230 } | 230 } |
| 231 } | 231 } |
| 232 | 232 |
| 233 std::unique_ptr<PopularSites> New() { | 233 std::unique_ptr<PopularSites> New() { |
| 234 if (!enabled_in_variations_) { | |
|
sfiera
2017/02/10 10:40:03
I don't think this change is correct. I think that
fhorschig
2017/02/13 10:34:13
Undone. The whole file is untouched.
The problem w
| |
| 235 return nullptr; | |
| 236 } | |
| 234 return base::MakeUnique<PopularSitesImpl>( | 237 return base::MakeUnique<PopularSitesImpl>( |
| 235 worker_pool_owner_.pool().get(), prefs_, | 238 worker_pool_owner_.pool().get(), prefs_, |
| 236 /*template_url_service=*/nullptr, | 239 /*template_url_service=*/nullptr, |
| 237 /*variations_service=*/nullptr, url_request_context_.get(), | 240 /*variations_service=*/nullptr, url_request_context_.get(), |
| 238 /*directory=*/base::FilePath(), base::Bind(JsonUnsafeParser::Parse)); | 241 /*directory=*/base::FilePath(), base::Bind(JsonUnsafeParser::Parse)); |
| 239 } | 242 } |
| 240 | 243 |
| 241 private: | 244 private: |
| 242 PrefService* prefs_; | 245 PrefService* prefs_; |
| 246 bool enabled_in_variations_; | |
| 243 net::FakeURLFetcherFactory url_fetcher_factory_; | 247 net::FakeURLFetcherFactory url_fetcher_factory_; |
| 244 scoped_refptr<net::TestURLRequestContextGetter> url_request_context_; | 248 scoped_refptr<net::TestURLRequestContextGetter> url_request_context_; |
| 245 base::SequencedWorkerPoolOwner worker_pool_owner_; | 249 base::SequencedWorkerPoolOwner worker_pool_owner_; |
| 246 }; | 250 }; |
| 247 | 251 |
| 248 // CallbackList-like container without Subscription, mimicking the | 252 // CallbackList-like container without Subscription, mimicking the |
| 249 // implementation in TopSites (which doesn't use base::CallbackList). | 253 // implementation in TopSites (which doesn't use base::CallbackList). |
| 250 class TopSitesCallbackList { | 254 class TopSitesCallbackList { |
| 251 public: | 255 public: |
| 252 // Second argument declared to match the signature of GetMostVisitedURLs(). | 256 // Second argument declared to match the signature of GetMostVisitedURLs(). |
| (...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 805 MatchesTile("Site 4", "https://www.site4.com/", | 809 MatchesTile("Site 4", "https://www.site4.com/", |
| 806 NTPTileSource::TOP_SITES), | 810 NTPTileSource::TOP_SITES), |
| 807 MatchesTile("Site 1", "https://www.site1.com/", | 811 MatchesTile("Site 1", "https://www.site1.com/", |
| 808 NTPTileSource::POPULAR), | 812 NTPTileSource::POPULAR), |
| 809 MatchesTile("Site 2", "https://www.site2.com/", | 813 MatchesTile("Site 2", "https://www.site2.com/", |
| 810 NTPTileSource::POPULAR))); | 814 NTPTileSource::POPULAR))); |
| 811 } | 815 } |
| 812 | 816 |
| 813 } // namespace | 817 } // namespace |
| 814 } // namespace ntp_tiles | 818 } // namespace ntp_tiles |
| OLD | NEW |