blob: c3a509fd9ad3c2217d9901adf5d24dae2d0dfafa [file] [log] [blame]
Richard Knollcd7072bf2019-11-14 16:36:141// 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 Jaju73ff9572020-01-20 12:23:4514#include "components/sync/protocol/device_info_specifics.pb.h"
Richard Knollcd7072bf2019-11-14 16:36:1415
16namespace syncer {
17class DeviceInfo;
18} // namespace syncer
19
20class 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 Jaju73ff9572020-01-20 12:23:4533 // 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 Knollcd7072bf2019-11-14 16:36:1438
Michael van Ouwerkerk889fff12019-12-13 17:29:2939 // 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 Knollcd7072bf2019-11-14 16:36:1441 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_