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

Side by Side Diff: chrome/browser/ui/webui/options/chromeos/internet_options_handler.cc

Issue 289383004: Merge FavoriteState into NetworkState (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Elim UpdateManagerProperties, feedback Created 6 years, 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/webui/options/chromeos/internet_options_handler.h" 5 #include "chrome/browser/ui/webui/options/chromeos/internet_options_handler.h"
6 6
7 #include <ctype.h> 7 #include <ctype.h>
8 8
9 #include <map> 9 #include <map>
10 #include <string> 10 #include <string>
(...skipping 18 matching lines...) Expand all
29 #include "chrome/browser/chromeos/options/network_property_ui_data.h" 29 #include "chrome/browser/chromeos/options/network_property_ui_data.h"
30 #include "chrome/browser/chromeos/settings/cros_settings.h" 30 #include "chrome/browser/chromeos/settings/cros_settings.h"
31 #include "chrome/browser/chromeos/sim_dialog_delegate.h" 31 #include "chrome/browser/chromeos/sim_dialog_delegate.h"
32 #include "chrome/browser/chromeos/ui/choose_mobile_network_dialog.h" 32 #include "chrome/browser/chromeos/ui/choose_mobile_network_dialog.h"
33 #include "chrome/browser/chromeos/ui/mobile_config_ui.h" 33 #include "chrome/browser/chromeos/ui/mobile_config_ui.h"
34 #include "chrome/browser/chromeos/ui_proxy_config_service.h" 34 #include "chrome/browser/chromeos/ui_proxy_config_service.h"
35 #include "chrome/browser/ui/webui/options/chromeos/core_chromeos_options_handler .h" 35 #include "chrome/browser/ui/webui/options/chromeos/core_chromeos_options_handler .h"
36 #include "chrome/browser/ui/webui/options/chromeos/internet_options_handler_stri ngs.h" 36 #include "chrome/browser/ui/webui/options/chromeos/internet_options_handler_stri ngs.h"
37 #include "chromeos/chromeos_switches.h" 37 #include "chromeos/chromeos_switches.h"
38 #include "chromeos/network/device_state.h" 38 #include "chromeos/network/device_state.h"
39 #include "chromeos/network/favorite_state.h"
40 #include "chromeos/network/managed_network_configuration_handler.h" 39 #include "chromeos/network/managed_network_configuration_handler.h"
41 #include "chromeos/network/network_configuration_handler.h" 40 #include "chromeos/network/network_configuration_handler.h"
42 #include "chromeos/network/network_connection_handler.h" 41 #include "chromeos/network/network_connection_handler.h"
43 #include "chromeos/network/network_device_handler.h" 42 #include "chromeos/network/network_device_handler.h"
44 #include "chromeos/network/network_event_log.h" 43 #include "chromeos/network/network_event_log.h"
45 #include "chromeos/network/network_ip_config.h" 44 #include "chromeos/network/network_ip_config.h"
46 #include "chromeos/network/network_profile.h" 45 #include "chromeos/network/network_profile.h"
47 #include "chromeos/network/network_profile_handler.h" 46 #include "chromeos/network/network_profile_handler.h"
48 #include "chromeos/network/network_state.h" 47 #include "chromeos/network/network_state.h"
49 #include "chromeos/network/network_state_handler.h" 48 #include "chromeos/network/network_state_handler.h"
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 return kTagLoggedInUserPublicAccount; 285 return kTagLoggedInUserPublicAccount;
287 case LoginState::LOGGED_IN_USER_LOCALLY_MANAGED: 286 case LoginState::LOGGED_IN_USER_LOCALLY_MANAGED:
288 return kTagLoggedInUserLocallyManaged; 287 return kTagLoggedInUserLocallyManaged;
289 case LoginState::LOGGED_IN_USER_KIOSK_APP: 288 case LoginState::LOGGED_IN_USER_KIOSK_APP:
290 return kTagLoggedInUserKioskApp; 289 return kTagLoggedInUserKioskApp;
291 } 290 }
292 NOTREACHED(); 291 NOTREACHED();
293 return std::string(); 292 return std::string();
294 } 293 }
295 294
296 bool HasPolicyForFavorite(const FavoriteState* favorite, 295 void SetCommonNetworkInfo(const NetworkState* state,
297 const PrefService* profile_prefs) {
298 return onc::HasPolicyForFavoriteNetwork(
299 profile_prefs, g_browser_process->local_state(), *favorite);
300 }
301
302 bool HasPolicyForNetwork(const NetworkState* network,
303 const PrefService* profile_prefs) {
304 const FavoriteState* favorite =
305 NetworkHandler::Get()
306 ->network_state_handler()
307 ->GetFavoriteStateFromServicePath(network->path(),
308 true /* configured_only */);
309 if (!favorite)
310 return false;
311 return HasPolicyForFavorite(favorite, profile_prefs);
312 }
313
314 void SetCommonNetworkInfo(const ManagedState* state,
315 const std::string& icon_url, 296 const std::string& icon_url,
316 base::DictionaryValue* network_info) { 297 base::DictionaryValue* network_info) {
317 network_info->SetString(kNetworkInfoKeyIconURL, icon_url); 298 network_info->SetString(kNetworkInfoKeyIconURL, icon_url);
318 299
319 std::string name = state->name(); 300 std::string name = state->name();
320 if (state->Matches(NetworkTypePattern::Ethernet())) { 301 if (state->Matches(NetworkTypePattern::Ethernet())) {
321 name = internet_options_strings::NetworkDeviceTypeString( 302 name = internet_options_strings::NetworkDeviceTypeString(
322 shill::kTypeEthernet); 303 shill::kTypeEthernet);
323 } 304 }
324 network_info->SetString(kNetworkInfoKeyNetworkName, name); 305 network_info->SetString(kNetworkInfoKeyNetworkName, name);
325 network_info->SetString(kNetworkInfoKeyNetworkType, state->type()); 306 network_info->SetString(kNetworkInfoKeyNetworkType, state->type());
326 network_info->SetString(kNetworkInfoKeyServicePath, state->path()); 307 network_info->SetString(kNetworkInfoKeyServicePath, state->path());
327 } 308 }
328 309
329 // Builds a dictionary with network information and an icon used for the 310 // Builds a dictionary with network information and an icon used for the
330 // NetworkList on the settings page. Ownership of the returned pointer is 311 // NetworkList on the settings page. Ownership of the returned pointer is
331 // transferred to the caller. 312 // transferred to the caller.
332 base::DictionaryValue* BuildNetworkDictionary( 313 base::DictionaryValue* BuildNetworkDictionary(
333 const NetworkState* network, 314 const NetworkState* network,
334 float icon_scale_factor, 315 float icon_scale_factor,
335 const PrefService* profile_prefs) { 316 const PrefService* profile_prefs) {
336 scoped_ptr<base::DictionaryValue> network_info(new base::DictionaryValue()); 317 scoped_ptr<base::DictionaryValue> network_info(new base::DictionaryValue());
337 network_info->SetBoolean(kNetworkInfoKeyConnectable, network->connectable()); 318 network_info->SetBoolean(kNetworkInfoKeyConnectable, network->connectable());
338 network_info->SetBoolean(kNetworkInfoKeyConnected, 319 network_info->SetBoolean(kNetworkInfoKeyConnected,
339 network->IsConnectedState()); 320 network->IsConnectedState());
340 network_info->SetBoolean(kNetworkInfoKeyConnecting, 321 network_info->SetBoolean(kNetworkInfoKeyConnecting,
341 network->IsConnectingState()); 322 network->IsConnectingState());
342 network_info->SetBoolean(kNetworkInfoKeyPolicyManaged, 323 bool has_policy = onc::HasPolicyForNetwork(
pneubeck (no reviews) 2014/06/11 12:44:55 yuhuu!
stevenjb 2014/06/11 23:31:40 :)
343 HasPolicyForNetwork(network, profile_prefs)); 324 profile_prefs, g_browser_process->local_state(), *network);
325 network_info->SetBoolean(kNetworkInfoKeyPolicyManaged, has_policy);
344 326
345 std::string icon_url = ash::network_icon::GetImageUrlForNetwork( 327 std::string icon_url = ash::network_icon::GetImageUrlForNetwork(
pneubeck (no reviews) 2014/06/11 12:44:55 I didn't look too thoroughly, but the code of GetI
stevenjb 2014/06/11 23:31:40 Good catch on GetImageUrlForDisconnectedNetwork no
346 network, ash::network_icon::ICON_TYPE_LIST, icon_scale_factor); 328 network, ash::network_icon::ICON_TYPE_LIST, icon_scale_factor);
347 SetCommonNetworkInfo(network, icon_url, network_info.get()); 329 SetCommonNetworkInfo(network, icon_url, network_info.get());
348 return network_info.release(); 330 return network_info.release();
349 } 331 }
350 332
351 base::DictionaryValue* BuildFavoriteDictionary(
352 const FavoriteState* favorite,
353 float icon_scale_factor,
354 const PrefService* profile_prefs) {
355 scoped_ptr<base::DictionaryValue> network_info(new base::DictionaryValue());
356 network_info->SetBoolean(kNetworkInfoKeyConnectable, false);
pneubeck (no reviews) 2014/06/11 12:44:55 as you mentioned elsewhere, these properties of vi
stevenjb 2014/06/11 23:31:40 Hmm, maybe. Better safe than sorry, I'll fix this
357 network_info->SetBoolean(kNetworkInfoKeyConnected, false);
358 network_info->SetBoolean(kNetworkInfoKeyConnecting, false);
359 network_info->SetBoolean(kNetworkInfoKeyPolicyManaged,
360 HasPolicyForFavorite(favorite, profile_prefs));
361
362 std::string icon_url = ash::network_icon::GetImageUrlForDisconnectedNetwork(
363 ash::network_icon::ICON_TYPE_LIST, favorite->type(), icon_scale_factor);
364 SetCommonNetworkInfo(favorite, icon_url, network_info.get());
365 return network_info.release();
366 }
367
368 // Pulls IP information out of a shill service properties dictionary. If 333 // Pulls IP information out of a shill service properties dictionary. If
369 // |static_ip| is true, then it fetches "StaticIP.*" properties. If not, then it 334 // |static_ip| is true, then it fetches "StaticIP.*" properties. If not, then it
370 // fetches "SavedIP.*" properties. Caller must take ownership of returned 335 // fetches "SavedIP.*" properties. Caller must take ownership of returned
371 // dictionary. If non-NULL, |ip_parameters_set| returns a count of the number 336 // dictionary. If non-NULL, |ip_parameters_set| returns a count of the number
372 // of IP routing parameters that get set. 337 // of IP routing parameters that get set.
373 base::DictionaryValue* BuildIPInfoDictionary( 338 base::DictionaryValue* BuildIPInfoDictionary(
374 const base::DictionaryValue& shill_properties, 339 const base::DictionaryValue& shill_properties,
375 bool static_ip, 340 bool static_ip,
376 int* routing_parameters_set) { 341 int* routing_parameters_set) {
377 std::string address_key; 342 std::string address_key;
(...skipping 1353 matching lines...) Expand 10 before | Expand all | Expand 10 after
1731 BuildNetworkDictionary(network, 1696 BuildNetworkDictionary(network,
1732 web_ui()->GetDeviceScaleFactor(), 1697 web_ui()->GetDeviceScaleFactor(),
1733 Profile::FromWebUI(web_ui())->GetPrefs())); 1698 Profile::FromWebUI(web_ui())->GetPrefs()));
1734 return list; 1699 return list;
1735 } 1700 }
1736 1701
1737 base::ListValue* InternetOptionsHandler::GetWirelessList() { 1702 base::ListValue* InternetOptionsHandler::GetWirelessList() {
1738 base::ListValue* list = new base::ListValue(); 1703 base::ListValue* list = new base::ListValue();
1739 1704
1740 NetworkStateHandler::NetworkStateList networks; 1705 NetworkStateHandler::NetworkStateList networks;
1741 NetworkHandler::Get()->network_state_handler()->GetNetworkListByType( 1706 NetworkHandler::Get()->network_state_handler()->GetVisibleNetworkListByType(
1742 NetworkTypePattern::Wireless(), &networks); 1707 NetworkTypePattern::Wireless(), &networks);
1743 for (NetworkStateHandler::NetworkStateList::const_iterator iter = 1708 for (NetworkStateHandler::NetworkStateList::const_iterator iter =
1744 networks.begin(); iter != networks.end(); ++iter) { 1709 networks.begin(); iter != networks.end(); ++iter) {
1745 list->Append( 1710 list->Append(
1746 BuildNetworkDictionary(*iter, 1711 BuildNetworkDictionary(*iter,
1747 web_ui()->GetDeviceScaleFactor(), 1712 web_ui()->GetDeviceScaleFactor(),
1748 Profile::FromWebUI(web_ui())->GetPrefs())); 1713 Profile::FromWebUI(web_ui())->GetPrefs()));
1749 } 1714 }
1750 1715
1751 return list; 1716 return list;
1752 } 1717 }
1753 1718
1754 base::ListValue* InternetOptionsHandler::GetVPNList() { 1719 base::ListValue* InternetOptionsHandler::GetVPNList() {
1755 base::ListValue* list = new base::ListValue(); 1720 base::ListValue* list = new base::ListValue();
1756 1721
1757 NetworkStateHandler::NetworkStateList networks; 1722 NetworkStateHandler::NetworkStateList networks;
1758 NetworkHandler::Get()->network_state_handler()->GetNetworkListByType( 1723 NetworkHandler::Get()->network_state_handler()->GetVisibleNetworkListByType(
1759 NetworkTypePattern::VPN(), &networks); 1724 NetworkTypePattern::VPN(), &networks);
1760 for (NetworkStateHandler::NetworkStateList::const_iterator iter = 1725 for (NetworkStateHandler::NetworkStateList::const_iterator iter =
1761 networks.begin(); iter != networks.end(); ++iter) { 1726 networks.begin(); iter != networks.end(); ++iter) {
1762 list->Append( 1727 list->Append(
1763 BuildNetworkDictionary(*iter, 1728 BuildNetworkDictionary(*iter,
1764 web_ui()->GetDeviceScaleFactor(), 1729 web_ui()->GetDeviceScaleFactor(),
1765 Profile::FromWebUI(web_ui())->GetPrefs())); 1730 Profile::FromWebUI(web_ui())->GetPrefs()));
1766 } 1731 }
1767 1732
1768 return list; 1733 return list;
1769 } 1734 }
1770 1735
1771 base::ListValue* InternetOptionsHandler::GetRememberedList() { 1736 base::ListValue* InternetOptionsHandler::GetRememberedList() {
1772 base::ListValue* list = new base::ListValue(); 1737 base::ListValue* list = new base::ListValue();
1773 1738
1774 NetworkStateHandler::FavoriteStateList favorites; 1739 NetworkStateHandler::NetworkStateList networks;
1775 NetworkHandler::Get()->network_state_handler()->GetFavoriteList(&favorites); 1740 NetworkHandler::Get()->network_state_handler()->GetNetworkListByType(
1776 for (NetworkStateHandler::FavoriteStateList::const_iterator iter = 1741 NetworkTypePattern::Default(),
1777 favorites.begin(); iter != favorites.end(); ++iter) { 1742 true /* configured_only */,
1778 const FavoriteState* favorite = *iter; 1743 false /* visible_only */,
1779 if (favorite->type() != shill::kTypeWifi && 1744 0 /* no limit */,
1780 favorite->type() != shill::kTypeVPN) 1745 &networks);
1746 for (NetworkStateHandler::NetworkStateList::const_iterator iter =
1747 networks.begin(); iter != networks.end(); ++iter) {
1748 const NetworkState* network = *iter;
1749 if (network->type() != shill::kTypeWifi &&
1750 network->type() != shill::kTypeVPN)
1781 continue; 1751 continue;
1782 list->Append( 1752 list->Append(
1783 BuildFavoriteDictionary(favorite, 1753 BuildNetworkDictionary(network,
1784 web_ui()->GetDeviceScaleFactor(), 1754 web_ui()->GetDeviceScaleFactor(),
1785 Profile::FromWebUI(web_ui())->GetPrefs())); 1755 Profile::FromWebUI(web_ui())->GetPrefs()));
1786 } 1756 }
1787 1757
1788 return list; 1758 return list;
1789 } 1759 }
1790 1760
1791 void InternetOptionsHandler::FillNetworkInfo( 1761 void InternetOptionsHandler::FillNetworkInfo(
1792 base::DictionaryValue* dictionary) { 1762 base::DictionaryValue* dictionary) {
1793 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); 1763 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler();
1794 dictionary->Set(kTagWiredList, GetWiredList()); 1764 dictionary->Set(kTagWiredList, GetWiredList());
1795 dictionary->Set(kTagWirelessList, GetWirelessList()); 1765 dictionary->Set(kTagWirelessList, GetWirelessList());
(...skipping 22 matching lines...) Expand all
1818 dictionary->SetBoolean( 1788 dictionary->SetBoolean(
1819 kTagWimaxAvailable, 1789 kTagWimaxAvailable,
1820 handler->IsTechnologyAvailable(NetworkTypePattern::Wimax())); 1790 handler->IsTechnologyAvailable(NetworkTypePattern::Wimax()));
1821 dictionary->SetBoolean( 1791 dictionary->SetBoolean(
1822 kTagWimaxEnabled, 1792 kTagWimaxEnabled,
1823 handler->IsTechnologyEnabled(NetworkTypePattern::Wimax())); 1793 handler->IsTechnologyEnabled(NetworkTypePattern::Wimax()));
1824 } 1794 }
1825 1795
1826 } // namespace options 1796 } // namespace options
1827 } // namespace chromeos 1797 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698