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

Side by Side Diff: chrome/browser/resources/options/chromeos/vpn_providers.js

Issue 1017443002: Allow users to add third-party VPNs from the settings page (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@f_3_460428_update_details_dialog
Patch Set: Finished renaming method. 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 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 /** 5 /**
6 * @fileoverview A singleton that keeps track of the VPN providers enabled in 6 * @fileoverview A singleton that keeps track of the VPN providers enabled in
7 * the primary user's profile. 7 * the primary user's profile.
8 */ 8 */
9 9
10 cr.define('options', function() { 10 cr.define('options', function() {
11 /** 11 /**
12 * @constructor 12 * @constructor
13 */ 13 */
14 function VPNProviders() { 14 function VPNProviders() {
15 } 15 }
16 16
17 cr.addSingletonGetter(VPNProviders); 17 cr.addSingletonGetter(VPNProviders);
18 18
19 VPNProviders.prototype = { 19 VPNProviders.prototype = {
20 /** 20 /**
21 * The VPN providers enabled in the primary user's profile. Each provider 21 * The VPN providers enabled in the primary user's profile. Each provider
22 * has a name. Third-party VPN providers additionally have an extension ID. 22 * has a name. Third-party VPN providers additionally have an extension ID.
23 * @type {!Array<{name: string, extensionID: ?string}>} 23 * @type {!Array<{name: string, extensionID: ?string}>}
24 * @private 24 * @private
25 */ 25 */
26 providers_: [], 26 providers_: [],
27 27
28 /** 28 /**
29 * Observers who will be notified when the list of VPN providers changes.
30 * @type {!Array<!function()>}
31 */
32 observers_: [],
33
34 /**
35 * The VPN providers enabled in the primary user's profile.
36 * @type {!Array<{name: string, extensionID: ?string}>}
37 */
38 get providers() {
39 return this.providers_;
40 },
41 set providers(providers) {
42 this.providers_ = providers;
43 for (var i = 0; i < this.observers_.length; ++i)
44 this.observers_[i]();
michaelpg 2015/03/19 19:48:28 What would happen if an observer tried to set prov
bartfab (slow) 2015/03/20 00:10:25 As discussed, I added a comment warning about this
45 },
46
47 /**
48 * Adds an observer to be notified when the list of VPN providers changes.
49 * @param {!function()} observer The observer to add.
50 */
51 addObserver: function(observer) {
52 this.observers_.push(observer);
53 },
54
55 /**
29 * Formats a network name for display purposes. If the network belongs to 56 * Formats a network name for display purposes. If the network belongs to
30 * a third-party VPN provider, the provider name is added to the network 57 * a third-party VPN provider, the provider name is added to the network
31 * name. 58 * name.
32 * @param {cr.onc.OncData} onc ONC data describing this network. 59 * @param {cr.onc.OncData} onc ONC data describing this network.
33 * @return {string} The resulting display name. 60 * @return {string} The resulting display name.
34 * @private 61 * @private
35 */ 62 */
36 formatNetworkName_: function(onc) { 63 formatNetworkName_: function(onc) {
37 var networkName = onc.getTranslatedValue('Name'); 64 var networkName = onc.getTranslatedValue('Name');
38 if (onc.getActiveValue('VPN.Type') != 'ThirdPartyVPN') 65 if (onc.getActiveValue('VPN.Type') != 'ThirdPartyVPN')
39 return networkName; 66 return networkName;
40 var extensionID = onc.getActiveValue('VPN.ThirdPartyVPN.ExtensionID'); 67 var extensionID = onc.getActiveValue('VPN.ThirdPartyVPN.ExtensionID');
41 for (var i = 0; i < this.providers_.length; ++i) { 68 for (var i = 0; i < this.providers_.length; ++i) {
42 if (extensionID == this.providers_[i].extensionID) { 69 if (extensionID == this.providers_[i].extensionID) {
43 return loadTimeData.getStringF('vpnNameTemplate', 70 return loadTimeData.getStringF('vpnNameTemplate',
44 this.providers_[i].name, 71 this.providers_[i].name,
45 networkName); 72 networkName);
46 } 73 }
47 } 74 }
48 return networkName; 75 return networkName;
49 }, 76 },
50 }; 77 };
51 78
52 /** 79 /**
80 * Adds an observer to be notified when the list of VPN providers changes.
michaelpg 2015/03/19 19:48:28 nit: s/notified/called
bartfab (slow) 2015/03/20 00:10:25 Done.
81 * @param {!function()} observer The observer to add.
82 */
83 VPNProviders.addObserver = function(observer) {
84 VPNProviders.getInstance().addObserver(observer);
85 };
86
87 /**
53 * Returns the list of VPN providers enabled in the primary user's profile. 88 * Returns the list of VPN providers enabled in the primary user's profile.
54 * @return {!Array<{name: string, extensionID: ?string}>} The list of VPN 89 * @return {!Array<{name: string, extensionID: ?string}>} The list of VPN
55 * providers enabled in the primary user's profile. 90 * providers enabled in the primary user's profile.
56 */ 91 */
57 VPNProviders.getProviders = function() { 92 VPNProviders.getProviders = function() {
58 return VPNProviders.getInstance().providers_; 93 return VPNProviders.getInstance().providers;
59 }; 94 };
60 95
61 /** 96 /**
62 * Replaces the list of VPN providers enabled in the primary user's profile. 97 * Replaces the list of VPN providers enabled in the primary user's profile.
63 * @param {!Array<{name: string, extensionID: ?string}>} providers The list 98 * @param {!Array<{name: string, extensionID: ?string}>} providers The list
64 * of VPN providers enabled in the primary user's profile. 99 * of VPN providers enabled in the primary user's profile.
65 */ 100 */
66 VPNProviders.setProviders = function(providers) { 101 VPNProviders.setProviders = function(providers) {
67 VPNProviders.getInstance().providers_ = providers; 102 VPNProviders.getInstance().providers = providers;
68 }; 103 };
69 104
70 /** 105 /**
71 * Formats a network name for display purposes. If the network belongs to a 106 * Formats a network name for display purposes. If the network belongs to a
72 * third-party VPN provider, the provider name is added to the network name. 107 * third-party VPN provider, the provider name is added to the network name.
73 * @param {cr.onc.OncData} onc ONC data describing this network. 108 * @param {cr.onc.OncData} onc ONC data describing this network.
74 * @return {string} The resulting display name. 109 * @return {string} The resulting display name.
75 */ 110 */
76 VPNProviders.formatNetworkName = function(onc) { 111 VPNProviders.formatNetworkName = function(onc) {
77 return VPNProviders.getInstance().formatNetworkName_(onc); 112 return VPNProviders.getInstance().formatNetworkName_(onc);
78 }; 113 };
79 114
80 // Export 115 // Export
81 return { 116 return {
82 VPNProviders: VPNProviders 117 VPNProviders: VPNProviders
83 }; 118 };
84 }); 119 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698