• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright (C) 2013 The Android Open Source Project
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 #ifndef SHILL_ETHERNET_ETHERNET_EAP_PROVIDER_H_
18 #define SHILL_ETHERNET_ETHERNET_EAP_PROVIDER_H_
19 
20 #include <map>
21 #include <string>
22 
23 #include <base/callback.h>
24 
25 #include "shill/provider_interface.h"
26 #include "shill/refptr_types.h"
27 
28 namespace shill {
29 
30 class ControlInterface;
31 class Error;
32 class Ethernet;
33 class EventDispatcher;
34 class KeyValueStore;
35 class Manager;
36 class Metrics;
37 
38 class EthernetEapProvider : public ProviderInterface {
39  public:
40   typedef base::Callback<void()> CredentialChangeCallback;
41 
42   EthernetEapProvider(ControlInterface* control_interface,
43                       EventDispatcher* dispatcher,
44                       Metrics* metrics,
45                       Manager* manager);
46   ~EthernetEapProvider() override;
47 
48   // Called by Manager as a part of the Provider interface.
49   void CreateServicesFromProfile(const ProfileRefPtr& profile) override;
50   ServiceRefPtr GetService(const KeyValueStore& args, Error* error) override;
51   ServiceRefPtr FindSimilarService(
52       const KeyValueStore& args, Error* error) const override;
53   ServiceRefPtr CreateTemporaryService(
54       const KeyValueStore& args, Error* error) override;
55   ServiceRefPtr CreateTemporaryServiceFromProfile(
56       const ProfileRefPtr& profile,
57       const std::string& entry_name,
58       Error* error) override;
59   void Start() override;
60   void Stop() override;
61 
service()62   virtual const ServiceRefPtr& service() const { return service_; }
63 
64   // Notify |device| via |callback| when EAP credentials have changed.
65   // Any previous callbacks for |device| are removed.  |device| is
66   // only used a key to a map and is never dereferenced.
67   virtual void SetCredentialChangeCallback(Ethernet* device,
68                                            CredentialChangeCallback callback);
69 
70   // Clear any previously registered callback for |device|.
71   virtual void ClearCredentialChangeCallback(Ethernet* device);
72 
73   // Called by |service_| when EAP credentials are changed.  Notify all
74   // listening Ethernet devices.
75   virtual void OnCredentialsChanged() const;
76 
77  private:
78   friend class EthernetEapProviderTest;
79   friend class EthernetTest;
80   friend class ManagerTest;
81 
82   // Used only in Ethernet and Manager unit tests.
83   // TODO(gauravsh): Remove this and allow mocks to work correctly
84   // crbug.com/232134
set_service(const ServiceRefPtr & service)85   void set_service(const ServiceRefPtr& service) { service_ = service; }
86 
87   typedef std::map<Ethernet*, CredentialChangeCallback> CallbackMap;
88 
89   // Representative service on which EAP credentials are configured.
90   ServiceRefPtr service_;
91 
92   // Keyed set of notifiers to call when the EAP credentials for |service_|
93   // have changed.
94   CallbackMap callback_map_;
95 
96   ControlInterface* control_interface_;
97   EventDispatcher* dispatcher_;
98   Metrics* metrics_;
99   Manager* manager_;
100 };
101 
102 }  // namespace shill
103 
104 #endif  // SHILL_ETHERNET_ETHERNET_EAP_PROVIDER_H_
105