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

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

Issue 2710003006: [Doodle] Introduce a DoodleService (Closed)
Patch Set: comment Created 3 years, 9 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
« no previous file with comments | « components/doodle/doodle_fetcher_impl.cc ('k') | components/doodle/doodle_service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef COMPONENTS_DOODLE_DOODLE_SERVICE_H_
6 #define COMPONENTS_DOODLE_DOODLE_SERVICE_H_
7
8 #include <memory>
9
10 #include "base/macros.h"
11 #include "base/observer_list.h"
12 #include "base/optional.h"
13 #include "components/doodle/doodle_fetcher.h"
14 #include "components/doodle/doodle_types.h"
15
16 namespace doodle {
17
18 class DoodleService {
19 public:
20 class Observer {
21 public:
22 virtual void OnDoodleConfigUpdated(const base::Optional<DoodleConfig>&) = 0;
23 };
24
25 DoodleService(std::unique_ptr<DoodleFetcher> fetcher);
26 ~DoodleService();
27
28 // Returns the current (cached) config, if any.
29 const base::Optional<DoodleConfig>& config() const { return cached_config_; }
30
31 // Adds a new observer to the service. It'll only be called when the config
32 // changes; to get the current (cached) config, call |config()|.
33 void AddObserver(Observer* observer);
34
35 // Prevents |observer| from receiving future updates. This is safe to call
36 // even when the observer is being notified of an update.
37 void RemoveObserver(Observer* observer);
38
39 // Requests an asynchronous refresh of the DoodleConfig from the network.
40 // After the update completes, the observers will be notified only if the
41 // config changed.
42 void Refresh();
43
44 private:
45 void DoodleFetched(DoodleState state,
46 const base::Optional<DoodleConfig>& doodle_config);
47
48 // The fetcher for getting fresh DoodleConfigs from the network.
49 std::unique_ptr<DoodleFetcher> fetcher_;
50
51 // The result of the last network fetch.
52 base::Optional<DoodleConfig> cached_config_;
53
54 // The list of observers to be notified when the DoodleConfig changes.
55 base::ObserverList<Observer> observers_;
56
57 DISALLOW_COPY_AND_ASSIGN(DoodleService);
58 };
59
60 } // namespace doodle
61
62 #endif // COMPONENTS_DOODLE_DOODLE_SERVICE_H_
OLDNEW
« no previous file with comments | « components/doodle/doodle_fetcher_impl.cc ('k') | components/doodle/doodle_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698