Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: components/doodle/doodle_service.h

Issue 2833473002: Record NTP.LogoShownTime for timely refreshs only (Closed)
Patch Set: Replace |Refresh| return value with treib@'s revalidation event Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/time/tick_clock.h" 14 #include "base/time/tick_clock.h"
15 #include "base/time/time.h" 15 #include "base/time/time.h"
16 #include "base/timer/timer.h" 16 #include "base/timer/timer.h"
17 #include "components/doodle/doodle_fetcher.h" 17 #include "components/doodle/doodle_fetcher.h"
18 #include "components/doodle/doodle_types.h" 18 #include "components/doodle/doodle_types.h"
19 #include "components/keyed_service/core/keyed_service.h" 19 #include "components/keyed_service/core/keyed_service.h"
20 20
21 class PrefRegistrySimple; 21 class PrefRegistrySimple;
22 class PrefService; 22 class PrefService;
23 23
24 namespace doodle { 24 namespace doodle {
25 25
26 class DoodleService : public KeyedService { 26 class DoodleService : public KeyedService {
27 public: 27 public:
28 class Observer { 28 class Observer {
29 public: 29 public:
30 virtual void OnDoodleConfigRevalidated(bool from_cache) = 0;
30 virtual void OnDoodleConfigUpdated(const base::Optional<DoodleConfig>&) = 0; 31 virtual void OnDoodleConfigUpdated(const base::Optional<DoodleConfig>&) = 0;
31 }; 32 };
32 33
33 static void RegisterProfilePrefs(PrefRegistrySimple* pref_registry); 34 static void RegisterProfilePrefs(PrefRegistrySimple* pref_registry);
34 35
35 // All pointer parameters must be non-null. If |min_refresh_interval| doesn't 36 // All pointer parameters must be non-null. If |min_refresh_interval| doesn't
36 // have a value, the default value is used. 37 // have a value, the default value is used.
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,
(...skipping 10 matching lines...) Expand all
50 51
51 // Adds a new observer to the service. It'll only be called when the config 52 // Adds a new observer to the service. It'll only be called when the config
52 // changes; to get the current (cached) config, call |config()|. 53 // changes; to get the current (cached) config, call |config()|.
53 void AddObserver(Observer* observer); 54 void AddObserver(Observer* observer);
54 55
55 // Prevents |observer| from receiving future updates. This is safe to call 56 // Prevents |observer| from receiving future updates. This is safe to call
56 // even when the observer is being notified of an update. 57 // even when the observer is being notified of an update.
57 void RemoveObserver(Observer* observer); 58 void RemoveObserver(Observer* observer);
58 59
59 // Requests an asynchronous refresh of the DoodleConfig from the network. 60 // Requests an asynchronous refresh of the DoodleConfig from the network.
60 // After the update completes, the observers will be notified only if the 61 // After the update completes, the observers will be notified whether the
61 // config changed. 62 // config changes or active configs remain valid.
Marc Treib 2017/04/27 15:22:55 s/changes/changed/ s/active configs remain/the act
fhorschig 2017/04/28 08:20:07 Done.
62 void Refresh(); 63 void Refresh();
63 64
64 private: 65 private:
65 // Note: Keep in sync with the corresponding enum in histograms.xml. Never 66 // Note: Keep in sync with the corresponding enum in histograms.xml. Never
66 // remove values, and only insert new values at the end. 67 // remove values, and only insert new values at the end.
67 enum DownloadOutcome { 68 enum DownloadOutcome {
68 OUTCOME_NEW_DOODLE = 0, 69 OUTCOME_NEW_DOODLE = 0,
69 OUTCOME_REVALIDATED_DOODLE = 1, 70 OUTCOME_REVALIDATED_DOODLE = 1,
70 OUTCOME_CHANGED_DOODLE = 2, 71 OUTCOME_CHANGED_DOODLE = 2,
71 OUTCOME_NO_DOODLE = 3, 72 OUTCOME_NO_DOODLE = 3,
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 126
126 // The list of observers to be notified when the DoodleConfig changes. 127 // The list of observers to be notified when the DoodleConfig changes.
127 base::ObserverList<Observer> observers_; 128 base::ObserverList<Observer> observers_;
128 129
129 DISALLOW_COPY_AND_ASSIGN(DoodleService); 130 DISALLOW_COPY_AND_ASSIGN(DoodleService);
130 }; 131 };
131 132
132 } // namespace doodle 133 } // namespace doodle
133 134
134 #endif // COMPONENTS_DOODLE_DOODLE_SERVICE_H_ 135 #endif // COMPONENTS_DOODLE_DOODLE_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698