| 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/ntp_snippets_service.h" | 5 #include "components/ntp_snippets/ntp_snippets_service.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 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/scoped_temp_dir.h" | 12 #include "base/files/scoped_temp_dir.h" |
| 13 #include "base/json/json_reader.h" | 13 #include "base/json/json_reader.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
| 16 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
| 17 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
| 18 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
| 19 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
| 20 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
| 21 #include "base/test/histogram_tester.h" | 21 #include "base/test/histogram_tester.h" |
| 22 #include "base/threading/thread_task_runner_handle.h" | 22 #include "base/threading/thread_task_runner_handle.h" |
| 23 #include "base/time/time.h" | 23 #include "base/time/time.h" |
| 24 #include "components/image_fetcher/image_decoder.h" |
| 24 #include "components/image_fetcher/image_fetcher.h" | 25 #include "components/image_fetcher/image_fetcher.h" |
| 25 #include "components/ntp_snippets/ntp_snippet.h" | 26 #include "components/ntp_snippets/ntp_snippet.h" |
| 26 #include "components/ntp_snippets/ntp_snippets_database.h" | 27 #include "components/ntp_snippets/ntp_snippets_database.h" |
| 27 #include "components/ntp_snippets/ntp_snippets_fetcher.h" | 28 #include "components/ntp_snippets/ntp_snippets_fetcher.h" |
| 28 #include "components/ntp_snippets/ntp_snippets_scheduler.h" | 29 #include "components/ntp_snippets/ntp_snippets_scheduler.h" |
| 29 #include "components/ntp_snippets/switches.h" | 30 #include "components/ntp_snippets/switches.h" |
| 30 #include "components/prefs/testing_pref_service.h" | 31 #include "components/prefs/testing_pref_service.h" |
| 31 #include "components/signin/core/browser/account_tracker_service.h" | 32 #include "components/signin/core/browser/account_tracker_service.h" |
| 32 #include "components/signin/core/browser/fake_profile_oauth2_token_service.h" | 33 #include "components/signin/core/browser/fake_profile_oauth2_token_service.h" |
| 33 #include "components/signin/core/browser/fake_signin_manager.h" | 34 #include "components/signin/core/browser/fake_signin_manager.h" |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 // create the new one, otherwise opening the new database will fail. | 320 // create the new one, otherwise opening the new database will fail. |
| 320 service_.reset(); | 321 service_.reset(); |
| 321 | 322 |
| 322 service_.reset(new NTPSnippetsService( | 323 service_.reset(new NTPSnippetsService( |
| 323 enabled, pref_service_.get(), mock_sync_service_.get(), nullptr, | 324 enabled, pref_service_.get(), mock_sync_service_.get(), nullptr, |
| 324 std::string("fr"), &scheduler_, | 325 std::string("fr"), &scheduler_, |
| 325 base::WrapUnique(new NTPSnippetsFetcher( | 326 base::WrapUnique(new NTPSnippetsFetcher( |
| 326 fake_signin_manager_.get(), fake_token_service_.get(), | 327 fake_signin_manager_.get(), fake_token_service_.get(), |
| 327 std::move(request_context_getter), base::Bind(&ParseJson), | 328 std::move(request_context_getter), base::Bind(&ParseJson), |
| 328 /*is_stable_channel=*/true)), | 329 /*is_stable_channel=*/true)), |
| 329 /*image_fetcher=*/nullptr, | 330 /*image_fetcher=*/nullptr, /*image_decoder=*/nullptr, |
| 330 base::WrapUnique(new NTPSnippetsDatabase(database_dir_.path(), | 331 base::WrapUnique(new NTPSnippetsDatabase(database_dir_.path(), |
| 331 task_runner)))); | 332 task_runner)))); |
| 332 if (enabled) | 333 if (enabled) |
| 333 WaitForDBLoad(service_.get()); | 334 WaitForDBLoad(service_.get()); |
| 334 } | 335 } |
| 335 | 336 |
| 336 protected: | 337 protected: |
| 337 const GURL& test_url() { return test_url_; } | 338 const GURL& test_url() { return test_url_; } |
| 338 NTPSnippetsService* service() { return service_.get(); } | 339 NTPSnippetsService* service() { return service_.get(); } |
| 339 MockScheduler& mock_scheduler() { return scheduler_; } | 340 MockScheduler& mock_scheduler() { return scheduler_; } |
| (...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 928 SetUpFetchResponse(GetTestJson({GetSnippet()})); | 929 SetUpFetchResponse(GetTestJson({GetSnippet()})); |
| 929 service()->OnStateChanged(); | 930 service()->OnStateChanged(); |
| 930 base::RunLoop().RunUntilIdle(); | 931 base::RunLoop().RunUntilIdle(); |
| 931 EXPECT_EQ(NTPSnippetsService::State::READY, service()->state_); | 932 EXPECT_EQ(NTPSnippetsService::State::READY, service()->state_); |
| 932 EXPECT_FALSE(service()->snippets().empty()); | 933 EXPECT_FALSE(service()->snippets().empty()); |
| 933 | 934 |
| 934 service()->RemoveObserver(&mock_observer); | 935 service()->RemoveObserver(&mock_observer); |
| 935 } | 936 } |
| 936 | 937 |
| 937 } // namespace ntp_snippets | 938 } // namespace ntp_snippets |
| OLD | NEW |