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

Unified Diff: components/doodle/doodle_service.h

Issue 2710003006: [Doodle] Introduce a DoodleService (Closed)
Patch Set: comment Created 3 years, 10 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/doodle/doodle_service.h
diff --git a/components/doodle/doodle_service.h b/components/doodle/doodle_service.h
new file mode 100644
index 0000000000000000000000000000000000000000..09e1ae1f9504fa2db23bf1f3d6f7dfb657f70673
--- /dev/null
+++ b/components/doodle/doodle_service.h
@@ -0,0 +1,62 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef COMPONENTS_DOODLE_DOODLE_SERVICE_H_
+#define COMPONENTS_DOODLE_DOODLE_SERVICE_H_
+
+#include <memory>
+
+#include "base/macros.h"
+#include "base/observer_list.h"
+#include "base/optional.h"
+#include "components/doodle/doodle_fetcher.h"
+#include "components/doodle/doodle_types.h"
+
+namespace doodle {
+
+class DoodleService {
+ public:
+ class Observer {
+ public:
+ virtual void OnDoodleConfigUpdated(const base::Optional<DoodleConfig>&) = 0;
+ };
+
+ DoodleService(std::unique_ptr<DoodleFetcher> fetcher);
+ ~DoodleService();
+
+ // Returns the current (cached) config, if any.
+ const base::Optional<DoodleConfig>& config() const { return cached_config_; }
+
+ // Adds a new observer to the service. It'll only be called when the config
+ // changes; to get the current (cached) config, call |config()|.
+ void AddObserver(Observer* observer);
+
+ // Prevents |observer| from receiving future updates. This is safe to call
+ // even when the observer is being notified of an update.
+ void RemoveObserver(Observer* observer);
+
+ // Requests an asynchronous refresh of the DoodleConfig from the network.
+ // After the update completes, the observers will be notified only if the
+ // config changed.
+ void Refresh();
+
+ private:
+ void DoodleFetched(DoodleState state,
+ const base::Optional<DoodleConfig>& doodle_config);
+
+ // The fetcher for getting fresh DoodleConfigs from the network.
+ std::unique_ptr<DoodleFetcher> fetcher_;
+
+ // The result of the last network fetch.
+ base::Optional<DoodleConfig> cached_config_;
+
+ // The list of observers to be notified when the DoodleConfig changes.
+ base::ObserverList<Observer> observers_;
+
+ DISALLOW_COPY_AND_ASSIGN(DoodleService);
+};
+
+} // namespace doodle
+
+#endif // COMPONENTS_DOODLE_DOODLE_SERVICE_H_
« 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