Chromium Code Reviews| 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_list.h" |
| 6 | |
| 7 #include <utility> | |
| 6 | 8 |
| 7 #include "ash/common/strings/grit/ash_strings.h" | 9 #include "ash/common/strings/grit/ash_strings.h" |
| 8 #include "chromeos/network/network_state.h" | 10 #include "chromeos/network/network_state.h" |
| 11 #include "services/service_manager/public/cpp/connector.h" | |
| 9 #include "third_party/cros_system_api/dbus/service_constants.h" | 12 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 10 #include "ui/base/l10n/l10n_util.h" | 13 #include "ui/base/l10n/l10n_util.h" |
| 11 | 14 |
| 12 namespace ash { | 15 namespace ash { |
| 13 | 16 |
| 14 VPNProvider::Key::Key() : third_party(false) {} | 17 VPNProvider::Key::Key() : third_party(false) {} |
| 15 | 18 |
| 16 VPNProvider::Key::Key(const std::string& extension_id) | 19 VPNProvider::Key::Key(const std::string& extension_id) |
| 17 : third_party(true), extension_id(extension_id) {} | 20 : third_party(true), extension_id(extension_id) {} |
| 18 | 21 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 32 network.third_party_vpn_provider_extension_id() == extension_id; | 35 network.third_party_vpn_provider_extension_id() == extension_id; |
| 33 } | 36 } |
| 34 | 37 |
| 35 VPNProvider::VPNProvider(const Key& key, const std::string& name) | 38 VPNProvider::VPNProvider(const Key& key, const std::string& name) |
| 36 : key(key), name(name) {} | 39 : key(key), name(name) {} |
| 37 | 40 |
| 38 bool VPNProvider::operator==(const VPNProvider& other) const { | 41 bool VPNProvider::operator==(const VPNProvider& other) const { |
| 39 return key == other.key && name == other.name; | 42 return key == other.key && name == other.name; |
| 40 } | 43 } |
| 41 | 44 |
| 42 VPNDelegate::Observer::~Observer() {} | 45 VpnList::Observer::~Observer() {} |
| 43 | 46 |
| 44 VPNDelegate::VPNDelegate() { | 47 VpnList::VpnList() { |
| 45 AddBuiltInProvider(); | 48 AddBuiltInProvider(); |
| 46 } | 49 } |
| 47 | 50 |
| 48 VPNDelegate::~VPNDelegate() {} | 51 VpnList::~VpnList() {} |
| 49 | 52 |
| 50 bool VPNDelegate::HaveThirdPartyVPNProviders() const { | 53 bool VpnList::HaveThirdPartyVPNProviders() const { |
| 51 for (const VPNProvider& provider : vpn_providers_) { | 54 for (const VPNProvider& provider : vpn_providers_) { |
| 52 if (provider.key.third_party) | 55 if (provider.key.third_party) |
| 53 return true; | 56 return true; |
| 54 } | 57 } |
| 55 return false; | 58 return false; |
| 56 } | 59 } |
| 57 | 60 |
| 58 void VPNDelegate::AddObserver(Observer* observer) { | 61 void VpnList::ShowAddPage(const VPNProvider::Key& key) { |
|
stevenjb
2016/11/19 00:04:58
This is kind of an odd method to have in a class n
| |
| 62 // May not be bound in tests or when running without Chrome. | |
| 63 if (!vpn_list_client_.is_bound()) | |
| 64 return; | |
| 65 | |
| 66 if (key.third_party) | |
| 67 vpn_list_client_->ShowThirdPartyAddNetworkPage(key.extension_id); | |
| 68 else | |
| 69 vpn_list_client_->ShowBuiltInAddNetworkPage(); | |
| 70 } | |
| 71 | |
| 72 void VpnList::AddObserver(Observer* observer) { | |
| 59 observer_list_.AddObserver(observer); | 73 observer_list_.AddObserver(observer); |
| 60 } | 74 } |
| 61 | 75 |
| 62 void VPNDelegate::RemoveObserver(Observer* observer) { | 76 void VpnList::RemoveObserver(Observer* observer) { |
| 63 observer_list_.RemoveObserver(observer); | 77 observer_list_.RemoveObserver(observer); |
| 64 } | 78 } |
| 65 | 79 |
| 66 void VPNDelegate::SetThirdPartyVpnProviders( | 80 void VpnList::BindRequest(mojom::VpnListRequest request) { |
| 67 const std::vector<VPNProvider>& providers) { | 81 bindings_.AddBinding(this, std::move(request)); |
| 82 } | |
| 83 | |
| 84 void VpnList::SetClient(mojom::VpnListClientPtr client) { | |
| 85 vpn_list_client_ = std::move(client); | |
| 86 } | |
| 87 | |
| 88 void VpnList::SetThirdPartyVpnProviders( | |
| 89 std::vector<mojom::ThirdPartyVpnProviderPtr> providers) { | |
| 68 // Reset the list with the extension-backed providers. | 90 // Reset the list with the extension-backed providers. |
| 69 vpn_providers_ = providers; | 91 vpn_providers_.clear(); |
| 92 vpn_providers_.reserve(providers.size() + 1); | |
| 93 for (const auto& provider : providers) { | |
| 94 VPNProvider::Key key(provider->extension_id); | |
| 95 vpn_providers_.push_back(VPNProvider(key, provider->name)); | |
| 96 } | |
| 97 // Add the OpenVPN provider. | |
| 70 AddBuiltInProvider(); | 98 AddBuiltInProvider(); |
| 71 NotifyObservers(); | 99 NotifyObservers(); |
| 72 } | 100 } |
| 73 | 101 |
| 74 void VPNDelegate::NotifyObservers() { | 102 void VpnList::NotifyObservers() { |
| 75 for (auto& observer : observer_list_) | 103 for (auto& observer : observer_list_) |
| 76 observer.OnVPNProvidersChanged(); | 104 observer.OnVPNProvidersChanged(); |
| 77 } | 105 } |
| 78 | 106 |
| 79 void VPNDelegate::AddBuiltInProvider() { | 107 void VpnList::AddBuiltInProvider() { |
| 80 // The VPNProvider::Key() constructor generates a key that identifies that | 108 // The VPNProvider::Key() constructor generates a key that identifies that |
| 81 // built-in provider and has no extension ID. | 109 // built-in provider and has no extension ID. |
| 82 vpn_providers_.push_back(VPNProvider( | 110 vpn_providers_.push_back(VPNProvider( |
| 83 VPNProvider::Key(), | 111 VPNProvider::Key(), |
| 84 l10n_util::GetStringUTF8(IDS_ASH_STATUS_TRAY_VPN_BUILT_IN_PROVIDER))); | 112 l10n_util::GetStringUTF8(IDS_ASH_STATUS_TRAY_VPN_BUILT_IN_PROVIDER))); |
| 85 } | 113 } |
| 86 | 114 |
| 87 } // namespace ash | 115 } // namespace ash |
| OLD | NEW |