| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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_DOODLE_DOODLE_SERVICE_H_ | 5 #ifndef COMPONENTS_DOODLE_DOODLE_SERVICE_H_ |
| 6 #define COMPONENTS_DOODLE_DOODLE_SERVICE_H_ | 6 #define COMPONENTS_DOODLE_DOODLE_SERVICE_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/observer_list.h" | 11 #include "base/observer_list.h" |
| 12 #include "base/optional.h" | 12 #include "base/optional.h" |
| 13 #include "base/time/clock.h" | 13 #include "base/time/clock.h" |
| 14 #include "base/timer/timer.h" | 14 #include "base/timer/timer.h" |
| 15 #include "components/doodle/doodle_fetcher.h" | 15 #include "components/doodle/doodle_fetcher.h" |
| 16 #include "components/doodle/doodle_types.h" | 16 #include "components/doodle/doodle_types.h" |
| 17 #include "components/keyed_service/core/keyed_service.h" |
| 17 | 18 |
| 18 class PrefRegistrySimple; | 19 class PrefRegistrySimple; |
| 19 class PrefService; | 20 class PrefService; |
| 20 | 21 |
| 21 namespace base { | 22 namespace base { |
| 22 class TimeDelta; | 23 class TimeDelta; |
| 23 } | 24 } |
| 24 | 25 |
| 25 namespace doodle { | 26 namespace doodle { |
| 26 | 27 |
| 27 class DoodleService { | 28 class DoodleService : public KeyedService { |
| 28 public: | 29 public: |
| 29 class Observer { | 30 class Observer { |
| 30 public: | 31 public: |
| 31 virtual void OnDoodleConfigUpdated(const base::Optional<DoodleConfig>&) = 0; | 32 virtual void OnDoodleConfigUpdated(const base::Optional<DoodleConfig>&) = 0; |
| 32 }; | 33 }; |
| 33 | 34 |
| 34 static void RegisterProfilePrefs(PrefRegistrySimple* pref_registry); | 35 static void RegisterProfilePrefs(PrefRegistrySimple* pref_registry); |
| 35 | 36 |
| 36 // All parameters must be non-null. | 37 // All parameters must be non-null. |
| 37 DoodleService(PrefService* pref_service, | 38 DoodleService(PrefService* pref_service, |
| 38 std::unique_ptr<DoodleFetcher> fetcher, | 39 std::unique_ptr<DoodleFetcher> fetcher, |
| 39 std::unique_ptr<base::OneShotTimer> expiry_timer, | 40 std::unique_ptr<base::OneShotTimer> expiry_timer, |
| 40 std::unique_ptr<base::Clock> clock); | 41 std::unique_ptr<base::Clock> clock); |
| 41 ~DoodleService(); | 42 ~DoodleService() override; |
| 43 |
| 44 // KeyedService implementation. |
| 45 void Shutdown() override; |
| 42 | 46 |
| 43 // Returns the current (cached) config, if any. | 47 // Returns the current (cached) config, if any. |
| 44 const base::Optional<DoodleConfig>& config() const { return cached_config_; } | 48 const base::Optional<DoodleConfig>& config() const { return cached_config_; } |
| 45 | 49 |
| 46 // Adds a new observer to the service. It'll only be called when the config | 50 // Adds a new observer to the service. It'll only be called when the config |
| 47 // changes; to get the current (cached) config, call |config()|. | 51 // changes; to get the current (cached) config, call |config()|. |
| 48 void AddObserver(Observer* observer); | 52 void AddObserver(Observer* observer); |
| 49 | 53 |
| 50 // Prevents |observer| from receiving future updates. This is safe to call | 54 // Prevents |observer| from receiving future updates. This is safe to call |
| 51 // even when the observer is being notified of an update. | 55 // even when the observer is being notified of an update. |
| (...skipping 29 matching lines...) Expand all Loading... |
| 81 | 85 |
| 82 // The list of observers to be notified when the DoodleConfig changes. | 86 // The list of observers to be notified when the DoodleConfig changes. |
| 83 base::ObserverList<Observer> observers_; | 87 base::ObserverList<Observer> observers_; |
| 84 | 88 |
| 85 DISALLOW_COPY_AND_ASSIGN(DoodleService); | 89 DISALLOW_COPY_AND_ASSIGN(DoodleService); |
| 86 }; | 90 }; |
| 87 | 91 |
| 88 } // namespace doodle | 92 } // namespace doodle |
| 89 | 93 |
| 90 #endif // COMPONENTS_DOODLE_DOODLE_SERVICE_H_ | 94 #endif // COMPONENTS_DOODLE_DOODLE_SERVICE_H_ |
| OLD | NEW |