Regan Hsu | 1f1aa4c | 2017-08-02 02:05:23 | [diff] [blame] | 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_CRYPTAUTH_REMOTE_DEVICE_PROVIDER_H_ |
| 6 | #define COMPONENTS_CRYPTAUTH_REMOTE_DEVICE_PROVIDER_H_ |
| 7 | |
Regan Hsu | 9fc97cc | 2017-09-08 03:13:51 | [diff] [blame] | 8 | #include "base/observer_list.h" |
Regan Hsu | 1f1aa4c | 2017-08-02 02:05:23 | [diff] [blame] | 9 | #include "components/cryptauth/remote_device.h" |
| 10 | |
| 11 | namespace cryptauth { |
| 12 | |
Regan Hsu | 1f1aa4c | 2017-08-02 02:05:23 | [diff] [blame] | 13 | // This class generates and caches RemoteDevice objects when associated metadata |
| 14 | // has been synced, and updates this cache when a new sync occurs. |
Regan Hsu | 9fc97cc | 2017-09-08 03:13:51 | [diff] [blame] | 15 | class RemoteDeviceProvider { |
Regan Hsu | 1f1aa4c | 2017-08-02 02:05:23 | [diff] [blame] | 16 | public: |
| 17 | class Observer { |
| 18 | public: |
| 19 | virtual void OnSyncDeviceListChanged() {} |
| 20 | |
| 21 | protected: |
Kyle Horimoto | cdfd4cb7c2 | 2017-12-06 00:47:55 | [diff] [blame] | 22 | virtual ~Observer() = default; |
Regan Hsu | 1f1aa4c | 2017-08-02 02:05:23 | [diff] [blame] | 23 | }; |
| 24 | |
Regan Hsu | 9fc97cc | 2017-09-08 03:13:51 | [diff] [blame] | 25 | RemoteDeviceProvider(); |
Regan Hsu | 9fc97cc | 2017-09-08 03:13:51 | [diff] [blame] | 26 | virtual ~RemoteDeviceProvider(); |
Regan Hsu | 1f1aa4c | 2017-08-02 02:05:23 | [diff] [blame] | 27 | |
Kyle Horimoto | cdfd4cb7c2 | 2017-12-06 00:47:55 | [diff] [blame] | 28 | void AddObserver(Observer* observer); |
| 29 | void RemoveObserver(Observer* observer); |
Regan Hsu | 1f1aa4c | 2017-08-02 02:05:23 | [diff] [blame] | 30 | |
| 31 | // Returns a list of all RemoteDevices that have been synced. |
Kyle Horimoto | cdfd4cb7c2 | 2017-12-06 00:47:55 | [diff] [blame] | 32 | virtual const cryptauth::RemoteDeviceList& GetSyncedDevices() const = 0; |
| 33 | |
| 34 | protected: |
| 35 | void NotifyObserversDeviceListChanged(); |
Regan Hsu | 1f1aa4c | 2017-08-02 02:05:23 | [diff] [blame] | 36 | |
| 37 | private: |
Regan Hsu | 1f1aa4c | 2017-08-02 02:05:23 | [diff] [blame] | 38 | base::ObserverList<Observer> observers_; |
Regan Hsu | 1f1aa4c | 2017-08-02 02:05:23 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | } // namespace cryptauth |
| 42 | |
| 43 | #endif // COMPONENTS_CRYPTAUTH_REMOTE_DEVICE_PROVIDER_H_ |