Skip to content

Commit

Permalink
Merge FavoriteState into NetworkState
Browse files Browse the repository at this point in the history
BUG=375955
For trivial renaming:

R=armansito@chromium.org, pneubeck@chromium.org
TBR=derat@chromium.org, xiyuan@chromium.org

Review URL: https://codereview.chromium.org/289383004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@276822 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
stevenjb@chromium.org committed Jun 12, 2014
1 parent 1208940 commit fa0336f
Show file tree
Hide file tree
Showing 57 changed files with 782 additions and 1,082 deletions.
2 changes: 1 addition & 1 deletion apps/shell/browser/shell_network_controller_chromeos.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ void ShellNetworkController::ConnectIfUnconnected() {
return;

chromeos::NetworkStateHandler::NetworkStateList state_list;
handler->network_state_handler()->GetNetworkListByType(
handler->network_state_handler()->GetVisibleNetworkListByType(
chromeos::NetworkTypePattern::WiFi(), &state_list);
for (chromeos::NetworkStateHandler::NetworkStateList::const_iterator it =
state_list.begin(); it != state_list.end(); ++it) {
Expand Down
33 changes: 5 additions & 28 deletions ash/system/chromeos/network/network_icon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -364,26 +364,6 @@ const gfx::ImageSkia GetDisconnectedImage(IconType icon_type,
return GetImageForIndex(image_type, icon_type, disconnected_index);
}

const std::string& GetDisconnectedImageUrl(IconType icon_type,
const std::string& network_type,
float scale_factor) {
static ImageIdUrlMap* s_image_url_map = NULL;
if (s_image_url_map == NULL)
s_image_url_map = new ImageIdUrlMap;

ImageIdForNetworkType key(icon_type, network_type, scale_factor);
ImageIdUrlMap::iterator iter = s_image_url_map->find(key);
if (iter != s_image_url_map->end())
return iter->second;

VLOG(2) << "Generating disconnected bitmap URL for: " << network_type;
gfx::ImageSkia image = GetDisconnectedImage(icon_type, network_type);
gfx::ImageSkiaRep image_rep = image.GetRepresentation(scale_factor);
iter = s_image_url_map->insert(std::make_pair(
key, webui::GetBitmapDataUrl(image_rep.sk_bitmap()))).first;
return iter->second;
}

gfx::ImageSkia* ConnectingWirelessImage(ImageType image_type,
IconType icon_type,
double animation) {
Expand Down Expand Up @@ -783,7 +763,9 @@ NetworkIconImpl* FindAndUpdateImageImpl(const NetworkState* network,
gfx::ImageSkia GetImageForNetwork(const NetworkState* network,
IconType icon_type) {
DCHECK(network);
// Handle connecting icons.
if (!network->visible())
return GetDisconnectedImage(icon_type, network->type());

if (network->IsConnectingState())
return GetConnectingImage(icon_type, network->type());

Expand Down Expand Up @@ -818,12 +800,6 @@ gfx::ImageSkia GetImageForDisconnectedNetwork(IconType icon_type,
return GetDisconnectedImage(icon_type, network_type);
}

std::string GetImageUrlForDisconnectedNetwork(IconType icon_type,
const std::string& network_type,
float scale_factor) {
return GetDisconnectedImageUrl(icon_type, network_type, scale_factor);
}

base::string16 GetLabelForNetwork(const chromeos::NetworkState* network,
IconType icon_type) {
DCHECK(network);
Expand Down Expand Up @@ -970,7 +946,8 @@ void GetDefaultNetworkImageAndLabel(IconType icon_type,

void PurgeNetworkIconCache() {
NetworkStateHandler::NetworkStateList networks;
NetworkHandler::Get()->network_state_handler()->GetNetworkList(&networks);
NetworkHandler::Get()->network_state_handler()->GetVisibleNetworkList(
&networks);
std::set<std::string> network_paths;
for (NetworkStateHandler::NetworkStateList::iterator iter = networks.begin();
iter != networks.end(); ++iter) {
Expand Down
6 changes: 0 additions & 6 deletions ash/system/chromeos/network/network_icon.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,6 @@ ASH_EXPORT gfx::ImageSkia GetImageForDisconnectedNetwork(
IconType icon_type,
const std::string& network_type);

// Gets a url representing the image for a disconnected network type.
ASH_EXPORT std::string GetImageUrlForDisconnectedNetwork(
IconType icon_type,
const std::string& network_type,
float scale_factor);

// Returns the label for |network| based on |icon_type|. |network| can be NULL.
ASH_EXPORT base::string16 GetLabelForNetwork(
const chromeos::NetworkState* network,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ void NetworkStateListDetailedView::ManagerChanged() {
void NetworkStateListDetailedView::NetworkListChanged() {
NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler();
NetworkStateHandler::NetworkStateList network_list;
handler->GetNetworkList(&network_list);
handler->GetVisibleNetworkList(&network_list);
UpdateNetworks(network_list);
UpdateNetworkList();
UpdateHeaderButtons();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class MobileActivatorTest : public testing::Test {
cellular_network_.activation_state_ = activation_state;
}
void set_connection_state(const std::string& state) {
cellular_network_.visible_ = true;
cellular_network_.connection_state_ = state;
}

Expand Down
39 changes: 19 additions & 20 deletions chrome/browser/chromeos/net/onc_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include "chrome/browser/chromeos/ui_proxy_config.h"
#include "chrome/browser/prefs/proxy_config_dictionary.h"
#include "chrome/common/pref_names.h"
#include "chromeos/network/favorite_state.h"
#include "chromeos/network/managed_network_configuration_handler.h"
#include "chromeos/network/network_configuration_handler.h"
#include "chromeos/network/network_handler.h"
Expand Down Expand Up @@ -348,22 +347,22 @@ const base::DictionaryValue* GetNetworkConfigForEthernetWithoutEAP(

const base::DictionaryValue* GetNetworkConfigForNetworkFromOnc(
const base::ListValue& network_configs,
const FavoriteState& favorite) {
const NetworkState& network) {
// In all cases except Ethernet, we use the GUID of |network|.
if (!favorite.Matches(NetworkTypePattern::Ethernet()))
return GetNetworkConfigByGUID(network_configs, favorite.guid());
if (!network.Matches(NetworkTypePattern::Ethernet()))
return GetNetworkConfigByGUID(network_configs, network.guid());

// Ethernet is always shared and thus cannot store a GUID per user. Thus we
// search for any Ethernet policy intead of a matching GUID.
// EthernetEAP service contains only the EAP parameters and stores the GUID of
// the respective ONC policy. The EthernetEAP service itself is however never
// in state "connected". An EthernetEAP policy must be applied, if an Ethernet
// service is connected using the EAP parameters.
const FavoriteState* ethernet_eap = NULL;
const NetworkState* ethernet_eap = NULL;
if (NetworkHandler::IsInitialized()) {
ethernet_eap =
NetworkHandler::Get()->network_state_handler()->GetEAPForEthernet(
favorite.path());
network.path());
}

// The GUID associated with the EthernetEAP service refers to the ONC policy
Expand All @@ -379,7 +378,7 @@ const base::DictionaryValue* GetNetworkConfigForNetworkFromOnc(
const base::DictionaryValue* GetPolicyForNetworkFromPref(
const PrefService* pref_service,
const char* pref_name,
const FavoriteState& favorite) {
const NetworkState& network) {
if (!pref_service) {
VLOG(2) << "No pref service";
return NULL;
Expand Down Expand Up @@ -413,42 +412,42 @@ const base::DictionaryValue* GetPolicyForNetworkFromPref(
onc_policy_value->GetAsList(&onc_policy);
DCHECK(onc_policy);

return GetNetworkConfigForNetworkFromOnc(*onc_policy, favorite);
return GetNetworkConfigForNetworkFromOnc(*onc_policy, network);
}

} // namespace

const base::DictionaryValue* GetPolicyForFavoriteNetwork(
const base::DictionaryValue* GetPolicyForNetwork(
const PrefService* profile_prefs,
const PrefService* local_state_prefs,
const FavoriteState& favorite,
const NetworkState& network,
::onc::ONCSource* onc_source) {
VLOG(2) << "GetPolicyForFavoriteNetwork: " << favorite.path();
VLOG(2) << "GetPolicyForNetwork: " << network.path();
*onc_source = ::onc::ONC_SOURCE_NONE;

const base::DictionaryValue* network_policy = GetPolicyForNetworkFromPref(
profile_prefs, prefs::kOpenNetworkConfiguration, favorite);
profile_prefs, prefs::kOpenNetworkConfiguration, network);
if (network_policy) {
VLOG(1) << "Network " << favorite.path() << " is managed by user policy.";
VLOG(1) << "Network " << network.path() << " is managed by user policy.";
*onc_source = ::onc::ONC_SOURCE_USER_POLICY;
return network_policy;
}
network_policy = GetPolicyForNetworkFromPref(
local_state_prefs, prefs::kDeviceOpenNetworkConfiguration, favorite);
local_state_prefs, prefs::kDeviceOpenNetworkConfiguration, network);
if (network_policy) {
VLOG(1) << "Network " << favorite.path() << " is managed by device policy.";
VLOG(1) << "Network " << network.path() << " is managed by device policy.";
*onc_source = ::onc::ONC_SOURCE_DEVICE_POLICY;
return network_policy;
}
VLOG(2) << "Network " << favorite.path() << " is unmanaged.";
VLOG(2) << "Network " << network.path() << " is unmanaged.";
return NULL;
}

bool HasPolicyForFavoriteNetwork(const PrefService* profile_prefs,
const PrefService* local_state_prefs,
const FavoriteState& network) {
bool HasPolicyForNetwork(const PrefService* profile_prefs,
const PrefService* local_state_prefs,
const NetworkState& network) {
::onc::ONCSource ignored_onc_source;
const base::DictionaryValue* policy = onc::GetPolicyForFavoriteNetwork(
const base::DictionaryValue* policy = onc::GetPolicyForNetwork(
profile_prefs, local_state_prefs, network, &ignored_onc_source);
return policy != NULL;
}
Expand Down
13 changes: 6 additions & 7 deletions chrome/browser/chromeos/net/onc_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class ListValue;

namespace chromeos {

class FavoriteState;
class NetworkState;
class User;

Expand Down Expand Up @@ -63,19 +62,19 @@ const base::DictionaryValue* GetGlobalConfigFromPolicy(bool for_active_user);
// GetGlobalConfigFromPolicy).
bool PolicyAllowsOnlyPolicyNetworksToAutoconnect(bool for_active_user);

// Returns the effective (user or device) policy for network |favorite|. Both
// Returns the effective (user or device) policy for network |network|. Both
// |profile_prefs| and |local_state_prefs| might be NULL. Returns NULL if no
// applicable policy is found. Sets |onc_source| accordingly.
const base::DictionaryValue* GetPolicyForFavoriteNetwork(
const base::DictionaryValue* GetPolicyForNetwork(
const PrefService* profile_prefs,
const PrefService* local_state_prefs,
const FavoriteState& favorite,
const NetworkState& network,
::onc::ONCSource* onc_source);

// Convenience function to check only whether a policy for a network exists.
bool HasPolicyForFavoriteNetwork(const PrefService* profile_prefs,
const PrefService* local_state_prefs,
const FavoriteState& network);
bool HasPolicyForNetwork(const PrefService* profile_prefs,
const PrefService* local_state_prefs,
const NetworkState& network);

} // namespace onc
} // namespace chromeos
Expand Down
12 changes: 6 additions & 6 deletions chrome/browser/chromeos/net/proxy_config_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
#include "chrome/common/pref_names.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/shill_service_client.h"
#include "chromeos/network/favorite_state.h"
#include "chromeos/network/network_handler_callbacks.h"
#include "chromeos/network/network_profile.h"
#include "chromeos/network/network_profile_handler.h"
#include "chromeos/network/network_state.h"
#include "chromeos/network/network_state_handler.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "dbus/object_path.h"
Expand All @@ -38,13 +38,13 @@ void NotifyNetworkStateHandler(const std::string& service_path) {

namespace proxy_config {

scoped_ptr<ProxyConfigDictionary> GetProxyConfigForFavoriteNetwork(
scoped_ptr<ProxyConfigDictionary> GetProxyConfigForNetwork(
const PrefService* profile_prefs,
const PrefService* local_state_prefs,
const FavoriteState& network,
const NetworkState& network,
::onc::ONCSource* onc_source) {
const base::DictionaryValue* network_policy =
onc::GetPolicyForFavoriteNetwork(
onc::GetPolicyForNetwork(
profile_prefs, local_state_prefs, network, onc_source);

if (network_policy) {
Expand Down Expand Up @@ -91,8 +91,8 @@ scoped_ptr<ProxyConfigDictionary> GetProxyConfigForFavoriteNetwork(
return make_scoped_ptr(new ProxyConfigDictionary(&value));
}

void SetProxyConfigForFavoriteNetwork(const ProxyConfigDictionary& proxy_config,
const FavoriteState& network) {
void SetProxyConfigForNetwork(const ProxyConfigDictionary& proxy_config,
const NetworkState& network) {
chromeos::ShillServiceClient* shill_service_client =
DBusThreadManager::Get()->GetShillServiceClient();

Expand Down
10 changes: 5 additions & 5 deletions chrome/browser/chromeos/net/proxy_config_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@ class PrefRegistrySyncable;

namespace chromeos {

class FavoriteState;
class NetworkState;

namespace proxy_config {

// Get the proxy configuration including per-network policies for network
// |network|. If |profile_prefs| is NULL, then only shared settings (and device
// policy) are respected. This is e.g. the case for the signin screen and the
// system request context.
scoped_ptr<ProxyConfigDictionary> GetProxyConfigForFavoriteNetwork(
scoped_ptr<ProxyConfigDictionary> GetProxyConfigForNetwork(
const PrefService* profile_prefs,
const PrefService* local_state_prefs,
const FavoriteState& network,
const NetworkState& network,
onc::ONCSource* onc_source);

void SetProxyConfigForFavoriteNetwork(const ProxyConfigDictionary& proxy_config,
const FavoriteState& network);
void SetProxyConfigForNetwork(const ProxyConfigDictionary& proxy_config,
const NetworkState& network);

void RegisterPrefs(PrefRegistrySimple* registry);

Expand Down
1 change: 0 additions & 1 deletion chrome/browser/chromeos/options/wifi_config_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include "chrome/browser/chromeos/options/passphrase_textfield.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chromeos/login/login_state.h"
#include "chromeos/network/favorite_state.h"
#include "chromeos/network/network_configuration_handler.h"
#include "chromeos/network/network_event_log.h"
#include "chromeos/network/network_handler.h"
Expand Down
7 changes: 3 additions & 4 deletions chrome/browser/chromeos/proxy_config_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include "chrome/browser/prefs/proxy_config_dictionary.h"
#include "chrome/browser/prefs/proxy_prefs.h"
#include "chrome/common/pref_names.h"
#include "chromeos/network/favorite_state.h"
#include "chromeos/network/network_profile.h"
#include "chromeos/network/network_profile_handler.h"
#include "chromeos/network/network_state.h"
Expand All @@ -35,11 +34,11 @@ namespace {
// proxy was configured for this network.
bool GetProxyConfig(const PrefService* profile_prefs,
const PrefService* local_state_prefs,
const FavoriteState& network,
const NetworkState& network,
net::ProxyConfig* proxy_config,
::onc::ONCSource* onc_source) {
scoped_ptr<ProxyConfigDictionary> proxy_dict =
proxy_config::GetProxyConfigForFavoriteNetwork(
proxy_config::GetProxyConfigForNetwork(
profile_prefs, local_state_prefs, network, onc_source);
if (!proxy_dict)
return false;
Expand Down Expand Up @@ -161,7 +160,7 @@ bool ProxyConfigServiceImpl::IgnoreProxy(const PrefService* profile_prefs,

void ProxyConfigServiceImpl::DetermineEffectiveConfigFromDefaultNetwork() {
NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler();
const FavoriteState* network = handler->DefaultFavoriteNetwork();
const NetworkState* network = handler->DefaultNetwork();

// Get prefs proxy config if available.
net::ProxyConfig pref_config;
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/chromeos/status/network_menu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ void MainMenuModel::InitMenuItems(bool should_open_button_options) {

// Get the list of all networks.
NetworkStateHandler::NetworkStateList network_list;
handler->GetNetworkList(&network_list);
handler->GetVisibleNetworkList(&network_list);

// Cellular Networks
if (handler->IsTechnologyEnabled(NetworkTypePattern::Cellular())) {
Expand Down
Loading

0 comments on commit fa0336f

Please sign in to comment.