OLD | NEW |
(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 CHROME_BROWSER_SEARCH_ONE_GOOGLE_BAR_ONE_GOOGLE_BAR_SERVICE_H_ |
| 6 #define CHROME_BROWSER_SEARCH_ONE_GOOGLE_BAR_ONE_GOOGLE_BAR_SERVICE_H_ |
| 7 |
| 8 #include <memory> |
| 9 |
| 10 #include "base/observer_list.h" |
| 11 #include "base/optional.h" |
| 12 #include "chrome/browser/search/one_google_bar/one_google_bar_data.h" |
| 13 #include "chrome/browser/search/one_google_bar/one_google_bar_service_observer.h
" |
| 14 #include "components/keyed_service/core/keyed_service.h" |
| 15 |
| 16 class OneGoogleBarFetcher; |
| 17 class SigninManagerBase; |
| 18 |
| 19 // A service that downloads, caches, and hands out OneGoogleBarData. It never |
| 20 // initiates a download automatically, only when Refresh is called. When the |
| 21 // user signs in or out, the cached value is cleared. |
| 22 class OneGoogleBarService : public KeyedService { |
| 23 public: |
| 24 OneGoogleBarService(SigninManagerBase* signin_manager, |
| 25 std::unique_ptr<OneGoogleBarFetcher> fetcher); |
| 26 ~OneGoogleBarService() override; |
| 27 |
| 28 // KeyedService implementation. |
| 29 void Shutdown() override; |
| 30 |
| 31 // Returns the currently cached OneGoogleBarData, if any. |
| 32 const base::Optional<OneGoogleBarData>& one_google_bar_data() const { |
| 33 return one_google_bar_data_; |
| 34 } |
| 35 |
| 36 // Requests an asynchronous refresh from the network. After the update |
| 37 // completes, the observers will be notified only if something changed. |
| 38 void Refresh(); |
| 39 |
| 40 // Add/remove observers. All observers must unregister themselves before the |
| 41 // OneGoogleBarService is destroyed. |
| 42 void AddObserver(OneGoogleBarServiceObserver* observer); |
| 43 void RemoveObserver(OneGoogleBarServiceObserver* observer); |
| 44 |
| 45 private: |
| 46 class SigninObserver; |
| 47 |
| 48 void SigninStatusChanged(); |
| 49 |
| 50 void SetOneGoogleBarData(const base::Optional<OneGoogleBarData>& data); |
| 51 |
| 52 std::unique_ptr<OneGoogleBarFetcher> fetcher_; |
| 53 |
| 54 std::unique_ptr<SigninObserver> signin_observer_; |
| 55 |
| 56 base::ObserverList<OneGoogleBarServiceObserver, true> observers_; |
| 57 |
| 58 base::Optional<OneGoogleBarData> one_google_bar_data_; |
| 59 }; |
| 60 |
| 61 #endif // CHROME_BROWSER_SEARCH_ONE_GOOGLE_BAR_ONE_GOOGLE_BAR_SERVICE_H_ |
OLD | NEW |