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/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 site_lists_copy.push_back((*it)->Clone()); | 104 site_lists_copy.push_back((*it)->Clone()); |
105 } | 105 } |
106 ui_url_filter_->LoadWhitelists(site_lists.Pass()); | 106 ui_url_filter_->LoadWhitelists(site_lists.Pass()); |
107 BrowserThread::PostTask( | 107 BrowserThread::PostTask( |
108 BrowserThread::IO, | 108 BrowserThread::IO, |
109 FROM_HERE, | 109 FROM_HERE, |
110 base::Bind(&SupervisedUserURLFilter::LoadWhitelists, | 110 base::Bind(&SupervisedUserURLFilter::LoadWhitelists, |
111 io_url_filter_, base::Passed(&site_lists_copy))); | 111 io_url_filter_, base::Passed(&site_lists_copy))); |
112 } | 112 } |
113 | 113 |
| 114 void SupervisedUserService::URLFilterContext::LoadBlacklist( |
| 115 const base::FilePath& path) { |
| 116 // For now, support loading only once. If we want to support re-load, we'll |
| 117 // have to clear the blacklist pointer in the url filters first. |
| 118 DCHECK_EQ(0u, blacklist_.GetEntryCount()); |
| 119 blacklist_.ReadFromFile( |
| 120 path, |
| 121 base::Bind(&SupervisedUserService::URLFilterContext::OnBlacklistLoaded, |
| 122 base::Unretained(this))); |
| 123 } |
| 124 |
114 void SupervisedUserService::URLFilterContext::SetManualHosts( | 125 void SupervisedUserService::URLFilterContext::SetManualHosts( |
115 scoped_ptr<std::map<std::string, bool> > host_map) { | 126 scoped_ptr<std::map<std::string, bool> > host_map) { |
116 ui_url_filter_->SetManualHosts(host_map.get()); | 127 ui_url_filter_->SetManualHosts(host_map.get()); |
117 BrowserThread::PostTask( | 128 BrowserThread::PostTask( |
118 BrowserThread::IO, | 129 BrowserThread::IO, |
119 FROM_HERE, | 130 FROM_HERE, |
120 base::Bind(&SupervisedUserURLFilter::SetManualHosts, | 131 base::Bind(&SupervisedUserURLFilter::SetManualHosts, |
121 io_url_filter_, base::Owned(host_map.release()))); | 132 io_url_filter_, base::Owned(host_map.release()))); |
122 } | 133 } |
123 | 134 |
124 void SupervisedUserService::URLFilterContext::SetManualURLs( | 135 void SupervisedUserService::URLFilterContext::SetManualURLs( |
125 scoped_ptr<std::map<GURL, bool> > url_map) { | 136 scoped_ptr<std::map<GURL, bool> > url_map) { |
126 ui_url_filter_->SetManualURLs(url_map.get()); | 137 ui_url_filter_->SetManualURLs(url_map.get()); |
127 BrowserThread::PostTask( | 138 BrowserThread::PostTask( |
128 BrowserThread::IO, | 139 BrowserThread::IO, |
129 FROM_HERE, | 140 FROM_HERE, |
130 base::Bind(&SupervisedUserURLFilter::SetManualURLs, | 141 base::Bind(&SupervisedUserURLFilter::SetManualURLs, |
131 io_url_filter_, base::Owned(url_map.release()))); | 142 io_url_filter_, base::Owned(url_map.release()))); |
132 } | 143 } |
133 | 144 |
| 145 void SupervisedUserService::URLFilterContext::OnBlacklistLoaded() { |
| 146 ui_url_filter_->SetBlacklist(&blacklist_); |
| 147 BrowserThread::PostTask( |
| 148 BrowserThread::IO, |
| 149 FROM_HERE, |
| 150 base::Bind(&SupervisedUserURLFilter::SetBlacklist, |
| 151 io_url_filter_, |
| 152 &blacklist_)); |
| 153 } |
| 154 |
134 SupervisedUserService::SupervisedUserService(Profile* profile) | 155 SupervisedUserService::SupervisedUserService(Profile* profile) |
135 : profile_(profile), | 156 : profile_(profile), |
136 active_(false), | 157 active_(false), |
137 delegate_(NULL), | 158 delegate_(NULL), |
138 #if defined(ENABLE_EXTENSIONS) | 159 #if defined(ENABLE_EXTENSIONS) |
139 extension_registry_observer_(this), | 160 extension_registry_observer_(this), |
140 #endif | 161 #endif |
141 waiting_for_sync_initialization_(false), | 162 waiting_for_sync_initialization_(false), |
142 is_profile_active_(false), | 163 is_profile_active_(false), |
143 elevated_for_testing_(false), | 164 elevated_for_testing_(false), |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 SupervisedUserURLFilter::BehaviorFromInt(behavior_value); | 533 SupervisedUserURLFilter::BehaviorFromInt(behavior_value); |
513 url_filter_context_.SetDefaultFilteringBehavior(behavior); | 534 url_filter_context_.SetDefaultFilteringBehavior(behavior); |
514 } | 535 } |
515 | 536 |
516 void SupervisedUserService::UpdateSiteLists() { | 537 void SupervisedUserService::UpdateSiteLists() { |
517 #if defined(ENABLE_EXTENSIONS) | 538 #if defined(ENABLE_EXTENSIONS) |
518 url_filter_context_.LoadWhitelists(GetActiveSiteLists()); | 539 url_filter_context_.LoadWhitelists(GetActiveSiteLists()); |
519 #endif | 540 #endif |
520 } | 541 } |
521 | 542 |
| 543 void SupervisedUserService::LoadBlacklist(const base::FilePath& path) { |
| 544 url_filter_context_.LoadBlacklist(path); |
| 545 } |
| 546 |
522 bool SupervisedUserService::AccessRequestsEnabled() { | 547 bool SupervisedUserService::AccessRequestsEnabled() { |
523 if (waiting_for_permissions_) | 548 if (waiting_for_permissions_) |
524 return false; | 549 return false; |
525 | 550 |
526 ProfileSyncService* service = | 551 ProfileSyncService* service = |
527 ProfileSyncServiceFactory::GetForProfile(profile_); | 552 ProfileSyncServiceFactory::GetForProfile(profile_); |
528 GoogleServiceAuthError::State state = service->GetAuthError().state(); | 553 GoogleServiceAuthError::State state = service->GetAuthError().state(); |
529 // We allow requesting access if Sync is working or has a transient error. | 554 // We allow requesting access if Sync is working or has a transient error. |
530 return (state == GoogleServiceAuthError::NONE || | 555 return (state == GoogleServiceAuthError::NONE || |
531 state == GoogleServiceAuthError::CONNECTION_FAILED || | 556 state == GoogleServiceAuthError::CONNECTION_FAILED || |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
816 // The active user can be NULL in unit tests. | 841 // The active user can be NULL in unit tests. |
817 if (user_manager::UserManager::Get()->GetActiveUser()) { | 842 if (user_manager::UserManager::Get()->GetActiveUser()) { |
818 return UTF16ToUTF8(user_manager::UserManager::Get()->GetUserDisplayName( | 843 return UTF16ToUTF8(user_manager::UserManager::Get()->GetUserDisplayName( |
819 user_manager::UserManager::Get()->GetActiveUser()->GetUserID())); | 844 user_manager::UserManager::Get()->GetActiveUser()->GetUserID())); |
820 } | 845 } |
821 return std::string(); | 846 return std::string(); |
822 #else | 847 #else |
823 return profile_->GetPrefs()->GetString(prefs::kProfileName); | 848 return profile_->GetPrefs()->GetString(prefs::kProfileName); |
824 #endif | 849 #endif |
825 } | 850 } |
OLD | NEW |