Chromium Code Reviews| 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" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 77 std::string id; | 77 std::string id; |
| 78 std::string name; | 78 std::string name; |
| 79 size_t separator = whitelist.find(':'); | 79 size_t separator = whitelist.find(':'); |
| 80 if (separator != base::StringPiece::npos) { | 80 if (separator != base::StringPiece::npos) { |
| 81 whitelist.substr(0, separator).CopyToString(&id); | 81 whitelist.substr(0, separator).CopyToString(&id); |
| 82 whitelist.substr(separator + 1).CopyToString(&name); | 82 whitelist.substr(separator + 1).CopyToString(&name); |
| 83 } else { | 83 } else { |
| 84 whitelist.CopyToString(&id); | 84 whitelist.CopyToString(&id); |
| 85 } | 85 } |
| 86 | 86 |
| 87 // Skip whitelists that were already registered. | 87 RegisterWhitelist(id, name, FROM_COMMAND_LINE); |
| 88 if (registered_whitelists_.count(id) > 0u) | |
| 89 continue; | |
| 90 | |
| 91 bool new_installation = true; | |
| 92 RegisterWhitelist(id, name, new_installation); | |
| 93 } | 88 } |
| 94 } | 89 } |
| 95 | 90 |
| 96 void SupervisedUserWhitelistService::AddSiteListsChangedCallback( | 91 void SupervisedUserWhitelistService::AddSiteListsChangedCallback( |
| 97 const SiteListsChangedCallback& callback) { | 92 const SiteListsChangedCallback& callback) { |
| 98 site_lists_changed_callbacks_.push_back(callback); | 93 site_lists_changed_callbacks_.push_back(callback); |
| 99 | 94 |
| 100 std::vector<scoped_refptr<SupervisedUserSiteList>> whitelists; | 95 std::vector<scoped_refptr<SupervisedUserSiteList>> whitelists; |
| 101 GetLoadedWhitelists(&whitelists); | 96 GetLoadedWhitelists(&whitelists); |
| 102 callback.Run(whitelists); | 97 callback.Run(whitelists); |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 262 NotifyWhitelistsChanged(); | 257 NotifyWhitelistsChanged(); |
| 263 | 258 |
| 264 return error; | 259 return error; |
| 265 } | 260 } |
| 266 | 261 |
| 267 void SupervisedUserWhitelistService::AddNewWhitelist( | 262 void SupervisedUserWhitelistService::AddNewWhitelist( |
| 268 base::DictionaryValue* pref_dict, | 263 base::DictionaryValue* pref_dict, |
| 269 const sync_pb::ManagedUserWhitelistSpecifics& whitelist) { | 264 const sync_pb::ManagedUserWhitelistSpecifics& whitelist) { |
| 270 base::RecordAction(base::UserMetricsAction("ManagedUsers_Whitelist_Added")); | 265 base::RecordAction(base::UserMetricsAction("ManagedUsers_Whitelist_Added")); |
| 271 | 266 |
| 272 bool new_installation = true; | 267 RegisterWhitelist(whitelist.id(), whitelist.name(), FROM_SYNC); |
| 273 RegisterWhitelist(whitelist.id(), whitelist.name(), new_installation); | |
| 274 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue); | 268 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue); |
| 275 SetWhitelistProperties(dict.get(), whitelist); | 269 SetWhitelistProperties(dict.get(), whitelist); |
| 276 pref_dict->SetWithoutPathExpansion(whitelist.id(), dict.release()); | 270 pref_dict->SetWithoutPathExpansion(whitelist.id(), dict.release()); |
| 277 } | 271 } |
| 278 | 272 |
| 279 void SupervisedUserWhitelistService::SetWhitelistProperties( | 273 void SupervisedUserWhitelistService::SetWhitelistProperties( |
| 280 base::DictionaryValue* dict, | 274 base::DictionaryValue* dict, |
| 281 const sync_pb::ManagedUserWhitelistSpecifics& whitelist) { | 275 const sync_pb::ManagedUserWhitelistSpecifics& whitelist) { |
| 282 dict->SetString(kName, whitelist.name()); | 276 dict->SetString(kName, whitelist.name()); |
| 283 } | 277 } |
| 284 | 278 |
| 285 void SupervisedUserWhitelistService::RemoveWhitelist( | 279 void SupervisedUserWhitelistService::RemoveWhitelist( |
| 286 base::DictionaryValue* pref_dict, | 280 base::DictionaryValue* pref_dict, |
| 287 const std::string& id) { | 281 const std::string& id) { |
| 288 base::RecordAction(base::UserMetricsAction("ManagedUsers_Whitelist_Removed")); | 282 base::RecordAction(base::UserMetricsAction("ManagedUsers_Whitelist_Removed")); |
| 289 | 283 |
| 290 pref_dict->RemoveWithoutPathExpansion(id, NULL); | 284 pref_dict->RemoveWithoutPathExpansion(id, NULL); |
| 291 installer_->UnregisterWhitelist(client_id_, id); | 285 installer_->UnregisterWhitelist(client_id_, id); |
| 292 UnloadWhitelist(id); | 286 UnloadWhitelist(id); |
| 293 } | 287 } |
| 294 | 288 |
| 295 void SupervisedUserWhitelistService::RegisterWhitelist(const std::string& id, | 289 void SupervisedUserWhitelistService::RegisterWhitelist(const std::string& id, |
| 296 const std::string& name, | 290 const std::string& name, |
| 297 bool new_installation) { | 291 WhitelistSource source) { |
| 298 bool result = registered_whitelists_.insert(id).second; | 292 bool result = registered_whitelists_.insert(id).second; |
| 299 DCHECK(result); | 293 DCHECK(result); |
| 300 | 294 |
| 301 installer_->RegisterWhitelist(client_id_, id, name); | 295 // Using an empty client ID for whitelists installed from the command line |
| 296 // causes the installer to not persist the installation, so the whitelist will | |
| 297 // be removed the next time the browser is started without the command line | |
| 298 // flag. | |
| 299 std::string client_id; | |
| 300 if (source == FROM_SYNC) | |
| 301 client_id = client_id_; | |
|
Marc Treib
2015/10/16 11:03:58
nit: I'd have put this inline, like
(source == FRO
Bernhard Bauer
2015/10/16 11:23:13
Done.
| |
| 302 | |
| 303 installer_->RegisterWhitelist(client_id, id, name); | |
| 302 } | 304 } |
| 303 | 305 |
| 304 void SupervisedUserWhitelistService::GetLoadedWhitelists( | 306 void SupervisedUserWhitelistService::GetLoadedWhitelists( |
| 305 std::vector<scoped_refptr<SupervisedUserSiteList>>* whitelists) { | 307 std::vector<scoped_refptr<SupervisedUserSiteList>>* whitelists) { |
| 306 for (const auto& whitelist : loaded_whitelists_) | 308 for (const auto& whitelist : loaded_whitelists_) |
| 307 whitelists->push_back(whitelist.second); | 309 whitelists->push_back(whitelist.second); |
| 308 } | 310 } |
| 309 | 311 |
| 310 void SupervisedUserWhitelistService::NotifyWhitelistsChanged() { | 312 void SupervisedUserWhitelistService::NotifyWhitelistsChanged() { |
| 311 std::vector<scoped_refptr<SupervisedUserSiteList>> whitelists; | 313 std::vector<scoped_refptr<SupervisedUserSiteList>> whitelists; |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 341 UMA_HISTOGRAM_TIMES("ManagedUsers.Whitelist.TotalLoadDuration", | 343 UMA_HISTOGRAM_TIMES("ManagedUsers.Whitelist.TotalLoadDuration", |
| 342 base::TimeTicks::Now() - start_time); | 344 base::TimeTicks::Now() - start_time); |
| 343 | 345 |
| 344 // If the whitelist has been unregistered in the mean time, ignore it. | 346 // If the whitelist has been unregistered in the mean time, ignore it. |
| 345 if (registered_whitelists_.count(id) == 0u) | 347 if (registered_whitelists_.count(id) == 0u) |
| 346 return; | 348 return; |
| 347 | 349 |
| 348 loaded_whitelists_[id] = whitelist; | 350 loaded_whitelists_[id] = whitelist; |
| 349 NotifyWhitelistsChanged(); | 351 NotifyWhitelistsChanged(); |
| 350 } | 352 } |
| OLD | NEW |