| 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_service.h" | 5 #include "chrome/browser/supervised_user/supervised_user_service.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/files/file_util.h" |
| 9 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 10 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 11 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/task_runner_util.h" |
| 13 #include "base/version.h" | 15 #include "base/version.h" |
| 14 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/component_updater/supervised_user_whitelist_installer.h
" | 17 #include "chrome/browser/component_updater/supervised_user_whitelist_installer.h
" |
| 16 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/profiles/profile_info_cache.h" | 19 #include "chrome/browser/profiles/profile_info_cache.h" |
| 18 #include "chrome/browser/profiles/profile_manager.h" | 20 #include "chrome/browser/profiles/profile_manager.h" |
| 19 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 21 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 20 #include "chrome/browser/signin/signin_manager_factory.h" | 22 #include "chrome/browser/signin/signin_manager_factory.h" |
| 21 #include "chrome/browser/supervised_user/experimental/supervised_user_blacklist_
downloader.h" | 23 #include "chrome/browser/supervised_user/experimental/supervised_user_blacklist_
downloader.h" |
| 22 #include "chrome/browser/supervised_user/experimental/supervised_user_filtering_
switches.h" | 24 #include "chrome/browser/supervised_user/experimental/supervised_user_filtering_
switches.h" |
| (...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 613 url_filter_context_.LoadWhitelists(site_lists); | 615 url_filter_context_.LoadWhitelists(site_lists); |
| 614 } | 616 } |
| 615 | 617 |
| 616 void SupervisedUserService::OnSiteListUpdated() { | 618 void SupervisedUserService::OnSiteListUpdated() { |
| 617 FOR_EACH_OBSERVER( | 619 FOR_EACH_OBSERVER( |
| 618 SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged()); | 620 SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged()); |
| 619 } | 621 } |
| 620 | 622 |
| 621 void SupervisedUserService::LoadBlacklist(const base::FilePath& path, | 623 void SupervisedUserService::LoadBlacklist(const base::FilePath& path, |
| 622 const GURL& url) { | 624 const GURL& url) { |
| 623 // TODO(treib): Don't re-download the blacklist if the local file exists! | 625 base::PostTaskAndReplyWithResult( |
| 624 if (!url.is_valid()) { | 626 BrowserThread::GetBlockingPool(), |
| 627 FROM_HERE, |
| 628 base::Bind(&base::PathExists, path), |
| 629 base::Bind(&SupervisedUserService::OnBlacklistFileChecked, |
| 630 weak_ptr_factory_.GetWeakPtr(), path, url)); |
| 631 } |
| 632 |
| 633 void SupervisedUserService::OnBlacklistFileChecked(const base::FilePath& path, |
| 634 const GURL& url, |
| 635 bool file_exists) { |
| 636 if (file_exists) { |
| 625 LoadBlacklistFromFile(path); | 637 LoadBlacklistFromFile(path); |
| 626 return; | 638 return; |
| 627 } | 639 } |
| 628 | 640 |
| 629 DCHECK(!blacklist_downloader_); | 641 DCHECK(!blacklist_downloader_); |
| 630 blacklist_downloader_.reset(new SupervisedUserBlacklistDownloader( | 642 blacklist_downloader_.reset(new SupervisedUserBlacklistDownloader( |
| 631 url, | 643 url, |
| 632 path, | 644 path, |
| 633 profile_->GetRequestContext(), | 645 profile_->GetRequestContext(), |
| 634 base::Bind(&SupervisedUserService::OnBlacklistDownloadDone, | 646 base::Bind(&SupervisedUserService::OnBlacklistDownloadDone, |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 948 // The active user can be NULL in unit tests. | 960 // The active user can be NULL in unit tests. |
| 949 if (user_manager::UserManager::Get()->GetActiveUser()) { | 961 if (user_manager::UserManager::Get()->GetActiveUser()) { |
| 950 return UTF16ToUTF8(user_manager::UserManager::Get()->GetUserDisplayName( | 962 return UTF16ToUTF8(user_manager::UserManager::Get()->GetUserDisplayName( |
| 951 user_manager::UserManager::Get()->GetActiveUser()->GetUserID())); | 963 user_manager::UserManager::Get()->GetActiveUser()->GetUserID())); |
| 952 } | 964 } |
| 953 return std::string(); | 965 return std::string(); |
| 954 #else | 966 #else |
| 955 return profile_->GetPrefs()->GetString(prefs::kProfileName); | 967 return profile_->GetPrefs()->GetString(prefs::kProfileName); |
| 956 #endif | 968 #endif |
| 957 } | 969 } |
| OLD | NEW |