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

Unified Diff: chrome/browser/resources/options/chromeos/vpn_providers.js

Issue 1006553002: Add third-party VPN support to network details dialog (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@f_2_460428_add_ash_ui
Patch Set: Prepare for removal of GetManagedPropertiesResult() by tracking VPN providers and networks separate… Created 5 years, 9 months 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/options/chromeos/vpn_providers.js
diff --git a/chrome/browser/resources/options/chromeos/vpn_providers.js b/chrome/browser/resources/options/chromeos/vpn_providers.js
new file mode 100644
index 0000000000000000000000000000000000000000..ba056ecbead732267ee5f27f990762a0c6a43d3d
--- /dev/null
+++ b/chrome/browser/resources/options/chromeos/vpn_providers.js
@@ -0,0 +1,102 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+/**
+ * @fileoverview A singleton that keeps track of the VPN providers enabled in
+ * the primary user's profile.
+ */
+
+cr.define('options', function() {
+ /**
+ * @constructor
+ */
+ function VPNProviders() {
+ }
+
+ cr.addSingletonGetter(VPNProviders);
+
+ VPNProviders.prototype = {
+ /**
+ * The VPN providers enabled in the primary user's profile. This is a
+ * mapping from provider ID to provider name. For third-party VPN providers,
+ * the provider ID is an extension ID. For the built-in OpenVPN/L2TP
+ * provider, the ID is 'built-in'.
+ * @type {Object.<string, string>}
michaelpg 2015/03/16 05:45:20 nit (25,62,70): dot (.) no longer required for arr
bartfab (slow) 2015/03/16 10:04:51 Done.
+ * @private
+ */
+ providers_: {},
+
+ /**
+ * Determines whether |provider_id| belongs to a third-party VPN provider.
+ * @param {string} provider_id The VPN provider ID.
+ * @return {boolean} True if the ID belongs to a third-party VPN provider.
+ * @private
+ */
+ isThirdPartyProvider_(provider_id) {
+ return provider_id != 'built-in';
+ },
+
+ /**
+ * Formats a network name for display purposes. If the network belongs to
+ * a third-party VPN provider, the provider name is added to the network
+ * name.
+ * @param {string} provider_id The VPN provider ID for this network.
+ * @param {string} network_name The network name.
+ * @return {string} The resulting display name.
+ * @private
+ */
+ formatNetworkName_(provider_id, network_name) {
+ if (!this.isThirdPartyProvider_(provider_id) ||
+ !(provider_id in this.providers_)) {
+ return network_name;
+ }
+ return loadTimeData.getStringF('vpnNameTemplate',
+ this.providers_[provider_id],
+ network_name);
+ },
+ };
+
+ /**
+ * Returns the list of VPN providers enabled in the primary user's profile.
+ * @return {Object.<string, string>} A mapping from VPN provider ID to name.
+ */
+ VPNProviders.getProviders = function() {
+ return VPNProviders.getInstance().providers_;
+ };
+
+ /**
+ * Replaces the list of VPN providers enabled in the primary user's profile.
+ * @param {Object.<string, string>} providers A mapping from VPN provider ID
+ * to name.
+ */
+ VPNProviders.setProviders = function(providers) {
+ VPNProviders.getInstance().providers_ = providers;
+ };
+
+ /**
+ * Determines whether |provider_id| belongs to a third-party VPN provider.
+ * @param {string} provider_id The VPN provider ID.
+ * @return {boolean} True if the ID belongs to a third-party VPN provider.
+ */
+ VPNProviders.isThirdPartyProvider = function(provider_id) {
+ return VPNProviders.getInstance().isThirdPartyProvider_(provider_id);
+ };
+
+ /**
+ * Formats a network name for display purposes. If the network belongs to a
+ * third-party VPN provider, the provider name is added to the network name.
+ * @param {string} provider_id The VPN provider ID for this network.
+ * @param {string} network_name The network name.
+ * @return {string} The resulting display name.
+ */
+ VPNProviders.formatNetworkName = function(provider_id, network_name) {
+ return VPNProviders.getInstance().formatNetworkName_(provider_id,
+ network_name);
+ };
+
+ // Export
+ return {
+ VPNProviders: VPNProviders
+ };
+});

Powered by Google App Engine
This is Rietveld 408576698