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

Side by Side Diff: ash/common/system/chromeos/network/vpn_list.cc

Issue 2513673004: Reland: chromeos: Convert ash VPNDelegate interface to mojo (Closed)
Patch Set: fix manifest for reland Created 4 years 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 #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 "base/logging.h" 9 #include "base/logging.h"
8 10
9 namespace ash { 11 namespace ash {
10 12
11 VPNProvider::VPNProvider() : third_party(false) {} 13 VPNProvider::VPNProvider() : third_party(false) {}
12 14
13 VPNProvider::VPNProvider(const std::string& extension_id, 15 VPNProvider::VPNProvider(const std::string& extension_id,
14 const std::string& third_party_provider_name) 16 const std::string& third_party_provider_name)
15 : third_party(true), 17 : third_party(true),
16 extension_id(extension_id), 18 extension_id(extension_id),
17 third_party_provider_name(third_party_provider_name) { 19 third_party_provider_name(third_party_provider_name) {
18 DCHECK(!extension_id.empty()); 20 DCHECK(!extension_id.empty());
19 DCHECK(!third_party_provider_name.empty()); 21 DCHECK(!third_party_provider_name.empty());
20 } 22 }
21 23
22 bool VPNProvider::operator==(const VPNProvider& other) const { 24 bool VPNProvider::operator==(const VPNProvider& other) const {
23 return third_party == other.third_party && 25 return third_party == other.third_party &&
24 extension_id == other.extension_id && 26 extension_id == other.extension_id &&
25 third_party_provider_name == other.third_party_provider_name; 27 third_party_provider_name == other.third_party_provider_name;
26 } 28 }
27 29
28 VPNDelegate::Observer::~Observer() {} 30 VpnList::Observer::~Observer() {}
29 31
30 VPNDelegate::VPNDelegate() { 32 VpnList::VpnList() {
31 AddBuiltInProvider(); 33 AddBuiltInProvider();
32 } 34 }
33 35
34 VPNDelegate::~VPNDelegate() {} 36 VpnList::~VpnList() {}
35 37
36 bool VPNDelegate::HaveThirdPartyVPNProviders() const { 38 bool VpnList::HaveThirdPartyVPNProviders() const {
37 for (const VPNProvider& provider : vpn_providers_) { 39 for (const VPNProvider& provider : vpn_providers_) {
38 if (provider.third_party) 40 if (provider.third_party)
39 return true; 41 return true;
40 } 42 }
41 return false; 43 return false;
42 } 44 }
43 45
44 void VPNDelegate::AddObserver(Observer* observer) { 46 void VpnList::AddObserver(Observer* observer) {
45 observer_list_.AddObserver(observer); 47 observer_list_.AddObserver(observer);
46 } 48 }
47 49
48 void VPNDelegate::RemoveObserver(Observer* observer) { 50 void VpnList::RemoveObserver(Observer* observer) {
49 observer_list_.RemoveObserver(observer); 51 observer_list_.RemoveObserver(observer);
50 } 52 }
51 53
52 void VPNDelegate::SetThirdPartyVpnProviders( 54 void VpnList::BindRequest(mojom::VpnListRequest request) {
53 const std::vector<VPNProvider>& third_party_providers) { 55 bindings_.AddBinding(this, std::move(request));
56 }
57
58 void VpnList::SetThirdPartyVpnProviders(
59 std::vector<mojom::ThirdPartyVpnProviderPtr> providers) {
54 vpn_providers_.clear(); 60 vpn_providers_.clear();
55 vpn_providers_.reserve(third_party_providers.size() + 1); 61 vpn_providers_.reserve(providers.size() + 1);
62 // Add the OpenVPN provider.
56 AddBuiltInProvider(); 63 AddBuiltInProvider();
57 // Append the extension-backed providers. 64 // Append the extension-backed providers.
58 vpn_providers_.insert(vpn_providers_.end(), third_party_providers.begin(), 65 for (const auto& provider : providers) {
59 third_party_providers.end()); 66 vpn_providers_.push_back(
67 VPNProvider(provider->extension_id, provider->name));
68 }
60 NotifyObservers(); 69 NotifyObservers();
61 } 70 }
62 71
63 void VPNDelegate::NotifyObservers() { 72 void VpnList::NotifyObservers() {
64 for (auto& observer : observer_list_) 73 for (auto& observer : observer_list_)
65 observer.OnVPNProvidersChanged(); 74 observer.OnVPNProvidersChanged();
66 } 75 }
67 76
68 void VPNDelegate::AddBuiltInProvider() { 77 void VpnList::AddBuiltInProvider() {
69 // The VPNProvider() constructor generates the built-in provider and has no 78 // The VPNProvider() constructor generates the built-in provider and has no
70 // extension ID. 79 // extension ID.
71 vpn_providers_.push_back(VPNProvider()); 80 vpn_providers_.push_back(VPNProvider());
72 } 81 }
73 82
74 } // namespace ash 83 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/system/chromeos/network/vpn_list.h ('k') | ash/common/system/chromeos/network/vpn_list_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698