| 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 "components/doodle/doodle_fetcher.h" | 13 #include "components/doodle/doodle_fetcher.h" |
| 14 #include "components/doodle/doodle_types.h" | 14 #include "components/doodle/doodle_types.h" |
| 15 | 15 |
| 16 namespace base { |
| 17 class TimeDelta; |
| 18 } |
| 19 |
| 16 namespace doodle { | 20 namespace doodle { |
| 17 | 21 |
| 18 class DoodleService { | 22 class DoodleService { |
| 19 public: | 23 public: |
| 20 class Observer { | 24 class Observer { |
| 21 public: | 25 public: |
| 22 virtual void OnDoodleConfigUpdated(const base::Optional<DoodleConfig>&) = 0; | 26 virtual void OnDoodleConfigUpdated(const base::Optional<DoodleConfig>&) = 0; |
| 23 }; | 27 }; |
| 24 | 28 |
| 25 DoodleService(std::unique_ptr<DoodleFetcher> fetcher); | 29 DoodleService(std::unique_ptr<DoodleFetcher> fetcher); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 36 // even when the observer is being notified of an update. | 40 // even when the observer is being notified of an update. |
| 37 void RemoveObserver(Observer* observer); | 41 void RemoveObserver(Observer* observer); |
| 38 | 42 |
| 39 // Requests an asynchronous refresh of the DoodleConfig from the network. | 43 // Requests an asynchronous refresh of the DoodleConfig from the network. |
| 40 // After the update completes, the observers will be notified only if the | 44 // After the update completes, the observers will be notified only if the |
| 41 // config changed. | 45 // config changed. |
| 42 void Refresh(); | 46 void Refresh(); |
| 43 | 47 |
| 44 private: | 48 private: |
| 45 void DoodleFetched(DoodleState state, | 49 void DoodleFetched(DoodleState state, |
| 50 base::TimeDelta time_to_live, |
| 46 const base::Optional<DoodleConfig>& doodle_config); | 51 const base::Optional<DoodleConfig>& doodle_config); |
| 47 | 52 |
| 48 // The fetcher for getting fresh DoodleConfigs from the network. | 53 // The fetcher for getting fresh DoodleConfigs from the network. |
| 49 std::unique_ptr<DoodleFetcher> fetcher_; | 54 std::unique_ptr<DoodleFetcher> fetcher_; |
| 50 | 55 |
| 51 // The result of the last network fetch. | 56 // The result of the last network fetch. |
| 52 base::Optional<DoodleConfig> cached_config_; | 57 base::Optional<DoodleConfig> cached_config_; |
| 53 | 58 |
| 54 // The list of observers to be notified when the DoodleConfig changes. | 59 // The list of observers to be notified when the DoodleConfig changes. |
| 55 base::ObserverList<Observer> observers_; | 60 base::ObserverList<Observer> observers_; |
| 56 | 61 |
| 57 DISALLOW_COPY_AND_ASSIGN(DoodleService); | 62 DISALLOW_COPY_AND_ASSIGN(DoodleService); |
| 58 }; | 63 }; |
| 59 | 64 |
| 60 } // namespace doodle | 65 } // namespace doodle |
| 61 | 66 |
| 62 #endif // COMPONENTS_DOODLE_DOODLE_SERVICE_H_ | 67 #endif // COMPONENTS_DOODLE_DOODLE_SERVICE_H_ |
| OLD | NEW |