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/files/file_util.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
| 13 #include "base/strings/stringprintf.h" |
13 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
14 #include "base/task_runner_util.h" | 15 #include "base/task_runner_util.h" |
15 #include "base/version.h" | 16 #include "base/version.h" |
16 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
17 #include "chrome/browser/component_updater/supervised_user_whitelist_installer.h
" | 18 #include "chrome/browser/component_updater/supervised_user_whitelist_installer.h
" |
18 #include "chrome/browser/net/file_downloader.h" | 19 #include "chrome/browser/net/file_downloader.h" |
19 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
20 #include "chrome/browser/profiles/profile_info_cache.h" | 21 #include "chrome/browser/profiles/profile_info_cache.h" |
21 #include "chrome/browser/profiles/profile_manager.h" | 22 #include "chrome/browser/profiles/profile_manager.h" |
22 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 23 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 creator->CreateURLAccessRequest(url, callback); | 103 creator->CreateURLAccessRequest(url, callback); |
103 } | 104 } |
104 | 105 |
105 void CreateExtensionUpdateRequest( | 106 void CreateExtensionUpdateRequest( |
106 const std::string& id, | 107 const std::string& id, |
107 PermissionRequestCreator* creator, | 108 PermissionRequestCreator* creator, |
108 const SupervisedUserService::SuccessCallback& callback) { | 109 const SupervisedUserService::SuccessCallback& callback) { |
109 creator->CreateExtensionUpdateRequest(id, callback); | 110 creator->CreateExtensionUpdateRequest(id, callback); |
110 } | 111 } |
111 | 112 |
| 113 // Default callback for AddExtensionUpdateRequest. |
| 114 void ExtensionUpdateRequestSent(const std::string& id, bool success) { |
| 115 VLOG_IF(1, !success) << "Failed sending update request for " << id; |
| 116 } |
| 117 |
112 base::FilePath GetBlacklistPath() { | 118 base::FilePath GetBlacklistPath() { |
113 base::FilePath blacklist_dir; | 119 base::FilePath blacklist_dir; |
114 PathService::Get(chrome::DIR_USER_DATA, &blacklist_dir); | 120 PathService::Get(chrome::DIR_USER_DATA, &blacklist_dir); |
115 return blacklist_dir.AppendASCII(kBlacklistFilename); | 121 return blacklist_dir.AppendASCII(kBlacklistFilename); |
116 } | 122 } |
117 | 123 |
118 #if defined(ENABLE_EXTENSIONS) | 124 #if defined(ENABLE_EXTENSIONS) |
119 enum ExtensionState { | 125 enum ExtensionState { |
120 EXTENSION_FORCED, | 126 EXTENSION_FORCED, |
121 EXTENSION_BLOCKED, | 127 EXTENSION_BLOCKED, |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 AddPermissionRequestInternal( | 245 AddPermissionRequestInternal( |
240 base::Bind(CreateURLAccessRequest, | 246 base::Bind(CreateURLAccessRequest, |
241 SupervisedUserURLFilter::Normalize(url)), | 247 SupervisedUserURLFilter::Normalize(url)), |
242 callback, 0); | 248 callback, 0); |
243 } | 249 } |
244 | 250 |
245 void SupervisedUserService::AddExtensionUpdateRequest( | 251 void SupervisedUserService::AddExtensionUpdateRequest( |
246 const std::string& extension_id, | 252 const std::string& extension_id, |
247 const base::Version& version, | 253 const base::Version& version, |
248 const SuccessCallback& callback) { | 254 const SuccessCallback& callback) { |
249 std::string id = extension_id + ":" + version.GetString(); | 255 std::string id = GetExtensionUpdateRequestId(extension_id, version); |
250 AddPermissionRequestInternal( | 256 AddPermissionRequestInternal( |
251 base::Bind(CreateExtensionUpdateRequest, id), | 257 base::Bind(CreateExtensionUpdateRequest, id), callback, 0); |
252 callback, 0); | 258 } |
| 259 |
| 260 void SupervisedUserService::AddExtensionUpdateRequest( |
| 261 const std::string& extension_id, |
| 262 const base::Version& version) { |
| 263 std::string id = GetExtensionUpdateRequestId(extension_id, version); |
| 264 AddExtensionUpdateRequest(extension_id, version, |
| 265 base::Bind(ExtensionUpdateRequestSent, id)); |
| 266 } |
| 267 |
| 268 // static |
| 269 std::string SupervisedUserService::GetExtensionUpdateRequestId( |
| 270 const std::string& extension_id, |
| 271 const base::Version& version) { |
| 272 return base::StringPrintf("%s:%s", extension_id.c_str(), |
| 273 version.GetString().c_str()); |
253 } | 274 } |
254 | 275 |
255 std::string SupervisedUserService::GetCustodianEmailAddress() const { | 276 std::string SupervisedUserService::GetCustodianEmailAddress() const { |
256 std::string email = profile_->GetPrefs()->GetString( | 277 std::string email = profile_->GetPrefs()->GetString( |
257 prefs::kSupervisedUserCustodianEmail); | 278 prefs::kSupervisedUserCustodianEmail); |
258 #if defined(OS_CHROMEOS) | 279 #if defined(OS_CHROMEOS) |
259 // |GetActiveUser()| can return null in unit tests. | 280 // |GetActiveUser()| can return null in unit tests. |
260 if (email.empty() && !!user_manager::UserManager::Get()->GetActiveUser()) { | 281 if (email.empty() && !!user_manager::UserManager::Get()->GetActiveUser()) { |
261 email = chromeos::ChromeUserManager::Get() | 282 email = chromeos::ChromeUserManager::Get() |
262 ->GetSupervisedUserManager() | 283 ->GetSupervisedUserManager() |
(...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
974 | 995 |
975 is_profile_active_ = profile_became_active; | 996 is_profile_active_ = profile_became_active; |
976 } | 997 } |
977 #endif // !defined(OS_ANDROID) && !defined(OS_IOS) | 998 #endif // !defined(OS_ANDROID) && !defined(OS_IOS) |
978 | 999 |
979 void SupervisedUserService::OnSiteListUpdated() { | 1000 void SupervisedUserService::OnSiteListUpdated() { |
980 FOR_EACH_OBSERVER( | 1001 FOR_EACH_OBSERVER( |
981 SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged()); | 1002 SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged()); |
982 } | 1003 } |
983 | 1004 |
OLD | NEW |