| OLD | NEW |
| 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 #include "ash/common/system/chromeos/network/vpn_delegate.h" | 5 #include "ash/common/system/chromeos/network/vpn_delegate.h" |
| 6 | 6 |
| 7 #include "chromeos/network/network_state.h" | 7 #include "base/logging.h" |
| 8 #include "third_party/cros_system_api/dbus/service_constants.h" | |
| 9 | 8 |
| 10 namespace ash { | 9 namespace ash { |
| 11 | 10 |
| 12 VPNProvider::Key::Key() : third_party(false) {} | 11 VPNProvider::VPNProvider() : third_party(false) {} |
| 13 | 12 |
| 14 VPNProvider::Key::Key(const std::string& extension_id) | 13 VPNProvider::VPNProvider(const std::string& extension_id, |
| 15 : third_party(true), extension_id(extension_id) {} | 14 const std::string& third_party_provider_name) |
| 16 | 15 : third_party(true), |
| 17 bool VPNProvider::Key::operator==(const Key& other) const { | 16 extension_id(extension_id), |
| 18 return other.third_party == third_party && other.extension_id == extension_id; | 17 third_party_provider_name(third_party_provider_name) { |
| 18 DCHECK(!extension_id.empty()); |
| 19 DCHECK(!third_party_provider_name.empty()); |
| 19 } | 20 } |
| 20 | 21 |
| 21 bool VPNProvider::Key::MatchesNetwork( | 22 bool VPNProvider::operator==(const VPNProvider& other) const { |
| 22 const chromeos::NetworkState& network) const { | 23 return third_party == other.third_party && |
| 23 if (network.type() != shill::kTypeVPN) | 24 extension_id == other.extension_id && |
| 24 return false; | 25 third_party_provider_name == other.third_party_provider_name; |
| 25 const bool network_uses_third_party_provider = | |
| 26 network.vpn_provider_type() == shill::kProviderThirdPartyVpn; | |
| 27 if (!third_party) | |
| 28 return !network_uses_third_party_provider; | |
| 29 return network_uses_third_party_provider && | |
| 30 network.third_party_vpn_provider_extension_id() == extension_id; | |
| 31 } | 26 } |
| 32 | 27 |
| 33 VPNProvider::VPNProvider(const Key& key, const std::string& name) | |
| 34 : key(key), name(name) {} | |
| 35 | |
| 36 VPNDelegate::Observer::~Observer() {} | 28 VPNDelegate::Observer::~Observer() {} |
| 37 | 29 |
| 38 VPNDelegate::VPNDelegate() {} | 30 VPNDelegate::VPNDelegate() { |
| 31 AddBuiltInProvider(); |
| 32 } |
| 39 | 33 |
| 40 VPNDelegate::~VPNDelegate() {} | 34 VPNDelegate::~VPNDelegate() {} |
| 41 | 35 |
| 36 bool VPNDelegate::HaveThirdPartyVPNProviders() const { |
| 37 for (const VPNProvider& provider : vpn_providers_) { |
| 38 if (provider.third_party) |
| 39 return true; |
| 40 } |
| 41 return false; |
| 42 } |
| 43 |
| 42 void VPNDelegate::AddObserver(Observer* observer) { | 44 void VPNDelegate::AddObserver(Observer* observer) { |
| 43 observer_list_.AddObserver(observer); | 45 observer_list_.AddObserver(observer); |
| 44 } | 46 } |
| 45 | 47 |
| 46 void VPNDelegate::RemoveObserver(Observer* observer) { | 48 void VPNDelegate::RemoveObserver(Observer* observer) { |
| 47 observer_list_.RemoveObserver(observer); | 49 observer_list_.RemoveObserver(observer); |
| 48 } | 50 } |
| 49 | 51 |
| 52 void VPNDelegate::SetThirdPartyVpnProviders( |
| 53 const std::vector<VPNProvider>& third_party_providers) { |
| 54 vpn_providers_.clear(); |
| 55 vpn_providers_.reserve(third_party_providers.size() + 1); |
| 56 AddBuiltInProvider(); |
| 57 // Append the extension-backed providers. |
| 58 vpn_providers_.insert(vpn_providers_.end(), third_party_providers.begin(), |
| 59 third_party_providers.end()); |
| 60 NotifyObservers(); |
| 61 } |
| 62 |
| 50 void VPNDelegate::NotifyObservers() { | 63 void VPNDelegate::NotifyObservers() { |
| 51 for (auto& observer : observer_list_) | 64 for (auto& observer : observer_list_) |
| 52 observer.OnVPNProvidersChanged(); | 65 observer.OnVPNProvidersChanged(); |
| 53 } | 66 } |
| 54 | 67 |
| 68 void VPNDelegate::AddBuiltInProvider() { |
| 69 // The VPNProvider() constructor generates the built-in provider and has no |
| 70 // extension ID. |
| 71 vpn_providers_.push_back(VPNProvider()); |
| 72 } |
| 73 |
| 55 } // namespace ash | 74 } // namespace ash |
| OLD | NEW |