Richard Knoll | cd7072bf | 2019-11-14 16:36:14 | [diff] [blame] | 1 | // Copyright 2019 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_SHARING_SHARING_DEVICE_SOURCE_H_ |
| 6 | #define CHROME_BROWSER_SHARING_SHARING_DEVICE_SOURCE_H_ |
| 7 | |
| 8 | #include <memory> |
| 9 | #include <string> |
| 10 | #include <vector> |
| 11 | |
| 12 | #include "base/callback_forward.h" |
| 13 | #include "base/macros.h" |
| 14 | |
| 15 | namespace syncer { |
| 16 | class DeviceInfo; |
| 17 | } // namespace syncer |
| 18 | |
| 19 | class SharingDeviceSource { |
| 20 | public: |
| 21 | SharingDeviceSource(); |
| 22 | virtual ~SharingDeviceSource(); |
| 23 | |
| 24 | // Returns if the source is ready. Calling GetAllDevices before this is true |
| 25 | // returns an empty list. |
| 26 | virtual bool IsReady() = 0; |
| 27 | |
| 28 | // Returns the device matching |guid|, or nullptr if no match was found. |
| 29 | virtual std::unique_ptr<syncer::DeviceInfo> GetDeviceByGuid( |
| 30 | const std::string& guid) = 0; |
| 31 | |
| 32 | // Returns all devices found. |
| 33 | virtual std::vector<std::unique_ptr<syncer::DeviceInfo>> GetAllDevices() = 0; |
| 34 | |
Michael van Ouwerkerk | 889fff1 | 2019-12-13 17:29:29 | [diff] [blame^] | 35 | // Adds a callback to be run when the SharingDeviceSource is ready. If a |
| 36 | // callback is added when it is already ready, it will be run immediately. |
Richard Knoll | cd7072bf | 2019-11-14 16:36:14 | [diff] [blame] | 37 | void AddReadyCallback(base::OnceClosure callback); |
| 38 | |
| 39 | protected: |
| 40 | void MaybeRunReadyCallbacks(); |
| 41 | |
| 42 | private: |
| 43 | std::vector<base::OnceClosure> ready_callbacks_; |
| 44 | |
| 45 | DISALLOW_COPY_AND_ASSIGN(SharingDeviceSource); |
| 46 | }; |
| 47 | |
| 48 | #endif // CHROME_BROWSER_SHARING_SHARING_DEVICE_SOURCE_H_ |