Index: chrome/browser/search/one_google_bar/one_google_bar_service.h |
diff --git a/chrome/browser/search/one_google_bar/one_google_bar_service.h b/chrome/browser/search/one_google_bar/one_google_bar_service.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..11dde85dee0b6ace5a3ed8eb2d7e5f9522a9715e |
--- /dev/null |
+++ b/chrome/browser/search/one_google_bar/one_google_bar_service.h |
@@ -0,0 +1,59 @@ |
+// 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 CHROME_BROWSER_SEARCH_ONE_GOOGLE_BAR_ONE_GOOGLE_BAR_SERVICE_H_ |
+#define CHROME_BROWSER_SEARCH_ONE_GOOGLE_BAR_ONE_GOOGLE_BAR_SERVICE_H_ |
+ |
+#include <memory> |
+ |
+#include "base/observer_list.h" |
+#include "base/optional.h" |
+#include "chrome/browser/search/one_google_bar/one_google_bar_data.h" |
+#include "chrome/browser/search/one_google_bar/one_google_bar_service_observer.h" |
+#include "components/keyed_service/core/keyed_service.h" |
+ |
+class OneGoogleBarFetcher; |
+class SigninManagerBase; |
+ |
+// A service that downloads, caches, and hands out OneGoogleBarData. |
sfiera
2017/04/13 15:18:31
I'd like a little detail about what is expected to
Marc Treib
2017/04/13 15:44:02
It never initiates fetches itself. Comment added.
|
+class OneGoogleBarService : public KeyedService { |
sfiera
2017/04/13 15:18:31
No expected need to split this into interface/impl
Marc Treib
2017/04/13 15:44:02
Nope :)
|
+ public: |
+ OneGoogleBarService(SigninManagerBase* signin_manager, |
+ std::unique_ptr<OneGoogleBarFetcher> fetcher); |
+ ~OneGoogleBarService() override; |
+ |
+ // KeyedService implementation. |
+ void Shutdown() override; |
+ |
+ // Returns the currently cached OneGoogleBarData, if any. |
+ const base::Optional<OneGoogleBarData>& one_google_bar_data() const { |
+ return one_google_bar_data_; |
+ } |
+ |
+ // Requests an asynchronous refresh from the network. After the update |
+ // completes, the observers will be notified only if something changed. |
+ void Refresh(); |
sfiera
2017/04/13 15:18:31
For my curiosity, who are you expecting to call th
Marc Treib
2017/04/13 15:44:02
The plan was: Open NTP, immediately serve the cach
sfiera
2017/04/13 15:58:33
Do we have a list of all of the places we have thi
Marc Treib
2017/04/13 16:45:15
That seems to be quite a comprehensive list; I can
|
+ |
+ // Add/remove observers. All observers must unregister themselves before the |
+ // OneGoogleBarService is destroyed. |
+ void AddObserver(OneGoogleBarServiceObserver* observer); |
+ void RemoveObserver(OneGoogleBarServiceObserver* observer); |
+ |
+ private: |
+ class SigninObserver; |
+ |
+ void SigninStatusChanged(); |
+ |
+ void SetOneGoogleBarData(const base::Optional<OneGoogleBarData>& data); |
+ |
+ std::unique_ptr<OneGoogleBarFetcher> fetcher_; |
+ |
+ std::unique_ptr<SigninObserver> signin_observer_; |
+ |
+ base::ObserverList<OneGoogleBarServiceObserver, true> observers_; |
+ |
+ base::Optional<OneGoogleBarData> one_google_bar_data_; |
+}; |
+ |
+#endif // CHROME_BROWSER_SEARCH_ONE_GOOGLE_BAR_ONE_GOOGLE_BAR_SERVICE_H_ |