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

Side by Side Diff: chrome/browser/ui/ash/vpn_delegate_chromeos.cc

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 #include "chrome/browser/ui/ash/vpn_delegate_chromeos.h" 5 #include "chrome/browser/ui/ash/vpn_delegate_chromeos.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/threading/thread_task_runner_handle.h" 10 #include "base/threading/thread_task_runner_handle.h"
11 #include "chrome/browser/chrome_notification_types.h" 11 #include "chrome/browser/chrome_notification_types.h"
12 #include "chrome/browser/chromeos/profiles/profile_helper.h" 12 #include "chrome/browser/chromeos/profiles/profile_helper.h"
13 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/ui/ash/system_tray_client.h" 14 #include "chrome/browser/ui/ash/system_tray_client.h"
15 #include "chrome/grit/generated_resources.h"
16 #include "components/user_manager/user.h" 15 #include "components/user_manager/user.h"
17 #include "components/user_manager/user_manager.h" 16 #include "components/user_manager/user_manager.h"
18 #include "content/public/browser/notification_service.h" 17 #include "content/public/browser/notification_service.h"
19 #include "content/public/browser/notification_source.h" 18 #include "content/public/browser/notification_source.h"
20 #include "extensions/browser/api/vpn_provider/vpn_service.h" 19 #include "extensions/browser/api/vpn_provider/vpn_service.h"
21 #include "extensions/browser/api/vpn_provider/vpn_service_factory.h" 20 #include "extensions/browser/api/vpn_provider/vpn_service_factory.h"
22 #include "extensions/browser/extension_registry.h" 21 #include "extensions/browser/extension_registry.h"
23 #include "extensions/common/extension.h" 22 #include "extensions/common/extension.h"
24 #include "extensions/common/extension_set.h" 23 #include "extensions/common/extension_set.h"
25 #include "extensions/common/permissions/api_permission.h" 24 #include "extensions/common/permissions/api_permission.h"
(...skipping 30 matching lines...) Expand all
56 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CREATED, 55 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CREATED,
57 content::NotificationService::AllSources()); 56 content::NotificationService::AllSources());
58 } 57 }
59 } 58 }
60 59
61 VPNDelegateChromeOS::~VPNDelegateChromeOS() { 60 VPNDelegateChromeOS::~VPNDelegateChromeOS() {
62 if (extension_registry_) 61 if (extension_registry_)
63 extension_registry_->RemoveObserver(this); 62 extension_registry_->RemoveObserver(this);
64 } 63 }
65 64
66 bool VPNDelegateChromeOS::HaveThirdPartyVPNProviders() const { 65 void VPNDelegateChromeOS::ShowAddPage(const std::string& extension_id) {
67 for (const ash::VPNProvider& provider : vpn_providers_) { 66 if (extension_id.empty()) {
68 if (provider.key.third_party)
69 return true;
70 }
71 return false;
72 }
73
74 const std::vector<ash::VPNProvider>& VPNDelegateChromeOS::GetVPNProviders()
75 const {
76 return vpn_providers_;
77 }
78
79 void VPNDelegateChromeOS::ShowAddPage(const ash::VPNProvider::Key& key) {
80 if (!key.third_party) {
81 // Show the "add network" dialog for the built-in OpenVPN/L2TP provider. 67 // Show the "add network" dialog for the built-in OpenVPN/L2TP provider.
82 SystemTrayClient::Get()->ShowNetworkCreate(shill::kTypeVPN); 68 SystemTrayClient::Get()->ShowNetworkCreate(shill::kTypeVPN);
83 return; 69 return;
84 } 70 }
85 71
86 Profile* const profile = GetProfileForPrimaryUser(); 72 Profile* const profile = GetProfileForPrimaryUser();
87 if (!profile) 73 if (!profile)
88 return; 74 return;
89 75
90 // Request that the third-party VPN provider identified by |key.extension_id| 76 // Request that the third-party VPN provider identified by |key.extension_id|
91 // show its "add network" dialog. 77 // show its "add network" dialog.
92 chromeos::VpnServiceFactory::GetForBrowserContext(profile) 78 chromeos::VpnServiceFactory::GetForBrowserContext(profile)
93 ->SendShowAddDialogToExtension(key.extension_id); 79 ->SendShowAddDialogToExtension(extension_id);
94 } 80 }
95 81
96 void VPNDelegateChromeOS::OnExtensionLoaded( 82 void VPNDelegateChromeOS::OnExtensionLoaded(
97 content::BrowserContext* browser_context, 83 content::BrowserContext* browser_context,
98 const extensions::Extension* extension) { 84 const extensions::Extension* extension) {
99 if (IsVPNProvider(extension)) 85 if (IsVPNProvider(extension))
100 UpdateVPNProviders(); 86 UpdateVPNProviders();
101 } 87 }
102 88
103 void VPNDelegateChromeOS::OnExtensionUnloaded( 89 void VPNDelegateChromeOS::OnExtensionUnloaded(
(...skipping 29 matching lines...) Expand all
133 registrar_.RemoveAll(); 119 registrar_.RemoveAll();
134 base::ThreadTaskRunnerHandle::Get()->PostTask( 120 base::ThreadTaskRunnerHandle::Get()->PostTask(
135 FROM_HERE, 121 FROM_HERE,
136 base::Bind(&VPNDelegateChromeOS::AttachToPrimaryUserExtensionRegistry, 122 base::Bind(&VPNDelegateChromeOS::AttachToPrimaryUserExtensionRegistry,
137 weak_factory_.GetWeakPtr())); 123 weak_factory_.GetWeakPtr()));
138 } 124 }
139 125
140 void VPNDelegateChromeOS::UpdateVPNProviders() { 126 void VPNDelegateChromeOS::UpdateVPNProviders() {
141 DCHECK(extension_registry_); 127 DCHECK(extension_registry_);
142 128
143 vpn_providers_.clear(); 129 std::vector<ash::VPNProvider> third_party_providers;
144 for (const auto& extension : extension_registry_->enabled_extensions()) { 130 for (const auto& extension : extension_registry_->enabled_extensions()) {
145 if (IsVPNProvider(extension.get())) { 131 if (IsVPNProvider(extension.get())) {
146 vpn_providers_.push_back(ash::VPNProvider( 132 third_party_providers.push_back(
147 ash::VPNProvider::Key(extension->id()), extension->name())); 133 ash::VPNProvider(extension->id(), extension->name()));
148 } 134 }
149 } 135 }
150 // Add the built-in OpenVPN/L2TP provider. The ash::VPNProvider::Key()
151 // constructor generates a key that identifies that built-in provider and has
152 // no extension ID.
153 vpn_providers_.push_back(ash::VPNProvider(
154 ash::VPNProvider::Key(),
155 l10n_util::GetStringUTF8(IDS_NETWORK_VPN_BUILT_IN_PROVIDER)));
156 136
157 NotifyObservers(); 137 // Ash adds the built-in OpenVPN/L2TP provider.
138 SetThirdPartyVpnProviders(third_party_providers);
158 } 139 }
159 140
160 void VPNDelegateChromeOS::AttachToPrimaryUserExtensionRegistry() { 141 void VPNDelegateChromeOS::AttachToPrimaryUserExtensionRegistry() {
161 DCHECK(!extension_registry_); 142 DCHECK(!extension_registry_);
162 extension_registry_ = 143 extension_registry_ =
163 extensions::ExtensionRegistry::Get(GetProfileForPrimaryUser()); 144 extensions::ExtensionRegistry::Get(GetProfileForPrimaryUser());
164 extension_registry_->AddObserver(this); 145 extension_registry_->AddObserver(this);
165 146
166 UpdateVPNProviders(); 147 UpdateVPNProviders();
167 } 148 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698