OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #ifndef CHROMEOS_NETWORK_POLICY_APPLICATOR_H_ | 5 #ifndef CHROMEOS_NETWORK_POLICY_APPLICATOR_H_ |
6 #define CHROMEOS_NETWORK_POLICY_APPLICATOR_H_ | 6 #define CHROMEOS_NETWORK_POLICY_APPLICATOR_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "base/values.h" |
14 #include "chromeos/network/network_profile.h" | 15 #include "chromeos/network/network_profile.h" |
15 | 16 |
16 namespace base { | |
17 class DictionaryValue; | |
18 } | |
19 | |
20 namespace chromeos { | 17 namespace chromeos { |
21 | 18 |
22 // This class compares (entry point is Run()) |modified_policies| with the | 19 // This class compares (entry point is Run()) |modified_policies| with the |
23 // existing entries in the provided Shill profile |profile|. It fetches all | 20 // existing entries in the provided Shill profile |profile|. It fetches all |
24 // entries in parallel (GetProfilePropertiesCallback), compares each entry with | 21 // entries in parallel (GetProfilePropertiesCallback), compares each entry with |
25 // the current policies (GetEntryCallback) and adds all missing policies | 22 // the current policies (GetEntryCallback) and adds all missing policies |
26 // (~PolicyApplicator). | 23 // (~PolicyApplicator). |
27 class PolicyApplicator : public base::RefCounted<PolicyApplicator> { | 24 class PolicyApplicator : public base::RefCounted<PolicyApplicator> { |
28 public: | 25 public: |
29 class ConfigurationHandler { | 26 class ConfigurationHandler { |
30 public: | 27 public: |
31 virtual ~ConfigurationHandler() {} | 28 virtual ~ConfigurationHandler() {} |
32 // Write the new configuration with the properties |shill_properties| to | 29 // Write the new configuration with the properties |shill_properties| to |
33 // Shill. This configuration comes from a policy. Any conflicting or | 30 // Shill. This configuration comes from a policy. Any conflicting or |
34 // existing configuration for the same network will have been removed | 31 // existing configuration for the same network will have been removed |
35 // before. | 32 // before. |
36 virtual void CreateConfigurationFromPolicy( | 33 virtual void CreateConfigurationFromPolicy( |
37 const base::DictionaryValue& shill_properties) = 0; | 34 const base::DictionaryValue& shill_properties) = 0; |
38 | 35 |
| 36 virtual void UpdateExistingConfigurationWithPropertiesFromPolicy( |
| 37 const base::DictionaryValue& existing_properties, |
| 38 const base::DictionaryValue& new_properties) = 0; |
| 39 |
39 private: | 40 private: |
40 DISALLOW_ASSIGN(ConfigurationHandler); | 41 DISALLOW_ASSIGN(ConfigurationHandler); |
41 }; | 42 }; |
42 | 43 |
43 typedef std::map<std::string, const base::DictionaryValue*> GuidToPolicyMap; | 44 typedef std::map<std::string, const base::DictionaryValue*> GuidToPolicyMap; |
44 | 45 |
45 // |modified_policies| must not be NULL and will be empty afterwards. | 46 // |modified_policies| must not be NULL and will be empty afterwards. |
46 PolicyApplicator(base::WeakPtr<ConfigurationHandler> handler, | 47 PolicyApplicator(base::WeakPtr<ConfigurationHandler> handler, |
47 const NetworkProfile& profile, | 48 const NetworkProfile& profile, |
48 const GuidToPolicyMap& all_policies, | 49 const GuidToPolicyMap& all_policies, |
| 50 const base::DictionaryValue& global_network_config, |
49 std::set<std::string>* modified_policies); | 51 std::set<std::string>* modified_policies); |
50 | 52 |
51 void Run(); | 53 void Run(); |
52 | 54 |
53 private: | 55 private: |
54 friend class base::RefCounted<PolicyApplicator>; | 56 friend class base::RefCounted<PolicyApplicator>; |
55 | 57 |
56 // Called with the properties of the profile |profile_|. Requests the | 58 // Called with the properties of the profile |profile_|. Requests the |
57 // properties of each entry, which are processed by GetEntryCallback. | 59 // properties of each entry, which are processed by GetEntryCallback. |
58 void GetProfilePropertiesCallback( | 60 void GetProfilePropertiesCallback( |
59 const base::DictionaryValue& profile_properties); | 61 const base::DictionaryValue& profile_properties); |
60 | 62 |
61 // Called with the properties of the profile entry |entry|. Checks whether the | 63 // Called with the properties of the profile entry |entry|. Checks whether the |
62 // entry was previously managed, whether a current policy applies and then | 64 // entry was previously managed, whether a current policy applies and then |
63 // either updates, deletes or not touches the entry. | 65 // either updates, deletes or not touches the entry. |
64 void GetEntryCallback(const std::string& entry, | 66 void GetEntryCallback(const std::string& entry, |
65 const base::DictionaryValue& entry_properties); | 67 const base::DictionaryValue& entry_properties); |
66 | 68 |
67 // Sends Shill the command to delete profile entry |entry| from |profile_|. | 69 // Sends Shill the command to delete profile entry |entry| from |profile_|. |
68 void DeleteEntry(const std::string& entry); | 70 void DeleteEntry(const std::string& entry); |
69 | 71 |
70 // Creates a Shill configuration from the given parameters and sends them to | 72 // Creates a Shill configuration from the given parameters and sends them to |
71 // Shill. |user_settings| can be NULL if none exist. | 73 // Shill. |user_settings| can be NULL if none exist. |
72 void CreateAndWriteNewShillConfiguration( | 74 void CreateAndWriteNewShillConfiguration( |
73 const std::string& guid, | 75 const std::string& guid, |
74 const base::DictionaryValue& policy, | 76 const base::DictionaryValue& policy, |
75 const base::DictionaryValue* user_settings); | 77 const base::DictionaryValue* user_settings); |
76 | 78 |
| 79 // Adds properties to |properties_to_update|, which are enforced on an |
| 80 // unamaged network by the global network config of the policy. |
| 81 // |entry_properties| are the network's current properties read from its |
| 82 // profile entry. |
| 83 void GetPropertiesForUnmanagedEntry( |
| 84 const base::DictionaryValue& entry_properties, |
| 85 base::DictionaryValue* properties_to_update) const; |
| 86 |
77 // Called once all Profile entries are processed. Calls | 87 // Called once all Profile entries are processed. Calls |
78 // ApplyRemainingPolicies. | 88 // ApplyRemainingPolicies. |
79 virtual ~PolicyApplicator(); | 89 virtual ~PolicyApplicator(); |
80 | 90 |
81 // Creates new entries for all remaining policies, i.e. for which no matching | 91 // Creates new entries for all remaining policies, i.e. for which no matching |
82 // Profile entry was found. | 92 // Profile entry was found. |
83 void ApplyRemainingPolicies(); | 93 void ApplyRemainingPolicies(); |
84 | 94 |
85 std::set<std::string> remaining_policies_; | 95 std::set<std::string> remaining_policies_; |
86 base::WeakPtr<ConfigurationHandler> handler_; | 96 base::WeakPtr<ConfigurationHandler> handler_; |
87 NetworkProfile profile_; | 97 NetworkProfile profile_; |
88 GuidToPolicyMap all_policies_; | 98 GuidToPolicyMap all_policies_; |
| 99 base::DictionaryValue global_network_config_; |
89 | 100 |
90 DISALLOW_COPY_AND_ASSIGN(PolicyApplicator); | 101 DISALLOW_COPY_AND_ASSIGN(PolicyApplicator); |
91 }; | 102 }; |
92 | 103 |
93 } // namespace chromeos | 104 } // namespace chromeos |
94 | 105 |
95 #endif // CHROMEOS_NETWORK_POLICY_APPLICATOR_H_ | 106 #endif // CHROMEOS_NETWORK_POLICY_APPLICATOR_H_ |
OLD | NEW |