Chromium Code Reviews| 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 /** | |
| 6 * @fileoverview A singleton that keeps track of the VPN providers enabled in | |
| 7 * the primary user's profile. | |
| 8 */ | |
| 9 | |
| 10 cr.define('options', function() { | |
| 11 /** | |
| 12 * @constructor | |
| 13 */ | |
| 14 function VPNProviders() { | |
| 15 } | |
| 16 | |
| 17 cr.addSingletonGetter(VPNProviders); | |
| 18 | |
| 19 VPNProviders.prototype = { | |
| 20 /** | |
| 21 * The VPN providers enabled in the primary user's profile. This is a | |
| 22 * mapping from provider ID to provider name. For third-party VPN providers, | |
| 23 * the provider ID is an extension ID. For the built-in OpenVPN/L2TP | |
| 24 * provider, the ID is 'built-in'. | |
| 25 * @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.
| |
| 26 * @private | |
| 27 */ | |
| 28 providers_: {}, | |
| 29 | |
| 30 /** | |
| 31 * Determines whether |provider_id| belongs to a third-party VPN provider. | |
| 32 * @param {string} provider_id The VPN provider ID. | |
| 33 * @return {boolean} True if the ID belongs to a third-party VPN provider. | |
| 34 * @private | |
| 35 */ | |
| 36 isThirdPartyProvider_(provider_id) { | |
| 37 return provider_id != 'built-in'; | |
| 38 }, | |
| 39 | |
| 40 /** | |
| 41 * Formats a network name for display purposes. If the network belongs to | |
| 42 * a third-party VPN provider, the provider name is added to the network | |
| 43 * name. | |
| 44 * @param {string} provider_id The VPN provider ID for this network. | |
| 45 * @param {string} network_name The network name. | |
| 46 * @return {string} The resulting display name. | |
| 47 * @private | |
| 48 */ | |
| 49 formatNetworkName_(provider_id, network_name) { | |
| 50 if (!this.isThirdPartyProvider_(provider_id) || | |
| 51 !(provider_id in this.providers_)) { | |
| 52 return network_name; | |
| 53 } | |
| 54 return loadTimeData.getStringF('vpnNameTemplate', | |
| 55 this.providers_[provider_id], | |
| 56 network_name); | |
| 57 }, | |
| 58 }; | |
| 59 | |
| 60 /** | |
| 61 * Returns the list of VPN providers enabled in the primary user's profile. | |
| 62 * @return {Object.<string, string>} A mapping from VPN provider ID to name. | |
| 63 */ | |
| 64 VPNProviders.getProviders = function() { | |
| 65 return VPNProviders.getInstance().providers_; | |
| 66 }; | |
| 67 | |
| 68 /** | |
| 69 * Replaces the list of VPN providers enabled in the primary user's profile. | |
| 70 * @param {Object.<string, string>} providers A mapping from VPN provider ID | |
| 71 * to name. | |
| 72 */ | |
| 73 VPNProviders.setProviders = function(providers) { | |
| 74 VPNProviders.getInstance().providers_ = providers; | |
| 75 }; | |
| 76 | |
| 77 /** | |
| 78 * Determines whether |provider_id| belongs to a third-party VPN provider. | |
| 79 * @param {string} provider_id The VPN provider ID. | |
| 80 * @return {boolean} True if the ID belongs to a third-party VPN provider. | |
| 81 */ | |
| 82 VPNProviders.isThirdPartyProvider = function(provider_id) { | |
| 83 return VPNProviders.getInstance().isThirdPartyProvider_(provider_id); | |
| 84 }; | |
| 85 | |
| 86 /** | |
| 87 * Formats a network name for display purposes. If the network belongs to a | |
| 88 * third-party VPN provider, the provider name is added to the network name. | |
| 89 * @param {string} provider_id The VPN provider ID for this network. | |
| 90 * @param {string} network_name The network name. | |
| 91 * @return {string} The resulting display name. | |
| 92 */ | |
| 93 VPNProviders.formatNetworkName = function(provider_id, network_name) { | |
| 94 return VPNProviders.getInstance().formatNetworkName_(provider_id, | |
| 95 network_name); | |
| 96 }; | |
| 97 | |
| 98 // Export | |
| 99 return { | |
| 100 VPNProviders: VPNProviders | |
| 101 }; | |
| 102 }); | |
| OLD | NEW |