| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ash/common/system/chromeos/network/vpn_delegate.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 |
| 9 namespace ash { |
| 10 |
| 11 VPNProvider::VPNProvider() : third_party(false) {} |
| 12 |
| 13 VPNProvider::VPNProvider(const std::string& extension_id, |
| 14 const std::string& third_party_provider_name) |
| 15 : third_party(true), |
| 16 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()); |
| 20 } |
| 21 |
| 22 bool VPNProvider::operator==(const VPNProvider& other) const { |
| 23 return third_party == other.third_party && |
| 24 extension_id == other.extension_id && |
| 25 third_party_provider_name == other.third_party_provider_name; |
| 26 } |
| 27 |
| 28 VPNDelegate::Observer::~Observer() {} |
| 29 |
| 30 VPNDelegate::VPNDelegate() { |
| 31 AddBuiltInProvider(); |
| 32 } |
| 33 |
| 34 VPNDelegate::~VPNDelegate() {} |
| 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 |
| 44 void VPNDelegate::AddObserver(Observer* observer) { |
| 45 observer_list_.AddObserver(observer); |
| 46 } |
| 47 |
| 48 void VPNDelegate::RemoveObserver(Observer* observer) { |
| 49 observer_list_.RemoveObserver(observer); |
| 50 } |
| 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 |
| 63 void VPNDelegate::NotifyObservers() { |
| 64 for (auto& observer : observer_list_) |
| 65 observer.OnVPNProvidersChanged(); |
| 66 } |
| 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 |
| 74 } // namespace ash |
| OLD | NEW |