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