| 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_snippets/remote/remote_suggestions_provider.h" | 5 #include "components/ntp_snippets/remote/remote_suggestions_provider.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 [](base::Closure signal, gfx::Image* output, | 273 [](base::Closure signal, gfx::Image* output, |
| 274 const gfx::Image& loaded) { | 274 const gfx::Image& loaded) { |
| 275 *output = loaded; | 275 *output = loaded; |
| 276 signal.Run(); | 276 signal.Run(); |
| 277 }, | 277 }, |
| 278 run_loop.QuitClosure(), &result)); | 278 run_loop.QuitClosure(), &result)); |
| 279 run_loop.Run(); | 279 run_loop.Run(); |
| 280 return result; | 280 return result; |
| 281 } | 281 } |
| 282 | 282 |
| 283 void ParseJson( | 283 void ParseJson(const std::string& json, |
| 284 const std::string& json, | 284 const SuccessCallback& success_callback, |
| 285 const ntp_snippets::NTPSnippetsFetcher::SuccessCallback& success_callback, | 285 const ErrorCallback& error_callback) { |
| 286 const ntp_snippets::NTPSnippetsFetcher::ErrorCallback& error_callback) { | |
| 287 base::JSONReader json_reader; | 286 base::JSONReader json_reader; |
| 288 std::unique_ptr<base::Value> value = json_reader.ReadToValue(json); | 287 std::unique_ptr<base::Value> value = json_reader.ReadToValue(json); |
| 289 if (value) { | 288 if (value) { |
| 290 success_callback.Run(std::move(value)); | 289 success_callback.Run(std::move(value)); |
| 291 } else { | 290 } else { |
| 292 error_callback.Run(json_reader.GetErrorMessage()); | 291 error_callback.Run(json_reader.GetErrorMessage()); |
| 293 } | 292 } |
| 294 } | 293 } |
| 295 | 294 |
| 296 // Factory for FakeURLFetcher objects that always generate errors. | 295 // Factory for FakeURLFetcher objects that always generate errors. |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 auto image_decoder = base::MakeUnique<FakeImageDecoder>(); | 449 auto image_decoder = base::MakeUnique<FakeImageDecoder>(); |
| 451 image_decoder_ = image_decoder.get(); | 450 image_decoder_ = image_decoder.get(); |
| 452 EXPECT_FALSE(observer_); | 451 EXPECT_FALSE(observer_); |
| 453 observer_ = base::MakeUnique<FakeContentSuggestionsProviderObserver>(); | 452 observer_ = base::MakeUnique<FakeContentSuggestionsProviderObserver>(); |
| 454 auto database = base::MakeUnique<RemoteSuggestionsDatabase>( | 453 auto database = base::MakeUnique<RemoteSuggestionsDatabase>( |
| 455 database_dir_.GetPath(), task_runner); | 454 database_dir_.GetPath(), task_runner); |
| 456 database_ = database.get(); | 455 database_ = database.get(); |
| 457 return base::MakeUnique<RemoteSuggestionsProvider>( | 456 return base::MakeUnique<RemoteSuggestionsProvider>( |
| 458 observer_.get(), &category_factory_, utils_.pref_service(), "fr", | 457 observer_.get(), &category_factory_, utils_.pref_service(), "fr", |
| 459 &user_classifier_, &scheduler_, std::move(snippets_fetcher), | 458 &user_classifier_, &scheduler_, std::move(snippets_fetcher), |
| 460 std::move(image_fetcher), std::move(image_decoder), | 459 std::move(image_fetcher), std::move(image_decoder), std::move(database), |
| 461 std::move(database), | |
| 462 base::MakeUnique<RemoteSuggestionsStatusService>( | 460 base::MakeUnique<RemoteSuggestionsStatusService>( |
| 463 utils_.fake_signin_manager(), utils_.pref_service())); | 461 utils_.fake_signin_manager(), utils_.pref_service())); |
| 464 } | 462 } |
| 465 | 463 |
| 466 void WaitForSnippetsServiceInitialization(RemoteSuggestionsProvider* service, | 464 void WaitForSnippetsServiceInitialization(RemoteSuggestionsProvider* service, |
| 467 bool set_empty_response) { | 465 bool set_empty_response) { |
| 468 EXPECT_EQ(RemoteSuggestionsProvider::State::NOT_INITED, service->state_); | 466 EXPECT_EQ(RemoteSuggestionsProvider::State::NOT_INITED, service->state_); |
| 469 | 467 |
| 470 // Add an initial fetch response, as the service tries to fetch when there | 468 // Add an initial fetch response, as the service tries to fetch when there |
| 471 // is nothing in the DB. | 469 // is nothing in the DB. |
| (...skipping 1241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1713 service->FetchSnippetsInTheBackground(); | 1711 service->FetchSnippetsInTheBackground(); |
| 1714 base::RunLoop().RunUntilIdle(); | 1712 base::RunLoop().RunUntilIdle(); |
| 1715 EXPECT_EQ( | 1713 EXPECT_EQ( |
| 1716 simple_test_clock_ptr->Now().ToInternalValue(), | 1714 simple_test_clock_ptr->Now().ToInternalValue(), |
| 1717 pref_service()->GetInt64(prefs::kLastSuccessfulBackgroundFetchTime)); | 1715 pref_service()->GetInt64(prefs::kLastSuccessfulBackgroundFetchTime)); |
| 1718 // TODO(markusheintz): Add a test that simulates a browser restart once the | 1716 // TODO(markusheintz): Add a test that simulates a browser restart once the |
| 1719 // scheduler refactoring is done (crbug.com/672434). | 1717 // scheduler refactoring is done (crbug.com/672434). |
| 1720 } | 1718 } |
| 1721 | 1719 |
| 1722 } // namespace ntp_snippets | 1720 } // namespace ntp_snippets |
| OLD | NEW |