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" |
13 #include "base/version.h" | 14 #include "base/version.h" |
14 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
15 #include "chrome/browser/component_updater/supervised_user_whitelist_installer.h " | 16 #include "chrome/browser/component_updater/supervised_user_whitelist_installer.h " |
16 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/profiles/profile_info_cache.h" | 18 #include "chrome/browser/profiles/profile_info_cache.h" |
18 #include "chrome/browser/profiles/profile_manager.h" | 19 #include "chrome/browser/profiles/profile_manager.h" |
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
613 url_filter_context_.LoadWhitelists(site_lists); | 614 url_filter_context_.LoadWhitelists(site_lists); |
614 } | 615 } |
615 | 616 |
616 void SupervisedUserService::OnSiteListUpdated() { | 617 void SupervisedUserService::OnSiteListUpdated() { |
617 FOR_EACH_OBSERVER( | 618 FOR_EACH_OBSERVER( |
618 SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged()); | 619 SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged()); |
619 } | 620 } |
620 | 621 |
621 void SupervisedUserService::LoadBlacklist(const base::FilePath& path, | 622 void SupervisedUserService::LoadBlacklist(const base::FilePath& path, |
622 const GURL& url) { | 623 const GURL& url) { |
623 // TODO(treib): Don't re-download the blacklist if the local file exists! | 624 BrowserThread::PostTaskAndReplyWithResult( |
624 if (!url.is_valid()) { | 625 BrowserThread::IO, |
Bernhard Bauer
2015/04/16 13:58:06
I don't think you want to do this on the IO thread
Marc Treib
2015/04/16 14:04:16
Argh, yeah, I ran into this before (the IO thread
Bernhard Bauer
2015/04/16 14:09:16
Yes, because it will use more than one thread, so
Marc Treib
2015/04/16 14:40:49
Got it, thanks! Done.
| |
626 FROM_HERE, | |
627 base::Bind(&base::PathExists, path), | |
628 base::Bind(&SupervisedUserService::OnBlacklistFileChecked, | |
629 weak_ptr_factory_.GetWeakPtr(), path, url)); | |
630 } | |
631 | |
632 void SupervisedUserService::OnBlacklistFileChecked(const base::FilePath& path, | |
633 const GURL& url, | |
634 bool file_exists) { | |
635 if (file_exists) { | |
625 LoadBlacklistFromFile(path); | 636 LoadBlacklistFromFile(path); |
626 return; | 637 return; |
627 } | 638 } |
628 | 639 |
629 DCHECK(!blacklist_downloader_); | 640 DCHECK(!blacklist_downloader_); |
630 blacklist_downloader_.reset(new SupervisedUserBlacklistDownloader( | 641 blacklist_downloader_.reset(new SupervisedUserBlacklistDownloader( |
631 url, | 642 url, |
632 path, | 643 path, |
633 profile_->GetRequestContext(), | 644 profile_->GetRequestContext(), |
634 base::Bind(&SupervisedUserService::OnBlacklistDownloadDone, | 645 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. | 959 // The active user can be NULL in unit tests. |
949 if (user_manager::UserManager::Get()->GetActiveUser()) { | 960 if (user_manager::UserManager::Get()->GetActiveUser()) { |
950 return UTF16ToUTF8(user_manager::UserManager::Get()->GetUserDisplayName( | 961 return UTF16ToUTF8(user_manager::UserManager::Get()->GetUserDisplayName( |
951 user_manager::UserManager::Get()->GetActiveUser()->GetUserID())); | 962 user_manager::UserManager::Get()->GetActiveUser()->GetUserID())); |
952 } | 963 } |
953 return std::string(); | 964 return std::string(); |
954 #else | 965 #else |
955 return profile_->GetPrefs()->GetString(prefs::kProfileName); | 966 return profile_->GetPrefs()->GetString(prefs::kProfileName); |
956 #endif | 967 #endif |
957 } | 968 } |
OLD | NEW |