| 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 id = whitelist; | 79 id = whitelist; |
| 80 } | 80 } |
| 81 bool new_installation = true; | 81 bool new_installation = true; |
| 82 RegisterWhitelist(id, name, new_installation); | 82 RegisterWhitelist(id, name, new_installation); |
| 83 } | 83 } |
| 84 } | 84 } |
| 85 | 85 |
| 86 void SupervisedUserWhitelistService::AddSiteListsChangedCallback( | 86 void SupervisedUserWhitelistService::AddSiteListsChangedCallback( |
| 87 const SiteListsChangedCallback& callback) { | 87 const SiteListsChangedCallback& callback) { |
| 88 site_lists_changed_callbacks_.push_back(callback); | 88 site_lists_changed_callbacks_.push_back(callback); |
| 89 NotifyWhitelistsChanged(); | 89 |
| 90 std::vector<scoped_refptr<SupervisedUserSiteList>> whitelists; |
| 91 GetLoadedWhitelists(&whitelists); |
| 92 callback.Run(whitelists); |
| 90 } | 93 } |
| 91 | 94 |
| 92 void SupervisedUserWhitelistService::LoadWhitelistForTesting( | 95 void SupervisedUserWhitelistService::LoadWhitelistForTesting( |
| 93 const std::string& id, | 96 const std::string& id, |
| 94 const base::FilePath& path) { | 97 const base::FilePath& path) { |
| 95 bool result = registered_whitelists_.insert(id).second; | 98 bool result = registered_whitelists_.insert(id).second; |
| 96 DCHECK(result); | 99 DCHECK(result); |
| 97 OnWhitelistReady(id, path); | 100 OnWhitelistReady(id, path); |
| 98 } | 101 } |
| 99 | 102 |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 bool new_installation) { | 283 bool new_installation) { |
| 281 bool result = registered_whitelists_.insert(id).second; | 284 bool result = registered_whitelists_.insert(id).second; |
| 282 DCHECK(result); | 285 DCHECK(result); |
| 283 | 286 |
| 284 installer_->RegisterWhitelist( | 287 installer_->RegisterWhitelist( |
| 285 id, name, new_installation, | 288 id, name, new_installation, |
| 286 base::Bind(&SupervisedUserWhitelistService::OnWhitelistReady, | 289 base::Bind(&SupervisedUserWhitelistService::OnWhitelistReady, |
| 287 weak_ptr_factory_.GetWeakPtr(), id)); | 290 weak_ptr_factory_.GetWeakPtr(), id)); |
| 288 } | 291 } |
| 289 | 292 |
| 293 void SupervisedUserWhitelistService::GetLoadedWhitelists( |
| 294 std::vector<scoped_refptr<SupervisedUserSiteList>>* whitelists) { |
| 295 for (const auto& whitelist : loaded_whitelists_) |
| 296 whitelists->push_back(whitelist.second); |
| 297 } |
| 298 |
| 290 void SupervisedUserWhitelistService::NotifyWhitelistsChanged() { | 299 void SupervisedUserWhitelistService::NotifyWhitelistsChanged() { |
| 291 std::vector<scoped_refptr<SupervisedUserSiteList> > whitelists; | 300 std::vector<scoped_refptr<SupervisedUserSiteList>> whitelists; |
| 292 for (const auto& whitelist : loaded_whitelists_) | 301 GetLoadedWhitelists(&whitelists); |
| 293 whitelists.push_back(whitelist.second); | |
| 294 | 302 |
| 295 for (const auto& callback : site_lists_changed_callbacks_) | 303 for (const auto& callback : site_lists_changed_callbacks_) |
| 296 callback.Run(whitelists); | 304 callback.Run(whitelists); |
| 297 } | 305 } |
| 298 | 306 |
| 299 void SupervisedUserWhitelistService::OnWhitelistReady( | 307 void SupervisedUserWhitelistService::OnWhitelistReady( |
| 300 const std::string& id, | 308 const std::string& id, |
| 301 const base::FilePath& whitelist_path) { | 309 const base::FilePath& whitelist_path) { |
| 302 // If the whitelist has been unregistered in the mean time, ignore it. | 310 // If the whitelist has been unregistered in the mean time, ignore it. |
| 303 if (registered_whitelists_.count(id) == 0u) | 311 if (registered_whitelists_.count(id) == 0u) |
| (...skipping 17 matching lines...) Expand all Loading... |
| 321 UMA_HISTOGRAM_TIMES("ManagedUsers.Whitelist.TotalLoadDuration", | 329 UMA_HISTOGRAM_TIMES("ManagedUsers.Whitelist.TotalLoadDuration", |
| 322 base::TimeTicks::Now() - start_time); | 330 base::TimeTicks::Now() - start_time); |
| 323 | 331 |
| 324 // If the whitelist has been unregistered in the mean time, ignore it. | 332 // If the whitelist has been unregistered in the mean time, ignore it. |
| 325 if (registered_whitelists_.count(id) == 0u) | 333 if (registered_whitelists_.count(id) == 0u) |
| 326 return; | 334 return; |
| 327 | 335 |
| 328 loaded_whitelists_[id] = whitelist; | 336 loaded_whitelists_[id] = whitelist; |
| 329 NotifyWhitelistsChanged(); | 337 NotifyWhitelistsChanged(); |
| 330 } | 338 } |
| OLD | NEW |