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 CHROMEOS_COMPONENTS_SYNC_WIFI_LOCAL_NETWORK_COLLECTOR_H_
6 #define CHROMEOS_COMPONENTS_SYNC_WIFI_LOCAL_NETWORK_COLLECTOR_H_
7 
8 #include <string>
9 #include <vector>
10 
11 #include "base/memory/weak_ptr.h"
12 #include "base/optional.h"
13 #include "chromeos/components/sync_wifi/network_identifier.h"
14 #include "chromeos/services/network_config/public/mojom/cros_network_config.mojom.h"
15 #include "mojo/public/cpp/bindings/receiver.h"
16 
17 namespace sync_pb {
18 class WifiConfigurationSpecifics;
19 }
20 
21 namespace chromeos {
22 
23 class NetworkMetadataStore;
24 
25 namespace sync_wifi {
26 
27 // Handles the retrieval, filtering, and conversion of local network
28 // configurations to syncable protos.
29 class LocalNetworkCollector {
30  public:
31   typedef base::OnceCallback<void(
32       base::Optional<sync_pb::WifiConfigurationSpecifics>)>
33       ProtoCallback;
34 
35   typedef base::OnceCallback<void(
36       std::vector<sync_pb::WifiConfigurationSpecifics>)>
37       ProtoListCallback;
38 
39   LocalNetworkCollector() = default;
40   virtual ~LocalNetworkCollector() = default;
41 
42   // Creates a list of all local networks which are syncable and delivers them
43   // to the provided |callback|.  This excludes networks which are managed,
44   // unsecured, use enterprise security, or shared.
45   virtual void GetAllSyncableNetworks(ProtoListCallback callback) = 0;
46 
47   // Creates a WifiConfigurationSpecifics proto with the relevant network
48   // details for the network with the given |id|.  If that network doesn't
49   // exist or isn't syncable it will provide base::nullopt to the callback.
50   virtual void GetSyncableNetwork(const std::string& guid,
51                                   ProtoCallback callback) = 0;
52 
53   // Retrieves the NetworkIdentifier for a given local network's |guid|
54   // if the network no longer exists it returns nullopt.
55   virtual base::Optional<NetworkIdentifier> GetNetworkIdentifierFromGuid(
56       const std::string& guid) = 0;
57 
58   // Provides the metadata store which gets constructed later.
59   virtual void SetNetworkMetadataStore(
60       base::WeakPtr<NetworkMetadataStore> network_metadata_store) = 0;
61 };
62 
63 }  // namespace sync_wifi
64 
65 }  // namespace chromeos
66 
67 #endif  // CHROMEOS_COMPONENTS_SYNC_WIFI_LOCAL_NETWORK_COLLECTOR_H_
68