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

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: Rebase 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 if (network->visible()) {
338 network_info->SetBoolean(kNetworkInfoKeyConnected, 319 network_info->SetBoolean(kNetworkInfoKeyConnectable,
339 network->IsConnectedState()); 320 network->connectable());
340 network_info->SetBoolean(kNetworkInfoKeyConnecting, 321 network_info->SetBoolean(kNetworkInfoKeyConnected,
341 network->IsConnectingState()); 322 network->IsConnectedState());
342 network_info->SetBoolean(kNetworkInfoKeyPolicyManaged, 323 network_info->SetBoolean(kNetworkInfoKeyConnecting,
343 HasPolicyForNetwork(network, profile_prefs)); 324 network->IsConnectingState());
325 } else {
326 network_info->SetBoolean(kNetworkInfoKeyConnectable, false);
327 network_info->SetBoolean(kNetworkInfoKeyConnected, false);
328 network_info->SetBoolean(kNetworkInfoKeyConnecting, false);
329 }
330 bool has_policy = onc::HasPolicyForNetwork(
331 profile_prefs, g_browser_process->local_state(), *network);
332 network_info->SetBoolean(kNetworkInfoKeyPolicyManaged, has_policy);
344 333
345 std::string icon_url = ash::network_icon::GetImageUrlForNetwork( 334 std::string icon_url = ash::network_icon::GetImageUrlForNetwork(
346 network, ash::network_icon::ICON_TYPE_LIST, icon_scale_factor); 335 network, ash::network_icon::ICON_TYPE_LIST, icon_scale_factor);
347 SetCommonNetworkInfo(network, icon_url, network_info.get()); 336 SetCommonNetworkInfo(network, icon_url, network_info.get());
348 return network_info.release(); 337 return network_info.release();
349 } 338 }
350 339
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);
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 340 // 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 341 // |static_ip| is true, then it fetches "StaticIP.*" properties. If not, then it
370 // fetches "SavedIP.*" properties. Caller must take ownership of returned 342 // fetches "SavedIP.*" properties. Caller must take ownership of returned
371 // dictionary. If non-NULL, |ip_parameters_set| returns a count of the number 343 // dictionary. If non-NULL, |ip_parameters_set| returns a count of the number
372 // of IP routing parameters that get set. 344 // of IP routing parameters that get set.
373 base::DictionaryValue* BuildIPInfoDictionary( 345 base::DictionaryValue* BuildIPInfoDictionary(
374 const base::DictionaryValue& shill_properties, 346 const base::DictionaryValue& shill_properties,
375 bool static_ip, 347 bool static_ip,
376 int* routing_parameters_set) { 348 int* routing_parameters_set) {
377 std::string address_key; 349 std::string address_key;
(...skipping 1353 matching lines...) Expand 10 before | Expand all | Expand 10 after
1731 BuildNetworkDictionary(network, 1703 BuildNetworkDictionary(network,
1732 web_ui()->GetDeviceScaleFactor(), 1704 web_ui()->GetDeviceScaleFactor(),
1733 Profile::FromWebUI(web_ui())->GetPrefs())); 1705 Profile::FromWebUI(web_ui())->GetPrefs()));
1734 return list; 1706 return list;
1735 } 1707 }
1736 1708
1737 base::ListValue* InternetOptionsHandler::GetWirelessList() { 1709 base::ListValue* InternetOptionsHandler::GetWirelessList() {
1738 base::ListValue* list = new base::ListValue(); 1710 base::ListValue* list = new base::ListValue();
1739 1711
1740 NetworkStateHandler::NetworkStateList networks; 1712 NetworkStateHandler::NetworkStateList networks;
1741 NetworkHandler::Get()->network_state_handler()->GetNetworkListByType( 1713 NetworkHandler::Get()->network_state_handler()->GetVisibleNetworkListByType(
1742 NetworkTypePattern::Wireless(), &networks); 1714 NetworkTypePattern::Wireless(), &networks);
1743 for (NetworkStateHandler::NetworkStateList::const_iterator iter = 1715 for (NetworkStateHandler::NetworkStateList::const_iterator iter =
1744 networks.begin(); iter != networks.end(); ++iter) { 1716 networks.begin(); iter != networks.end(); ++iter) {
1745 list->Append( 1717 list->Append(
1746 BuildNetworkDictionary(*iter, 1718 BuildNetworkDictionary(*iter,
1747 web_ui()->GetDeviceScaleFactor(), 1719 web_ui()->GetDeviceScaleFactor(),
1748 Profile::FromWebUI(web_ui())->GetPrefs())); 1720 Profile::FromWebUI(web_ui())->GetPrefs()));
1749 } 1721 }
1750 1722
1751 return list; 1723 return list;
1752 } 1724 }
1753 1725
1754 base::ListValue* InternetOptionsHandler::GetVPNList() { 1726 base::ListValue* InternetOptionsHandler::GetVPNList() {
1755 base::ListValue* list = new base::ListValue(); 1727 base::ListValue* list = new base::ListValue();
1756 1728
1757 NetworkStateHandler::NetworkStateList networks; 1729 NetworkStateHandler::NetworkStateList networks;
1758 NetworkHandler::Get()->network_state_handler()->GetNetworkListByType( 1730 NetworkHandler::Get()->network_state_handler()->GetVisibleNetworkListByType(
1759 NetworkTypePattern::VPN(), &networks); 1731 NetworkTypePattern::VPN(), &networks);
1760 for (NetworkStateHandler::NetworkStateList::const_iterator iter = 1732 for (NetworkStateHandler::NetworkStateList::const_iterator iter =
1761 networks.begin(); iter != networks.end(); ++iter) { 1733 networks.begin(); iter != networks.end(); ++iter) {
1762 list->Append( 1734 list->Append(
1763 BuildNetworkDictionary(*iter, 1735 BuildNetworkDictionary(*iter,
1764 web_ui()->GetDeviceScaleFactor(), 1736 web_ui()->GetDeviceScaleFactor(),
1765 Profile::FromWebUI(web_ui())->GetPrefs())); 1737 Profile::FromWebUI(web_ui())->GetPrefs()));
1766 } 1738 }
1767 1739
1768 return list; 1740 return list;
1769 } 1741 }
1770 1742
1771 base::ListValue* InternetOptionsHandler::GetRememberedList() { 1743 base::ListValue* InternetOptionsHandler::GetRememberedList() {
1772 base::ListValue* list = new base::ListValue(); 1744 base::ListValue* list = new base::ListValue();
1773 1745
1774 NetworkStateHandler::FavoriteStateList favorites; 1746 NetworkStateHandler::NetworkStateList networks;
1775 NetworkHandler::Get()->network_state_handler()->GetFavoriteList(&favorites); 1747 NetworkHandler::Get()->network_state_handler()->GetNetworkListByType(
1776 for (NetworkStateHandler::FavoriteStateList::const_iterator iter = 1748 NetworkTypePattern::Default(),
1777 favorites.begin(); iter != favorites.end(); ++iter) { 1749 true /* configured_only */,
1778 const FavoriteState* favorite = *iter; 1750 false /* visible_only */,
1779 if (favorite->type() != shill::kTypeWifi && 1751 0 /* no limit */,
1780 favorite->type() != shill::kTypeVPN) 1752 &networks);
1753 for (NetworkStateHandler::NetworkStateList::const_iterator iter =
1754 networks.begin(); iter != networks.end(); ++iter) {
1755 const NetworkState* network = *iter;
1756 if (network->type() != shill::kTypeWifi &&
1757 network->type() != shill::kTypeVPN)
1781 continue; 1758 continue;
1782 list->Append( 1759 list->Append(
1783 BuildFavoriteDictionary(favorite, 1760 BuildNetworkDictionary(network,
1784 web_ui()->GetDeviceScaleFactor(), 1761 web_ui()->GetDeviceScaleFactor(),
1785 Profile::FromWebUI(web_ui())->GetPrefs())); 1762 Profile::FromWebUI(web_ui())->GetPrefs()));
1786 } 1763 }
1787 1764
1788 return list; 1765 return list;
1789 } 1766 }
1790 1767
1791 void InternetOptionsHandler::FillNetworkInfo( 1768 void InternetOptionsHandler::FillNetworkInfo(
1792 base::DictionaryValue* dictionary) { 1769 base::DictionaryValue* dictionary) {
1793 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); 1770 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler();
1794 dictionary->Set(kTagWiredList, GetWiredList()); 1771 dictionary->Set(kTagWiredList, GetWiredList());
1795 dictionary->Set(kTagWirelessList, GetWirelessList()); 1772 dictionary->Set(kTagWirelessList, GetWirelessList());
(...skipping 22 matching lines...) Expand all
1818 dictionary->SetBoolean( 1795 dictionary->SetBoolean(
1819 kTagWimaxAvailable, 1796 kTagWimaxAvailable,
1820 handler->IsTechnologyAvailable(NetworkTypePattern::Wimax())); 1797 handler->IsTechnologyAvailable(NetworkTypePattern::Wimax()));
1821 dictionary->SetBoolean( 1798 dictionary->SetBoolean(
1822 kTagWimaxEnabled, 1799 kTagWimaxEnabled,
1823 handler->IsTechnologyEnabled(NetworkTypePattern::Wimax())); 1800 handler->IsTechnologyEnabled(NetworkTypePattern::Wimax()));
1824 } 1801 }
1825 1802
1826 } // namespace options 1803 } // namespace options
1827 } // namespace chromeos 1804 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698