| 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> |
| 11 #include <string> | 11 #include <string> |
| 12 #include <utility> | 12 #include <utility> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "base/callback_list.h" | 15 #include "base/callback_list.h" |
| 16 #include "base/command_line.h" | 16 #include "base/command_line.h" |
| 17 #include "base/macros.h" | 17 #include "base/macros.h" |
| 18 #include "base/memory/ptr_util.h" | 18 #include "base/memory/ptr_util.h" |
| 19 #include "base/message_loop/message_loop.h" | 19 #include "base/message_loop/message_loop.h" |
| 20 #include "base/run_loop.h" | 20 #include "base/run_loop.h" |
| 21 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
| 22 #include "base/task/cancelable_task_tracker.h" | 22 #include "base/task/cancelable_task_tracker.h" |
| 23 #include "base/test/scoped_feature_list.h" | 23 #include "base/test/scoped_feature_list.h" |
| 24 #include "base/test/sequenced_worker_pool_owner.h" | |
| 25 #include "base/threading/thread_task_runner_handle.h" | 24 #include "base/threading/thread_task_runner_handle.h" |
| 26 #include "components/history/core/browser/top_sites.h" | 25 #include "components/history/core/browser/top_sites.h" |
| 27 #include "components/history/core/browser/top_sites_observer.h" | 26 #include "components/history/core/browser/top_sites_observer.h" |
| 28 #include "components/ntp_tiles/constants.h" | 27 #include "components/ntp_tiles/constants.h" |
| 29 #include "components/ntp_tiles/icon_cacher.h" | 28 #include "components/ntp_tiles/icon_cacher.h" |
| 30 #include "components/ntp_tiles/json_unsafe_parser.h" | 29 #include "components/ntp_tiles/json_unsafe_parser.h" |
| 31 #include "components/ntp_tiles/popular_sites_impl.h" | 30 #include "components/ntp_tiles/popular_sites_impl.h" |
| 32 #include "components/ntp_tiles/pref_names.h" | 31 #include "components/ntp_tiles/pref_names.h" |
| 33 #include "components/ntp_tiles/switches.h" | 32 #include "components/ntp_tiles/switches.h" |
| 34 #include "components/sync_preferences/testing_pref_service_syncable.h" | 33 #include "components/sync_preferences/testing_pref_service_syncable.h" |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 }; | 251 }; |
| 253 | 252 |
| 254 class PopularSitesFactoryForTest { | 253 class PopularSitesFactoryForTest { |
| 255 public: | 254 public: |
| 256 PopularSitesFactoryForTest( | 255 PopularSitesFactoryForTest( |
| 257 bool enabled, | 256 bool enabled, |
| 258 sync_preferences::TestingPrefServiceSyncable* pref_service) | 257 sync_preferences::TestingPrefServiceSyncable* pref_service) |
| 259 : prefs_(pref_service), | 258 : prefs_(pref_service), |
| 260 url_fetcher_factory_(/*default_factory=*/nullptr), | 259 url_fetcher_factory_(/*default_factory=*/nullptr), |
| 261 url_request_context_(new net::TestURLRequestContextGetter( | 260 url_request_context_(new net::TestURLRequestContextGetter( |
| 262 base::ThreadTaskRunnerHandle::Get())), | 261 base::ThreadTaskRunnerHandle::Get())) { |
| 263 worker_pool_owner_(/*max_threads=*/2, "PopularSitesFactoryForTest.") { | |
| 264 PopularSitesImpl::RegisterProfilePrefs(pref_service->registry()); | 262 PopularSitesImpl::RegisterProfilePrefs(pref_service->registry()); |
| 265 if (enabled) { | 263 if (enabled) { |
| 266 prefs_->SetString(prefs::kPopularSitesOverrideCountry, "IN"); | 264 prefs_->SetString(prefs::kPopularSitesOverrideCountry, "IN"); |
| 267 prefs_->SetString(prefs::kPopularSitesOverrideVersion, "7"); | 265 prefs_->SetString(prefs::kPopularSitesOverrideVersion, "7"); |
| 268 | 266 |
| 269 url_fetcher_factory_.SetFakeResponse( | 267 url_fetcher_factory_.SetFakeResponse( |
| 270 GURL("https://www.gstatic.com/chrome/ntp/suggested_sites_IN_7.json"), | 268 GURL("https://www.gstatic.com/chrome/ntp/suggested_sites_IN_7.json"), |
| 271 R"([{ | 269 R"([{ |
| 272 "title": "PopularSite1", | 270 "title": "PopularSite1", |
| 273 "url": "http://popularsite1/", | 271 "url": "http://popularsite1/", |
| 274 "favicon_url": "http://popularsite1/favicon.ico" | 272 "favicon_url": "http://popularsite1/favicon.ico" |
| 275 }, | 273 }, |
| 276 { | 274 { |
| 277 "title": "PopularSite2", | 275 "title": "PopularSite2", |
| 278 "url": "http://popularsite2/", | 276 "url": "http://popularsite2/", |
| 279 "favicon_url": "http://popularsite2/favicon.ico" | 277 "favicon_url": "http://popularsite2/favicon.ico" |
| 280 }, | 278 }, |
| 281 ])", | 279 ])", |
| 282 net::HTTP_OK, net::URLRequestStatus::SUCCESS); | 280 net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
| 283 } | 281 } |
| 284 } | 282 } |
| 285 | 283 |
| 286 std::unique_ptr<PopularSites> New() { | 284 std::unique_ptr<PopularSites> New() { |
| 287 return base::MakeUnique<PopularSitesImpl>( | 285 return base::MakeUnique<PopularSitesImpl>( |
| 288 worker_pool_owner_.pool().get(), prefs_, | 286 prefs_, |
| 289 /*template_url_service=*/nullptr, | 287 /*template_url_service=*/nullptr, |
| 290 /*variations_service=*/nullptr, url_request_context_.get(), | 288 /*variations_service=*/nullptr, url_request_context_.get(), |
| 291 /*directory=*/base::FilePath(), base::Bind(JsonUnsafeParser::Parse)); | 289 base::Bind(JsonUnsafeParser::Parse)); |
| 292 } | 290 } |
| 293 | 291 |
| 294 private: | 292 private: |
| 295 PrefService* prefs_; | 293 PrefService* prefs_; |
| 296 net::FakeURLFetcherFactory url_fetcher_factory_; | 294 net::FakeURLFetcherFactory url_fetcher_factory_; |
| 297 scoped_refptr<net::TestURLRequestContextGetter> url_request_context_; | 295 scoped_refptr<net::TestURLRequestContextGetter> url_request_context_; |
| 298 base::SequencedWorkerPoolOwner worker_pool_owner_; | |
| 299 }; | 296 }; |
| 300 | 297 |
| 301 // CallbackList-like container without Subscription, mimicking the | 298 // CallbackList-like container without Subscription, mimicking the |
| 302 // implementation in TopSites (which doesn't use base::CallbackList). | 299 // implementation in TopSites (which doesn't use base::CallbackList). |
| 303 class TopSitesCallbackList { | 300 class TopSitesCallbackList { |
| 304 public: | 301 public: |
| 305 // Second argument declared to match the signature of GetMostVisitedURLs(). | 302 // Second argument declared to match the signature of GetMostVisitedURLs(). |
| 306 void Add(const TopSites::GetMostVisitedURLsCallback& callback, | 303 void Add(const TopSites::GetMostVisitedURLsCallback& callback, |
| 307 testing::Unused) { | 304 testing::Unused) { |
| 308 callbacks_.push_back(callback); | 305 callbacks_.push_back(callback); |
| (...skipping 875 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1184 TileSource::TOP_SITES), | 1181 TileSource::TOP_SITES), |
| 1185 MatchesTile("Site 4", "https://www.site4.com/", | 1182 MatchesTile("Site 4", "https://www.site4.com/", |
| 1186 TileSource::TOP_SITES), | 1183 TileSource::TOP_SITES), |
| 1187 MatchesTile("Site 1", "https://www.site1.com/", TileSource::POPULAR), | 1184 MatchesTile("Site 1", "https://www.site1.com/", TileSource::POPULAR), |
| 1188 MatchesTile("Site 2", "https://www.site2.com/", | 1185 MatchesTile("Site 2", "https://www.site2.com/", |
| 1189 TileSource::POPULAR))); | 1186 TileSource::POPULAR))); |
| 1190 } | 1187 } |
| 1191 | 1188 |
| 1192 } // namespace | 1189 } // namespace |
| 1193 } // namespace ntp_tiles | 1190 } // namespace ntp_tiles |
| OLD | NEW |