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" |
Himanshu Jaju | 73ff957 | 2020-01-20 12:23:45 | [diff] [blame] | 14 | #include "components/sync/protocol/device_info_specifics.pb.h" |
Richard Knoll | cd7072bf | 2019-11-14 16:36:14 | [diff] [blame] | 15 | |
| 16 | namespace syncer { |
| 17 | class DeviceInfo; |
| 18 | } // namespace syncer |
| 19 | |
| 20 | class SharingDeviceSource { |
| 21 | public: |
| 22 | SharingDeviceSource(); |
| 23 | virtual ~SharingDeviceSource(); |
| 24 | |
| 25 | // Returns if the source is ready. Calling GetAllDevices before this is true |
| 26 | // returns an empty list. |
| 27 | virtual bool IsReady() = 0; |
| 28 | |
| 29 | // Returns the device matching |guid|, or nullptr if no match was found. |
| 30 | virtual std::unique_ptr<syncer::DeviceInfo> GetDeviceByGuid( |
| 31 | const std::string& guid) = 0; |
| 32 | |
Himanshu Jaju | 73ff957 | 2020-01-20 12:23:45 | [diff] [blame] | 33 | // Returns all device candidates for |required_feature|. Internally filters |
| 34 | // out older devices and returns them in (not strictly) decreasing order of |
| 35 | // last updated timestamp. |
| 36 | virtual std::vector<std::unique_ptr<syncer::DeviceInfo>> GetDeviceCandidates( |
| 37 | sync_pb::SharingSpecificFields::EnabledFeatures required_feature) = 0; |
Richard Knoll | cd7072bf | 2019-11-14 16:36:14 | [diff] [blame] | 38 | |
Michael van Ouwerkerk | 889fff1 | 2019-12-13 17:29:29 | [diff] [blame] | 39 | // Adds a callback to be run when the SharingDeviceSource is ready. If a |
| 40 | // callback is added when it is already ready, it will be run immediately. |
Richard Knoll | cd7072bf | 2019-11-14 16:36:14 | [diff] [blame] | 41 | void AddReadyCallback(base::OnceClosure callback); |
| 42 | |
| 43 | protected: |
| 44 | void MaybeRunReadyCallbacks(); |
| 45 | |
| 46 | private: |
| 47 | std::vector<base::OnceClosure> ready_callbacks_; |
| 48 | |
| 49 | DISALLOW_COPY_AND_ASSIGN(SharingDeviceSource); |
| 50 | }; |
| 51 | |
| 52 | #endif // CHROME_BROWSER_SHARING_SHARING_DEVICE_SOURCE_H_ |