| 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 #ifndef COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTIONS_PROVIDER_IMPL_H_ | 5 #ifndef COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTIONS_PROVIDER_IMPL_H_ |
| 6 #define COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTIONS_PROVIDER_IMPL_H_ | 6 #define COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTIONS_PROVIDER_IMPL_H_ |
| 7 | 7 |
| 8 #include <cstddef> | 8 #include <cstddef> |
| 9 #include <deque> | 9 #include <deque> |
| 10 #include <map> | 10 #include <map> |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 public: | 110 public: |
| 111 // |application_language_code| should be a ISO 639-1 compliant string, e.g. | 111 // |application_language_code| should be a ISO 639-1 compliant string, e.g. |
| 112 // 'en' or 'en-US'. Note that this code should only specify the language, not | 112 // 'en' or 'en-US'. Note that this code should only specify the language, not |
| 113 // the locale, so 'en_US' (English language with US locale) and 'en-GB_US' | 113 // the locale, so 'en_US' (English language with US locale) and 'en-GB_US' |
| 114 // (British English person in the US) are not language codes. | 114 // (British English person in the US) are not language codes. |
| 115 RemoteSuggestionsProviderImpl( | 115 RemoteSuggestionsProviderImpl( |
| 116 Observer* observer, | 116 Observer* observer, |
| 117 PrefService* pref_service, | 117 PrefService* pref_service, |
| 118 const std::string& application_language_code, | 118 const std::string& application_language_code, |
| 119 CategoryRanker* category_ranker, | 119 CategoryRanker* category_ranker, |
| 120 RemoteSuggestionsScheduler* scheduler, |
| 120 std::unique_ptr<RemoteSuggestionsFetcher> suggestions_fetcher, | 121 std::unique_ptr<RemoteSuggestionsFetcher> suggestions_fetcher, |
| 121 std::unique_ptr<image_fetcher::ImageFetcher> image_fetcher, | 122 std::unique_ptr<image_fetcher::ImageFetcher> image_fetcher, |
| 122 std::unique_ptr<RemoteSuggestionsDatabase> database, | 123 std::unique_ptr<RemoteSuggestionsDatabase> database, |
| 123 std::unique_ptr<RemoteSuggestionsStatusService> status_service); | 124 std::unique_ptr<RemoteSuggestionsStatusService> status_service); |
| 124 | 125 |
| 125 ~RemoteSuggestionsProviderImpl() override; | 126 ~RemoteSuggestionsProviderImpl() override; |
| 126 | 127 |
| 127 static void RegisterProfilePrefs(PrefRegistrySimple* registry); | 128 static void RegisterProfilePrefs(PrefRegistrySimple* registry); |
| 128 | 129 |
| 129 // Returns whether the service is ready. While this is false, the list of | 130 // Returns whether the service is ready. While this is false, the list of |
| 130 // suggestions will be empty, and all modifications to it (fetch, dismiss, | 131 // suggestions will be empty, and all modifications to it (fetch, dismiss, |
| 131 // etc) will be ignored. | 132 // etc) will be ignored. |
| 132 bool ready() const { return state_ == State::READY; } | 133 bool ready() const { return state_ == State::READY; } |
| 133 | 134 |
| 134 // Returns whether the service is successfully initialized. While this is | 135 // Returns whether the service is successfully initialized. While this is |
| 135 // false, some calls may trigger DCHECKs. | 136 // false, some calls may trigger DCHECKs. |
| 136 bool initialized() const { return ready() || state_ == State::DISABLED; } | 137 bool initialized() const { return ready() || state_ == State::DISABLED; } |
| 137 | 138 |
| 138 // Set the scheduler to be notified whenever the provider becomes active / | |
| 139 // in-active and whenever history is deleted. The initial change is also | |
| 140 // notified (switching from an initial undecided status). If the scheduler is | |
| 141 // set after the first change, it is called back immediately. | |
| 142 void SetRemoteSuggestionsScheduler(RemoteSuggestionsScheduler* scheduler); | |
| 143 | |
| 144 // RemoteSuggestionsProvider implementation. | 139 // RemoteSuggestionsProvider implementation. |
| 145 void RefetchInTheBackground( | 140 void RefetchInTheBackground( |
| 146 std::unique_ptr<FetchStatusCallback> callback) override; | 141 std::unique_ptr<FetchStatusCallback> callback) override; |
| 147 | 142 |
| 148 // TODO(fhorschig): Remove this getter when there is an interface for the | 143 // TODO(fhorschig): Remove this getter when there is an interface for the |
| 149 // fetcher that allows better mocks. | 144 // fetcher that allows better mocks. |
| 150 const RemoteSuggestionsFetcher* suggestions_fetcher_for_debugging() | 145 const RemoteSuggestionsFetcher* suggestions_fetcher_for_debugging() |
| 151 const override; | 146 const override; |
| 152 | 147 |
| 153 // ContentSuggestionsProvider implementation. | 148 // ContentSuggestionsProvider implementation. |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 const Category articles_category_; | 418 const Category articles_category_; |
| 424 | 419 |
| 425 std::map<Category, CategoryContent, Category::CompareByID> category_contents_; | 420 std::map<Category, CategoryContent, Category::CompareByID> category_contents_; |
| 426 | 421 |
| 427 // The ISO 639-1 code of the language used by the application. | 422 // The ISO 639-1 code of the language used by the application. |
| 428 const std::string application_language_code_; | 423 const std::string application_language_code_; |
| 429 | 424 |
| 430 // Ranker that orders the categories. Not owned. | 425 // Ranker that orders the categories. Not owned. |
| 431 CategoryRanker* category_ranker_; | 426 CategoryRanker* category_ranker_; |
| 432 | 427 |
| 428 // Scheduler to inform about scheduling-related events. Not owned. |
| 429 RemoteSuggestionsScheduler* remote_suggestions_scheduler_; |
| 430 |
| 433 // The suggestions fetcher. | 431 // The suggestions fetcher. |
| 434 std::unique_ptr<RemoteSuggestionsFetcher> suggestions_fetcher_; | 432 std::unique_ptr<RemoteSuggestionsFetcher> suggestions_fetcher_; |
| 435 | 433 |
| 436 // The database for persisting suggestions. | 434 // The database for persisting suggestions. |
| 437 std::unique_ptr<RemoteSuggestionsDatabase> database_; | 435 std::unique_ptr<RemoteSuggestionsDatabase> database_; |
| 438 base::TimeTicks database_load_start_; | 436 base::TimeTicks database_load_start_; |
| 439 | 437 |
| 440 // The image fetcher. | 438 // The image fetcher. |
| 441 CachedImageFetcher image_fetcher_; | 439 CachedImageFetcher image_fetcher_; |
| 442 | 440 |
| 443 // The service that provides events and data about the signin and sync state. | 441 // The service that provides events and data about the signin and sync state. |
| 444 std::unique_ptr<RemoteSuggestionsStatusService> status_service_; | 442 std::unique_ptr<RemoteSuggestionsStatusService> status_service_; |
| 445 | 443 |
| 446 // Set to true if FetchSuggestions is called while the service isn't ready. | 444 // Set to true if FetchSuggestions is called while the service isn't ready. |
| 447 // The fetch will be executed once the service enters the READY state. | 445 // The fetch will be executed once the service enters the READY state. |
| 448 // TODO(jkrcal): create a struct and have here just one base::Optional<>? | 446 // TODO(jkrcal): create a struct and have here just one base::Optional<>? |
| 449 bool fetch_when_ready_; | 447 bool fetch_when_ready_; |
| 450 | 448 |
| 451 // The parameters for the fetch to perform later. | 449 // The parameters for the fetch to perform later. |
| 452 bool fetch_when_ready_interactive_; | 450 bool fetch_when_ready_interactive_; |
| 453 std::unique_ptr<FetchStatusCallback> fetch_when_ready_callback_; | 451 std::unique_ptr<FetchStatusCallback> fetch_when_ready_callback_; |
| 454 | 452 |
| 455 RemoteSuggestionsScheduler* remote_suggestions_scheduler_; | |
| 456 | |
| 457 // Set to true if ClearHistoryDependentState is called while the service isn't | 453 // Set to true if ClearHistoryDependentState is called while the service isn't |
| 458 // ready. The nuke will be executed once the service finishes initialization | 454 // ready. The nuke will be executed once the service finishes initialization |
| 459 // or enters the READY state. | 455 // or enters the READY state. |
| 460 bool clear_history_dependent_state_when_initialized_; | 456 bool clear_history_dependent_state_when_initialized_; |
| 461 | 457 |
| 462 // A clock for getting the time. This allows to inject a clock in tests. | 458 // A clock for getting the time. This allows to inject a clock in tests. |
| 463 std::unique_ptr<base::Clock> clock_; | 459 std::unique_ptr<base::Clock> clock_; |
| 464 | 460 |
| 465 DISALLOW_COPY_AND_ASSIGN(RemoteSuggestionsProviderImpl); | 461 DISALLOW_COPY_AND_ASSIGN(RemoteSuggestionsProviderImpl); |
| 466 }; | 462 }; |
| 467 | 463 |
| 468 } // namespace ntp_snippets | 464 } // namespace ntp_snippets |
| 469 | 465 |
| 470 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTIONS_PROVIDER_IMPL_H_ | 466 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTIONS_PROVIDER_IMPL_H_ |
| OLD | NEW |