onc_utils.h revision f8ee788a64d60abd8f2d742a5fdedde054ecd910
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 3// found in the LICENSE file. 4 5#ifndef CHROME_BROWSER_CHROMEOS_NET_ONC_UTILS_H_ 6#define CHROME_BROWSER_CHROMEOS_NET_ONC_UTILS_H_ 7 8#include <string> 9 10#include "base/memory/scoped_ptr.h" 11#include "components/onc/onc_constants.h" 12 13class PrefService; 14 15namespace base { 16class DictionaryValue; 17class ListValue; 18} 19 20namespace chromeos { 21 22class NetworkState; 23class User; 24 25namespace onc { 26 27// Translates |onc_proxy_settings|, which has to be a valid ONC ProxySettings 28// dictionary, to a ProxyConfig dictionary (see 29// chrome/browser/prefs/proxy_config_dictionary.h). 30// 31// This function is used to translate ONC ProxySettings to the "ProxyConfig" 32// field of the Shill configuration. 33scoped_ptr<base::DictionaryValue> ConvertOncProxySettingsToProxyConfig( 34 const base::DictionaryValue& onc_proxy_settings); 35 36// Replaces string placeholders in |network_configs|, which must be a list of 37// ONC NetworkConfigurations. Currently only user name placeholders are 38// implemented, which are replaced by attributes of the logged-in user with 39// |hashed_username|. 40void ExpandStringPlaceholdersInNetworksForUser( 41 const chromeos::User* user, 42 base::ListValue* network_configs); 43 44void ImportNetworksForUser(const chromeos::User* user, 45 const base::ListValue& network_configs, 46 std::string* error); 47 48// Looks up the policy for |guid| for the current active user and sets 49// |global_config| (if not NULL) and |onc_source| (if not NULL) accordingly. If 50// |guid| is empty, returns NULL and sets the |global_config| and |onc_source| 51// if a policy is found. 52const base::DictionaryValue* FindPolicyForActiveUser( 53 const std::string& guid, 54 ::onc::ONCSource* onc_source); 55 56// Returns the global network configuration section of the active user's network 57// policy (if |for_active_user| is true) or of the device policy. 58const base::DictionaryValue* GetGlobalConfigFromPolicy(bool for_active_user); 59 60// Convenvience function to retrieve the "AllowOnlyPolicyNetworksToAutoconnect" 61// setting from the global network configuration (see 62// GetGlobalConfigFromPolicy). 63bool PolicyAllowsOnlyPolicyNetworksToAutoconnect(bool for_active_user); 64 65// Returns the effective (user or device) policy for network |network|. Both 66// |profile_prefs| and |local_state_prefs| might be NULL. Returns NULL if no 67// applicable policy is found. Sets |onc_source| accordingly. 68const base::DictionaryValue* GetPolicyForNetwork( 69 const PrefService* profile_prefs, 70 const PrefService* local_state_prefs, 71 const NetworkState& network, 72 ::onc::ONCSource* onc_source); 73 74// Convenience function to check only whether a policy for a network exists. 75bool HasPolicyForNetwork(const PrefService* profile_prefs, 76 const PrefService* local_state_prefs, 77 const NetworkState& network); 78 79} // namespace onc 80} // namespace chromeos 81 82#endif // CHROME_BROWSER_CHROMEOS_NET_ONC_UTILS_H_ 83