OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/supervised_user/supervised_user_whitelist_service.h" | 5 #include "chrome/browser/supervised_user/supervised_user_whitelist_service.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 12 #include "base/metrics/user_metrics.h" |
| 13 #include "base/metrics/user_metrics_action.h" |
12 #include "base/prefs/pref_service.h" | 14 #include "base/prefs/pref_service.h" |
13 #include "base/prefs/scoped_user_pref_update.h" | 15 #include "base/prefs/scoped_user_pref_update.h" |
14 #include "base/strings/string_split.h" | 16 #include "base/strings/string_split.h" |
15 #include "base/values.h" | 17 #include "base/values.h" |
16 #include "chrome/browser/component_updater/supervised_user_whitelist_installer.h
" | 18 #include "chrome/browser/component_updater/supervised_user_whitelist_installer.h
" |
17 #include "chrome/browser/supervised_user/supervised_user_site_list.h" | 19 #include "chrome/browser/supervised_user/supervised_user_site_list.h" |
18 #include "chrome/common/chrome_switches.h" | 20 #include "chrome/common/chrome_switches.h" |
19 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
20 #include "components/pref_registry/pref_registry_syncable.h" | 22 #include "components/pref_registry/pref_registry_syncable.h" |
21 #include "sync/api/sync_change.h" | 23 #include "sync/api/sync_change.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 for (base::DictionaryValue::Iterator it(*whitelists); !it.IsAtEnd(); | 56 for (base::DictionaryValue::Iterator it(*whitelists); !it.IsAtEnd(); |
55 it.Advance()) { | 57 it.Advance()) { |
56 const base::DictionaryValue* dict = nullptr; | 58 const base::DictionaryValue* dict = nullptr; |
57 it.value().GetAsDictionary(&dict); | 59 it.value().GetAsDictionary(&dict); |
58 std::string name; | 60 std::string name; |
59 bool result = dict->GetString(kName, &name); | 61 bool result = dict->GetString(kName, &name); |
60 DCHECK(result); | 62 DCHECK(result); |
61 bool new_installation = false; | 63 bool new_installation = false; |
62 RegisterWhitelist(it.key(), name, new_installation); | 64 RegisterWhitelist(it.key(), name, new_installation); |
63 } | 65 } |
| 66 UMA_HISTOGRAM_COUNTS_100("ManagedUsers.Whitelist.Count", whitelists->size()); |
64 | 67 |
65 // Register whitelists specified on the command line. | 68 // Register whitelists specified on the command line. |
66 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 69 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
67 std::string command_line_whitelists = command_line->GetSwitchValueASCII( | 70 std::string command_line_whitelists = command_line->GetSwitchValueASCII( |
68 switches::kInstallSupervisedUserWhitelists); | 71 switches::kInstallSupervisedUserWhitelists); |
69 std::vector<std::string> split_whitelists; | 72 std::vector<std::string> split_whitelists; |
70 base::SplitString(command_line_whitelists, ',', &split_whitelists); | 73 base::SplitString(command_line_whitelists, ',', &split_whitelists); |
71 for (const std::string& whitelist : split_whitelists) { | 74 for (const std::string& whitelist : split_whitelists) { |
72 std::string id; | 75 std::string id; |
73 std::string name; | 76 std::string name; |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 | 253 |
251 if (whitelists_removed) | 254 if (whitelists_removed) |
252 NotifyWhitelistsChanged(); | 255 NotifyWhitelistsChanged(); |
253 | 256 |
254 return error; | 257 return error; |
255 } | 258 } |
256 | 259 |
257 void SupervisedUserWhitelistService::AddNewWhitelist( | 260 void SupervisedUserWhitelistService::AddNewWhitelist( |
258 base::DictionaryValue* pref_dict, | 261 base::DictionaryValue* pref_dict, |
259 const sync_pb::ManagedUserWhitelistSpecifics& whitelist) { | 262 const sync_pb::ManagedUserWhitelistSpecifics& whitelist) { |
| 263 base::RecordAction(base::UserMetricsAction("ManagedUsers_Whitelist_Added")); |
| 264 |
260 bool new_installation = true; | 265 bool new_installation = true; |
261 RegisterWhitelist(whitelist.id(), whitelist.name(), new_installation); | 266 RegisterWhitelist(whitelist.id(), whitelist.name(), new_installation); |
262 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue); | 267 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue); |
263 SetWhitelistProperties(dict.get(), whitelist); | 268 SetWhitelistProperties(dict.get(), whitelist); |
264 pref_dict->SetWithoutPathExpansion(whitelist.id(), dict.release()); | 269 pref_dict->SetWithoutPathExpansion(whitelist.id(), dict.release()); |
265 } | 270 } |
266 | 271 |
267 void SupervisedUserWhitelistService::SetWhitelistProperties( | 272 void SupervisedUserWhitelistService::SetWhitelistProperties( |
268 base::DictionaryValue* dict, | 273 base::DictionaryValue* dict, |
269 const sync_pb::ManagedUserWhitelistSpecifics& whitelist) { | 274 const sync_pb::ManagedUserWhitelistSpecifics& whitelist) { |
270 dict->SetString(kName, whitelist.name()); | 275 dict->SetString(kName, whitelist.name()); |
271 } | 276 } |
272 | 277 |
273 void SupervisedUserWhitelistService::RemoveWhitelist( | 278 void SupervisedUserWhitelistService::RemoveWhitelist( |
274 base::DictionaryValue* pref_dict, | 279 base::DictionaryValue* pref_dict, |
275 const std::string& id) { | 280 const std::string& id) { |
| 281 base::RecordAction(base::UserMetricsAction("ManagedUsers_Whitelist_Removed")); |
| 282 |
276 pref_dict->RemoveWithoutPathExpansion(id, NULL); | 283 pref_dict->RemoveWithoutPathExpansion(id, NULL); |
277 installer_->UnregisterWhitelist(id); | 284 installer_->UnregisterWhitelist(id); |
278 UnloadWhitelist(id); | 285 UnloadWhitelist(id); |
279 } | 286 } |
280 | 287 |
281 void SupervisedUserWhitelistService::RegisterWhitelist(const std::string& id, | 288 void SupervisedUserWhitelistService::RegisterWhitelist(const std::string& id, |
282 const std::string& name, | 289 const std::string& name, |
283 bool new_installation) { | 290 bool new_installation) { |
284 bool result = registered_whitelists_.insert(id).second; | 291 bool result = registered_whitelists_.insert(id).second; |
285 DCHECK(result); | 292 DCHECK(result); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 UMA_HISTOGRAM_TIMES("ManagedUsers.Whitelist.TotalLoadDuration", | 336 UMA_HISTOGRAM_TIMES("ManagedUsers.Whitelist.TotalLoadDuration", |
330 base::TimeTicks::Now() - start_time); | 337 base::TimeTicks::Now() - start_time); |
331 | 338 |
332 // If the whitelist has been unregistered in the mean time, ignore it. | 339 // If the whitelist has been unregistered in the mean time, ignore it. |
333 if (registered_whitelists_.count(id) == 0u) | 340 if (registered_whitelists_.count(id) == 0u) |
334 return; | 341 return; |
335 | 342 |
336 loaded_whitelists_[id] = whitelist; | 343 loaded_whitelists_[id] = whitelist; |
337 NotifyWhitelistsChanged(); | 344 NotifyWhitelistsChanged(); |
338 } | 345 } |
OLD | NEW |