Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Side by Side Diff: ash/common/system/chromeos/network/vpn_delegate.h

Issue 2510083006: chromeos: Move ownership of ash VPN provider list from chrome into ash (Closed)
Patch Set: Collapse VPNProvider::Key and VPNProvider structs Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef ASH_COMMON_SYSTEM_CHROMEOS_NETWORK_VPN_DELEGATE_H_ 5 #ifndef ASH_COMMON_SYSTEM_CHROMEOS_NETWORK_VPN_DELEGATE_H_
6 #define ASH_COMMON_SYSTEM_CHROMEOS_NETWORK_VPN_DELEGATE_H_ 6 #define ASH_COMMON_SYSTEM_CHROMEOS_NETWORK_VPN_DELEGATE_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "ash/ash_export.h" 11 #include "ash/ash_export.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/observer_list.h" 13 #include "base/observer_list.h"
14 14
15 namespace chromeos {
16 class NetworkState;
17 }
18
19 namespace ash { 15 namespace ash {
20 16
21 // Describes a VPN provider. 17 // Describes a VPN provider.
22 struct ASH_EXPORT VPNProvider { 18 struct ASH_EXPORT VPNProvider {
23 struct Key { 19 // Constructs the built-in VPN provider.
24 // Constructs a key for the built-in VPN provider. 20 VPNProvider();
25 Key();
26 21
27 // Constructs a key for a third-party VPN provider. 22 // Constructs a third-party VPN provider.
28 explicit Key(const std::string& extension_id); 23 VPNProvider(const std::string& extension_id,
24 const std::string& third_party_provider_name);
29 25
30 bool operator==(const Key& other) const; 26 bool operator==(const VPNProvider& other) const;
31 27
32 // Indicates whether |network| belongs to this VPN provider. 28 // Whether this key represents a built-in or third-party VPN provider.
33 bool MatchesNetwork(const chromeos::NetworkState& network) const; 29 bool third_party;
34 30
35 // Whether this key represents a built-in or third-party VPN provider. 31 // ID of the extension that implements this provider. Used for third-party
36 bool third_party; 32 // VPN providers only.
33 std::string extension_id;
37 34
38 // ID of the extension that implements this provider. Used for third-party 35 // Human-readable name if |third_party| is true, otherwise empty.
39 // VPN providers only. 36 std::string third_party_provider_name;
40 std::string extension_id;
41 };
42
43 VPNProvider(const Key& key, const std::string& name);
44
45 // Key that uniquely identifies this VPN provider.
46 Key key;
47
48 // Human-readable name.
49 std::string name;
50 }; 37 };
51 38
52 // This delegate provides UI code in ash, e.g. |VPNList|, with access to the 39 // This delegate provides UI code in ash, e.g. |VPNListView|, with access to the
53 // list of VPN providers enabled in the primary user's profile. The delegate 40 // list of VPN providers enabled in the primary user's profile. The delegate
54 // furthermore allows the UI code to request that a VPN provider show its "add 41 // furthermore allows the UI code to request that a VPN provider show its "add
55 // network" dialog. 42 // network" dialog.
43 // TODO(jamescook): Rename this to VpnList as part of mojo conversion because it
44 // won't be a delegate anymore.
56 class ASH_EXPORT VPNDelegate { 45 class ASH_EXPORT VPNDelegate {
57 public: 46 public:
58 // An observer that is notified whenever the list of VPN providers enabled in 47 // An observer that is notified whenever the list of VPN providers enabled in
59 // the primary user's profile changes. 48 // the primary user's profile changes.
60 class Observer { 49 class Observer {
61 public: 50 public:
62 virtual void OnVPNProvidersChanged() = 0; 51 virtual void OnVPNProvidersChanged() = 0;
63 52
64 protected: 53 protected:
65 virtual ~Observer(); 54 virtual ~Observer();
66 55
67 private: 56 private:
68 DISALLOW_ASSIGN(Observer); 57 DISALLOW_ASSIGN(Observer);
69 }; 58 };
70 59
71 VPNDelegate(); 60 VPNDelegate();
72 virtual ~VPNDelegate(); 61 virtual ~VPNDelegate();
73 62
63 const std::vector<VPNProvider>& vpn_providers() { return vpn_providers_; }
64
74 // Returns |true| if at least one third-party VPN provider is enabled in the 65 // Returns |true| if at least one third-party VPN provider is enabled in the
75 // primary user's profile, in addition to the built-in OpenVPN/L2TP provider. 66 // primary user's profile, in addition to the built-in OpenVPN/L2TP provider.
76 virtual bool HaveThirdPartyVPNProviders() const = 0; 67 bool HaveThirdPartyVPNProviders() const;
77 68
78 // Returns the list of VPN providers enabled in the primary user's profile. 69 // Requests that the third-party VPN provider identified by |extension_id|
79 virtual const std::vector<VPNProvider>& GetVPNProviders() const = 0; 70 // show its "add network" dialog. If |extension_id| is empty then the built-in
80 71 // VPN provider's dialog is shown.
81 // Requests that the VPN provider identified by |key| show its "add network" 72 virtual void ShowAddPage(const std::string& extension_id) = 0;
82 // dialog.
83 virtual void ShowAddPage(const VPNProvider::Key& key) = 0;
84 73
85 void AddObserver(Observer* observer); 74 void AddObserver(Observer* observer);
86 void RemoveObserver(Observer* observer); 75 void RemoveObserver(Observer* observer);
87 76
88 protected: 77 // Sets the list of extension-backed VPN providers. The list may be empty.
78 // Notifies observers. Public for testing.
79 // TODO(jamescook): Convert to mojo interface.
80 void SetThirdPartyVpnProviders(
81 const std::vector<VPNProvider>& third_party_providers);
82
83 private:
89 // Notify observers that the list of VPN providers enabled in the primary 84 // Notify observers that the list of VPN providers enabled in the primary
90 // user's profile has changed. 85 // user's profile has changed.
91 void NotifyObservers(); 86 void NotifyObservers();
92 87
93 private: 88 // Adds the built-in OpenVPN/L2TP provider to |vpn_providers_|.
89 void AddBuiltInProvider();
90
91 // Cache of VPN providers, including the built-in OpenVPN/L2TP provider and
92 // other providers added by extensions in the primary user's profile.
93 std::vector<VPNProvider> vpn_providers_;
94
94 base::ObserverList<Observer> observer_list_; 95 base::ObserverList<Observer> observer_list_;
95 96
96 DISALLOW_COPY_AND_ASSIGN(VPNDelegate); 97 DISALLOW_COPY_AND_ASSIGN(VPNDelegate);
97 }; 98 };
98 99
99 } // namespace ash 100 } // namespace ash
100 101
101 #endif // ASH_COMMON_SYSTEM_CHROMEOS_NETWORK_VPN_DELEGATE_H_ 102 #endif // ASH_COMMON_SYSTEM_CHROMEOS_NETWORK_VPN_DELEGATE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698