[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 5 | #include "chrome/browser/supervised_user/supervised_user_service.h" |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 6 | |
[email protected] | a19df3e | 2013-05-21 00:03:03 | [diff] [blame] | 7 | #include "base/command_line.h" |
treib | daece84f | 2014-09-05 12:58:15 | [diff] [blame] | 8 | #include "base/files/file_path.h" |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 9 | #include "base/memory/ref_counted.h" |
treib | d3f8b7a | 2015-04-10 11:41:33 | [diff] [blame] | 10 | #include "base/path_service.h" |
[email protected] | 3853a4c | 2013-02-11 17:15:57 | [diff] [blame] | 11 | #include "base/prefs/pref_service.h" |
[email protected] | 112158af | 2013-06-07 23:46:18 | [diff] [blame] | 12 | #include "base/strings/utf_string_conversions.h" |
treib | f832a99 | 2015-03-24 18:09:24 | [diff] [blame] | 13 | #include "base/version.h" |
[email protected] | 5ddfade | 2014-02-03 10:24:53 | [diff] [blame] | 14 | #include "chrome/browser/browser_process.h" |
bauerb | 4da3613 | 2014-12-26 19:53:13 | [diff] [blame] | 15 | #include "chrome/browser/component_updater/supervised_user_whitelist_installer.h" |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 16 | #include "chrome/browser/profiles/profile.h" |
[email protected] | 5ddfade | 2014-02-03 10:24:53 | [diff] [blame] | 17 | #include "chrome/browser/profiles/profile_info_cache.h" |
| 18 | #include "chrome/browser/profiles/profile_manager.h" |
[email protected] | aab94691 | 2013-11-06 22:18:51 | [diff] [blame] | 19 | #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
[email protected] | f252df2e | 2013-06-06 23:47:19 | [diff] [blame] | 20 | #include "chrome/browser/signin/signin_manager_factory.h" |
treib | f136dfb | 2014-09-25 17:37:47 | [diff] [blame] | 21 | #include "chrome/browser/supervised_user/experimental/supervised_user_blacklist_downloader.h" |
treib | e2082a0e | 2015-04-08 10:15:30 | [diff] [blame] | 22 | #include "chrome/browser/supervised_user/experimental/supervised_user_filtering_switches.h" |
treib | b473df2 | 2015-01-08 18:08:26 | [diff] [blame] | 23 | #include "chrome/browser/supervised_user/legacy/custodian_profile_downloader_service.h" |
| 24 | #include "chrome/browser/supervised_user/legacy/custodian_profile_downloader_service_factory.h" |
| 25 | #include "chrome/browser/supervised_user/legacy/permission_request_creator_sync.h" |
| 26 | #include "chrome/browser/supervised_user/legacy/supervised_user_pref_mapping_service.h" |
| 27 | #include "chrome/browser/supervised_user/legacy/supervised_user_pref_mapping_service_factory.h" |
| 28 | #include "chrome/browser/supervised_user/legacy/supervised_user_registration_utility.h" |
| 29 | #include "chrome/browser/supervised_user/legacy/supervised_user_shared_settings_service_factory.h" |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 30 | #include "chrome/browser/supervised_user/supervised_user_constants.h" |
treib | ab0a39e | 2014-09-24 14:48:28 | [diff] [blame] | 31 | #include "chrome/browser/supervised_user/supervised_user_service_observer.h" |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 32 | #include "chrome/browser/supervised_user/supervised_user_settings_service.h" |
| 33 | #include "chrome/browser/supervised_user/supervised_user_settings_service_factory.h" |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 34 | #include "chrome/browser/supervised_user/supervised_user_site_list.h" |
bauerb | 4da3613 | 2014-12-26 19:53:13 | [diff] [blame] | 35 | #include "chrome/browser/supervised_user/supervised_user_whitelist_service.h" |
[email protected] | a19df3e | 2013-05-21 00:03:03 | [diff] [blame] | 36 | #include "chrome/browser/sync/profile_sync_service.h" |
| 37 | #include "chrome/browser/sync/profile_sync_service_factory.h" |
[email protected] | 509ad1a9 | 2013-03-19 21:41:06 | [diff] [blame] | 38 | #include "chrome/browser/ui/browser.h" |
[email protected] | dfddd02 | 2013-07-10 17:29:48 | [diff] [blame] | 39 | #include "chrome/browser/ui/browser_list.h" |
treib | d3f8b7a | 2015-04-10 11:41:33 | [diff] [blame] | 40 | #include "chrome/common/chrome_paths.h" |
[email protected] | a19df3e | 2013-05-21 00:03:03 | [diff] [blame] | 41 | #include "chrome/common/chrome_switches.h" |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 42 | #include "chrome/common/pref_names.h" |
[email protected] | af39f00 | 2014-08-22 10:18:18 | [diff] [blame] | 43 | #include "chrome/grit/generated_resources.h" |
[email protected] | f0c8c499 | 2014-05-15 17:37:26 | [diff] [blame] | 44 | #include "components/pref_registry/pref_registry_syncable.h" |
[email protected] | 7274ef0 | 2014-03-24 22:43:40 | [diff] [blame] | 45 | #include "components/signin/core/browser/profile_oauth2_token_service.h" |
[email protected] | 7fbd3b1 | 2014-04-01 11:19:16 | [diff] [blame] | 46 | #include "components/signin/core/browser/signin_manager.h" |
[email protected] | 63c7f0c | 2014-03-25 21:12:59 | [diff] [blame] | 47 | #include "components/signin/core/browser/signin_manager_base.h" |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 48 | #include "content/public/browser/browser_thread.h" |
[email protected] | 2056c3b | 2014-04-07 18:08:50 | [diff] [blame] | 49 | #include "content/public/browser/user_metrics.h" |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 50 | #include "ui/base/l10n/l10n_util.h" |
| 51 | |
[email protected] | 3aacc9c | 2013-08-08 11:19:31 | [diff] [blame] | 52 | #if defined(OS_CHROMEOS) |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 53 | #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" |
[email protected] | 83d82d4 | 2014-05-16 02:04:42 | [diff] [blame] | 54 | #include "chrome/browser/chromeos/login/users/supervised_user_manager.h" |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 55 | #include "components/user_manager/user_manager.h" |
[email protected] | 3aacc9c | 2013-08-08 11:19:31 | [diff] [blame] | 56 | #endif |
| 57 | |
[email protected] | c14a680 | 2014-07-11 21:51:12 | [diff] [blame] | 58 | #if defined(ENABLE_EXTENSIONS) |
treib | 9e30e30 | 2015-04-15 08:12:16 | [diff] [blame^] | 59 | #include "chrome/browser/extensions/extension_service.h" |
[email protected] | c14a680 | 2014-07-11 21:51:12 | [diff] [blame] | 60 | #include "extensions/browser/extension_system.h" |
[email protected] | c14a680 | 2014-07-11 21:51:12 | [diff] [blame] | 61 | #endif |
| 62 | |
[email protected] | f085fdd5 | 2014-06-11 18:09:20 | [diff] [blame] | 63 | #if defined(ENABLE_THEMES) |
| 64 | #include "chrome/browser/themes/theme_service.h" |
| 65 | #include "chrome/browser/themes/theme_service_factory.h" |
| 66 | #endif |
| 67 | |
[email protected] | a581ea2 | 2013-05-06 12:34:19 | [diff] [blame] | 68 | using base::DictionaryValue; |
[email protected] | 2056c3b | 2014-04-07 18:08:50 | [diff] [blame] | 69 | using base::UserMetricsAction; |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 70 | using content::BrowserThread; |
| 71 | |
treib | 22c3a04 | 2015-01-15 21:30:13 | [diff] [blame] | 72 | namespace { |
| 73 | |
treib | d3f8b7a | 2015-04-10 11:41:33 | [diff] [blame] | 74 | // The URL from which to download a host blacklist if no local one exists yet. |
| 75 | const char kBlacklistURL[] = |
| 76 | "https://www.gstatic.com/chrome/supervised_user/blacklist-20141001-1k.bin"; |
| 77 | // The filename under which we'll store the blacklist (in the user data dir). |
| 78 | const char kBlacklistFilename[] = "su-blacklist.bin"; |
| 79 | |
treib | 22c3a04 | 2015-01-15 21:30:13 | [diff] [blame] | 80 | const char* const kCustodianInfoPrefs[] = { |
| 81 | prefs::kSupervisedUserCustodianName, |
| 82 | prefs::kSupervisedUserCustodianEmail, |
| 83 | prefs::kSupervisedUserCustodianProfileImageURL, |
| 84 | prefs::kSupervisedUserCustodianProfileURL, |
| 85 | prefs::kSupervisedUserSecondCustodianName, |
| 86 | prefs::kSupervisedUserSecondCustodianEmail, |
| 87 | prefs::kSupervisedUserSecondCustodianProfileImageURL, |
| 88 | prefs::kSupervisedUserSecondCustodianProfileURL, |
| 89 | }; |
| 90 | |
treib | 8ecc1eb5 | 2015-03-04 18:29:06 | [diff] [blame] | 91 | void CreateURLAccessRequest( |
| 92 | const GURL& url, |
| 93 | PermissionRequestCreator* creator, |
| 94 | const SupervisedUserService::SuccessCallback& callback) { |
| 95 | creator->CreateURLAccessRequest(url, callback); |
| 96 | } |
| 97 | |
| 98 | void CreateExtensionUpdateRequest( |
treib | f832a99 | 2015-03-24 18:09:24 | [diff] [blame] | 99 | const std::string& id, |
treib | 8ecc1eb5 | 2015-03-04 18:29:06 | [diff] [blame] | 100 | PermissionRequestCreator* creator, |
| 101 | const SupervisedUserService::SuccessCallback& callback) { |
treib | f832a99 | 2015-03-24 18:09:24 | [diff] [blame] | 102 | creator->CreateExtensionUpdateRequest(id, callback); |
treib | 8ecc1eb5 | 2015-03-04 18:29:06 | [diff] [blame] | 103 | } |
| 104 | |
treib | d3f8b7a | 2015-04-10 11:41:33 | [diff] [blame] | 105 | base::FilePath GetBlacklistPath() { |
| 106 | base::FilePath blacklist_dir; |
| 107 | PathService::Get(chrome::DIR_USER_DATA, &blacklist_dir); |
| 108 | return blacklist_dir.AppendASCII(kBlacklistFilename); |
| 109 | } |
| 110 | |
treib | bb9a196 | 2015-02-25 13:40:59 | [diff] [blame] | 111 | #if defined(ENABLE_EXTENSIONS) |
| 112 | enum ExtensionState { |
| 113 | EXTENSION_FORCED, |
| 114 | EXTENSION_BLOCKED, |
| 115 | EXTENSION_ALLOWED |
| 116 | }; |
| 117 | |
| 118 | ExtensionState GetExtensionState(const extensions::Extension* extension) { |
treib | bb9a196 | 2015-02-25 13:40:59 | [diff] [blame] | 119 | bool was_installed_by_default = extension->was_installed_by_default(); |
treib | bb9a196 | 2015-02-25 13:40:59 | [diff] [blame] | 120 | #if defined(OS_CHROMEOS) |
| 121 | // On Chrome OS all external sources are controlled by us so it means that |
| 122 | // they are "default". Method was_installed_by_default returns false because |
| 123 | // extensions creation flags are ignored in case of default extensions with |
| 124 | // update URL(the flags aren't passed to OnExternalExtensionUpdateUrlFound). |
| 125 | // TODO(dpolukhin): remove this Chrome OS specific code as soon as creation |
| 126 | // flags are not ignored. |
| 127 | was_installed_by_default = |
| 128 | extensions::Manifest::IsExternalLocation(extension->location()); |
| 129 | #endif |
treib | 2fc0934 | 2015-04-09 15:53:58 | [diff] [blame] | 130 | // Note: Component extensions are protected from modification/uninstallation |
| 131 | // anyway, so there's no need to enforce them again for supervised users. |
treib | bb9a196 | 2015-02-25 13:40:59 | [diff] [blame] | 132 | if (extensions::Manifest::IsComponentLocation(extension->location()) || |
treib | 2fc0934 | 2015-04-09 15:53:58 | [diff] [blame] | 133 | extension->is_theme() || |
| 134 | was_installed_by_default) { |
| 135 | return EXTENSION_ALLOWED; |
treib | bb9a196 | 2015-02-25 13:40:59 | [diff] [blame] | 136 | } |
| 137 | |
treib | 2fc0934 | 2015-04-09 15:53:58 | [diff] [blame] | 138 | if (extension->was_installed_by_custodian()) |
| 139 | return EXTENSION_FORCED; |
| 140 | |
treib | bb9a196 | 2015-02-25 13:40:59 | [diff] [blame] | 141 | return EXTENSION_BLOCKED; |
| 142 | } |
| 143 | #endif |
| 144 | |
treib | 22c3a04 | 2015-01-15 21:30:13 | [diff] [blame] | 145 | } // namespace |
| 146 | |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 147 | SupervisedUserService::URLFilterContext::URLFilterContext() |
| 148 | : ui_url_filter_(new SupervisedUserURLFilter), |
| 149 | io_url_filter_(new SupervisedUserURLFilter) {} |
| 150 | SupervisedUserService::URLFilterContext::~URLFilterContext() {} |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 151 | |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 152 | SupervisedUserURLFilter* |
| 153 | SupervisedUserService::URLFilterContext::ui_url_filter() const { |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 154 | return ui_url_filter_.get(); |
| 155 | } |
| 156 | |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 157 | SupervisedUserURLFilter* |
| 158 | SupervisedUserService::URLFilterContext::io_url_filter() const { |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 159 | return io_url_filter_.get(); |
| 160 | } |
| 161 | |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 162 | void SupervisedUserService::URLFilterContext::SetDefaultFilteringBehavior( |
| 163 | SupervisedUserURLFilter::FilteringBehavior behavior) { |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 164 | ui_url_filter_->SetDefaultFilteringBehavior(behavior); |
| 165 | BrowserThread::PostTask( |
| 166 | BrowserThread::IO, |
| 167 | FROM_HERE, |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 168 | base::Bind(&SupervisedUserURLFilter::SetDefaultFilteringBehavior, |
[email protected] | 5e02229 | 2013-02-06 16:42:17 | [diff] [blame] | 169 | io_url_filter_.get(), behavior)); |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 170 | } |
| 171 | |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 172 | void SupervisedUserService::URLFilterContext::LoadWhitelists( |
bauerb | 95a5068 | 2015-01-07 17:04:15 | [diff] [blame] | 173 | const std::vector<scoped_refptr<SupervisedUserSiteList> >& site_lists) { |
| 174 | ui_url_filter_->LoadWhitelists(site_lists); |
| 175 | BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 176 | base::Bind(&SupervisedUserURLFilter::LoadWhitelists, |
| 177 | io_url_filter_, site_lists)); |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 178 | } |
| 179 | |
treib | 4edbded | 2014-09-05 08:43:55 | [diff] [blame] | 180 | void SupervisedUserService::URLFilterContext::LoadBlacklist( |
bauerb | ce9a1a8 | 2014-12-18 13:34:24 | [diff] [blame] | 181 | const base::FilePath& path, |
| 182 | const base::Closure& callback) { |
treib | 4edbded | 2014-09-05 08:43:55 | [diff] [blame] | 183 | // For now, support loading only once. If we want to support re-load, we'll |
| 184 | // have to clear the blacklist pointer in the url filters first. |
| 185 | DCHECK_EQ(0u, blacklist_.GetEntryCount()); |
| 186 | blacklist_.ReadFromFile( |
| 187 | path, |
| 188 | base::Bind(&SupervisedUserService::URLFilterContext::OnBlacklistLoaded, |
bauerb | ce9a1a8 | 2014-12-18 13:34:24 | [diff] [blame] | 189 | base::Unretained(this), callback)); |
treib | 4edbded | 2014-09-05 08:43:55 | [diff] [blame] | 190 | } |
| 191 | |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 192 | void SupervisedUserService::URLFilterContext::SetManualHosts( |
[email protected] | 5e02229 | 2013-02-06 16:42:17 | [diff] [blame] | 193 | scoped_ptr<std::map<std::string, bool> > host_map) { |
| 194 | ui_url_filter_->SetManualHosts(host_map.get()); |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 195 | BrowserThread::PostTask( |
| 196 | BrowserThread::IO, |
| 197 | FROM_HERE, |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 198 | base::Bind(&SupervisedUserURLFilter::SetManualHosts, |
[email protected] | 5e02229 | 2013-02-06 16:42:17 | [diff] [blame] | 199 | io_url_filter_, base::Owned(host_map.release()))); |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 200 | } |
| 201 | |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 202 | void SupervisedUserService::URLFilterContext::SetManualURLs( |
[email protected] | 5e02229 | 2013-02-06 16:42:17 | [diff] [blame] | 203 | scoped_ptr<std::map<GURL, bool> > url_map) { |
| 204 | ui_url_filter_->SetManualURLs(url_map.get()); |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 205 | BrowserThread::PostTask( |
| 206 | BrowserThread::IO, |
| 207 | FROM_HERE, |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 208 | base::Bind(&SupervisedUserURLFilter::SetManualURLs, |
[email protected] | 5e02229 | 2013-02-06 16:42:17 | [diff] [blame] | 209 | io_url_filter_, base::Owned(url_map.release()))); |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 210 | } |
| 211 | |
treib | 22c3a04 | 2015-01-15 21:30:13 | [diff] [blame] | 212 | void SupervisedUserService::URLFilterContext::Clear() { |
| 213 | ui_url_filter_->Clear(); |
| 214 | BrowserThread::PostTask( |
| 215 | BrowserThread::IO, |
| 216 | FROM_HERE, |
| 217 | base::Bind(&SupervisedUserURLFilter::Clear, |
| 218 | io_url_filter_)); |
| 219 | } |
| 220 | |
bauerb | ce9a1a8 | 2014-12-18 13:34:24 | [diff] [blame] | 221 | void SupervisedUserService::URLFilterContext::OnBlacklistLoaded( |
| 222 | const base::Closure& callback) { |
treib | 4edbded | 2014-09-05 08:43:55 | [diff] [blame] | 223 | ui_url_filter_->SetBlacklist(&blacklist_); |
| 224 | BrowserThread::PostTask( |
| 225 | BrowserThread::IO, |
| 226 | FROM_HERE, |
| 227 | base::Bind(&SupervisedUserURLFilter::SetBlacklist, |
| 228 | io_url_filter_, |
| 229 | &blacklist_)); |
bauerb | ce9a1a8 | 2014-12-18 13:34:24 | [diff] [blame] | 230 | callback.Run(); |
treib | 4edbded | 2014-09-05 08:43:55 | [diff] [blame] | 231 | } |
| 232 | |
treib | 9e4fab90 | 2014-10-29 14:25:26 | [diff] [blame] | 233 | void SupervisedUserService::URLFilterContext::InitAsyncURLChecker( |
treib | d3f8b7a | 2015-04-10 11:41:33 | [diff] [blame] | 234 | const scoped_refptr<net::URLRequestContextGetter>& context) { |
| 235 | ui_url_filter_->InitAsyncURLChecker(context.get()); |
treib | 9e4fab90 | 2014-10-29 14:25:26 | [diff] [blame] | 236 | BrowserThread::PostTask( |
| 237 | BrowserThread::IO, |
| 238 | FROM_HERE, |
| 239 | base::Bind(&SupervisedUserURLFilter::InitAsyncURLChecker, |
treib | d3f8b7a | 2015-04-10 11:41:33 | [diff] [blame] | 240 | io_url_filter_, context)); |
treib | 9e4fab90 | 2014-10-29 14:25:26 | [diff] [blame] | 241 | } |
| 242 | |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 243 | SupervisedUserService::SupervisedUserService(Profile* profile) |
fhorschig | 1f351f0 | 2014-09-30 12:30:22 | [diff] [blame] | 244 | : includes_sync_sessions_type_(true), |
| 245 | profile_(profile), |
[email protected] | f085fdd5 | 2014-06-11 18:09:20 | [diff] [blame] | 246 | active_(false), |
| 247 | delegate_(NULL), |
[email protected] | a243d644c | 2013-06-20 18:37:55 | [diff] [blame] | 248 | waiting_for_sync_initialization_(false), |
[email protected] | dfddd02 | 2013-07-10 17:29:48 | [diff] [blame] | 249 | is_profile_active_(false), |
[email protected] | 3a276ff | 2014-08-12 14:22:09 | [diff] [blame] | 250 | did_init_(false), |
[email protected] | 8052b24 | 2013-11-15 16:40:55 | [diff] [blame] | 251 | did_shutdown_(false), |
| 252 | weak_ptr_factory_(this) { |
bauerb | ce9a1a8 | 2014-12-18 13:34:24 | [diff] [blame] | 253 | url_filter_context_.ui_url_filter()->AddObserver(this); |
[email protected] | a243d644c | 2013-06-20 18:37:55 | [diff] [blame] | 254 | } |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 255 | |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 256 | SupervisedUserService::~SupervisedUserService() { |
[email protected] | 3a276ff | 2014-08-12 14:22:09 | [diff] [blame] | 257 | DCHECK(!did_init_ || did_shutdown_); |
bauerb | ce9a1a8 | 2014-12-18 13:34:24 | [diff] [blame] | 258 | url_filter_context_.ui_url_filter()->RemoveObserver(this); |
[email protected] | 3bf45d0 | 2013-07-10 00:03:41 | [diff] [blame] | 259 | } |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 260 | |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 261 | void SupervisedUserService::Shutdown() { |
[email protected] | 3a276ff | 2014-08-12 14:22:09 | [diff] [blame] | 262 | if (!did_init_) |
| 263 | return; |
| 264 | DCHECK(!did_shutdown_); |
[email protected] | 3bf45d0 | 2013-07-10 00:03:41 | [diff] [blame] | 265 | did_shutdown_ = true; |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 266 | if (ProfileIsSupervised()) { |
[email protected] | 2056c3b | 2014-04-07 18:08:50 | [diff] [blame] | 267 | content::RecordAction(UserMetricsAction("ManagedUsers_QuitBrowser")); |
[email protected] | dfddd02 | 2013-07-10 17:29:48 | [diff] [blame] | 268 | } |
[email protected] | f085fdd5 | 2014-06-11 18:09:20 | [diff] [blame] | 269 | SetActive(false); |
[email protected] | 3a276ff | 2014-08-12 14:22:09 | [diff] [blame] | 270 | |
| 271 | ProfileSyncService* sync_service = |
| 272 | ProfileSyncServiceFactory::GetForProfile(profile_); |
| 273 | // Can be null in tests. |
| 274 | if (sync_service) |
| 275 | sync_service->RemovePreferenceProvider(this); |
[email protected] | a243d644c | 2013-06-20 18:37:55 | [diff] [blame] | 276 | } |
| 277 | |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 278 | bool SupervisedUserService::ProfileIsSupervised() const { |
[email protected] | d20d043 | 2014-06-12 17:14:05 | [diff] [blame] | 279 | return profile_->IsSupervised(); |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 280 | } |
| 281 | |
treib | 3fce4e9 | 2014-09-26 16:06:25 | [diff] [blame] | 282 | void SupervisedUserService::OnCustodianInfoChanged() { |
| 283 | FOR_EACH_OBSERVER( |
| 284 | SupervisedUserServiceObserver, observer_list_, OnCustodianInfoChanged()); |
| 285 | } |
| 286 | |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 287 | // static |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 288 | void SupervisedUserService::RegisterProfilePrefs( |
[email protected] | 443e931 | 2013-05-06 06:17:34 | [diff] [blame] | 289 | user_prefs::PrefRegistrySyncable* registry) { |
| 290 | registry->RegisterDictionaryPref( |
[email protected] | d20d043 | 2014-06-12 17:14:05 | [diff] [blame] | 291 | prefs::kSupervisedUserManualHosts, |
[email protected] | 443e931 | 2013-05-06 06:17:34 | [diff] [blame] | 292 | user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 293 | registry->RegisterDictionaryPref( |
[email protected] | d20d043 | 2014-06-12 17:14:05 | [diff] [blame] | 294 | prefs::kSupervisedUserManualURLs, |
[email protected] | 443e931 | 2013-05-06 06:17:34 | [diff] [blame] | 295 | user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 296 | registry->RegisterIntegerPref( |
[email protected] | d20d043 | 2014-06-12 17:14:05 | [diff] [blame] | 297 | prefs::kDefaultSupervisedUserFilteringBehavior, |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 298 | SupervisedUserURLFilter::ALLOW, |
[email protected] | 443e931 | 2013-05-06 06:17:34 | [diff] [blame] | 299 | user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
[email protected] | d20d043 | 2014-06-12 17:14:05 | [diff] [blame] | 300 | registry->RegisterBooleanPref(prefs::kSupervisedUserCreationAllowed, true, |
[email protected] | a7d65a8 | 2013-07-02 17:01:05 | [diff] [blame] | 301 | user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
treib | 22c3a04 | 2015-01-15 21:30:13 | [diff] [blame] | 302 | for (const char* pref : kCustodianInfoPrefs) { |
| 303 | registry->RegisterStringPref(pref, std::string(), |
| 304 | user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 305 | } |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 306 | } |
| 307 | |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 308 | void SupervisedUserService::SetDelegate(Delegate* delegate) { |
[email protected] | 49607ff | 2014-08-12 16:27:01 | [diff] [blame] | 309 | if (delegate) { |
| 310 | // Changing delegates isn't allowed. |
| 311 | DCHECK(!delegate_); |
| 312 | } else { |
| 313 | // If the delegate is removed, deactivate first to give the old delegate a |
| 314 | // chance to clean up. |
| 315 | SetActive(false); |
| 316 | } |
[email protected] | f085fdd5 | 2014-06-11 18:09:20 | [diff] [blame] | 317 | delegate_ = delegate; |
| 318 | } |
| 319 | |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 320 | scoped_refptr<const SupervisedUserURLFilter> |
| 321 | SupervisedUserService::GetURLFilterForIOThread() { |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 322 | return url_filter_context_.io_url_filter(); |
| 323 | } |
| 324 | |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 325 | SupervisedUserURLFilter* SupervisedUserService::GetURLFilterForUIThread() { |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 326 | return url_filter_context_.ui_url_filter(); |
| 327 | } |
| 328 | |
bauerb | 4da3613 | 2014-12-26 19:53:13 | [diff] [blame] | 329 | SupervisedUserWhitelistService* SupervisedUserService::GetWhitelistService() { |
| 330 | return whitelist_service_.get(); |
| 331 | } |
| 332 | |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 333 | std::string SupervisedUserService::GetCustodianEmailAddress() const { |
merkulova | 270ffc01 | 2014-10-13 13:58:04 | [diff] [blame] | 334 | std::string custodian_email = profile_->GetPrefs()->GetString( |
| 335 | prefs::kSupervisedUserCustodianEmail); |
[email protected] | 3aacc9c | 2013-08-08 11:19:31 | [diff] [blame] | 336 | #if defined(OS_CHROMEOS) |
merkulova | 270ffc01 | 2014-10-13 13:58:04 | [diff] [blame] | 337 | if (custodian_email.empty()) { |
| 338 | custodian_email = chromeos::ChromeUserManager::Get() |
| 339 | ->GetSupervisedUserManager() |
| 340 | ->GetManagerDisplayEmail( |
| 341 | user_manager::UserManager::Get()->GetActiveUser()->email()); |
| 342 | } |
[email protected] | 3aacc9c | 2013-08-08 11:19:31 | [diff] [blame] | 343 | #endif |
merkulova | 270ffc01 | 2014-10-13 13:58:04 | [diff] [blame] | 344 | return custodian_email; |
[email protected] | fae057a | 2013-06-21 22:46:08 | [diff] [blame] | 345 | } |
| 346 | |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 347 | std::string SupervisedUserService::GetCustodianName() const { |
[email protected] | fae057a | 2013-06-21 22:46:08 | [diff] [blame] | 348 | std::string name = profile_->GetPrefs()->GetString( |
[email protected] | d20d043 | 2014-06-12 17:14:05 | [diff] [blame] | 349 | prefs::kSupervisedUserCustodianName); |
merkulova | 270ffc01 | 2014-10-13 13:58:04 | [diff] [blame] | 350 | #if defined(OS_CHROMEOS) |
| 351 | if (name.empty()) { |
| 352 | name = base::UTF16ToUTF8(chromeos::ChromeUserManager::Get() |
| 353 | ->GetSupervisedUserManager() |
| 354 | ->GetManagerDisplayName( |
| 355 | user_manager::UserManager::Get()->GetActiveUser()->email())); |
| 356 | } |
[email protected] | 3aacc9c | 2013-08-08 11:19:31 | [diff] [blame] | 357 | #endif |
merkulova | 270ffc01 | 2014-10-13 13:58:04 | [diff] [blame] | 358 | return name.empty() ? GetCustodianEmailAddress() : name; |
[email protected] | a9c2d64 | 2013-05-31 14:37:14 | [diff] [blame] | 359 | } |
| 360 | |
treib | 3e7ecf7 | 2014-10-24 16:44:07 | [diff] [blame] | 361 | std::string SupervisedUserService::GetSecondCustodianEmailAddress() const { |
| 362 | return profile_->GetPrefs()->GetString( |
| 363 | prefs::kSupervisedUserSecondCustodianEmail); |
| 364 | } |
| 365 | |
| 366 | std::string SupervisedUserService::GetSecondCustodianName() const { |
| 367 | std::string name = profile_->GetPrefs()->GetString( |
| 368 | prefs::kSupervisedUserSecondCustodianName); |
| 369 | return name.empty() ? GetSecondCustodianEmailAddress() : name; |
| 370 | } |
| 371 | |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 372 | void SupervisedUserService::AddNavigationBlockedCallback( |
[email protected] | 438f7e1 | 2013-08-07 06:59:00 | [diff] [blame] | 373 | const NavigationBlockedCallback& callback) { |
| 374 | navigation_blocked_callbacks_.push_back(callback); |
| 375 | } |
| 376 | |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 377 | void SupervisedUserService::DidBlockNavigation( |
[email protected] | 438f7e1 | 2013-08-07 06:59:00 | [diff] [blame] | 378 | content::WebContents* web_contents) { |
treib | 5844aca | 2014-09-30 14:08:38 | [diff] [blame] | 379 | for (const auto& callback : navigation_blocked_callbacks_) |
| 380 | callback.Run(web_contents); |
[email protected] | 438f7e1 | 2013-08-07 06:59:00 | [diff] [blame] | 381 | } |
| 382 | |
treib | ab0a39e | 2014-09-24 14:48:28 | [diff] [blame] | 383 | void SupervisedUserService::AddObserver( |
| 384 | SupervisedUserServiceObserver* observer) { |
| 385 | observer_list_.AddObserver(observer); |
| 386 | } |
| 387 | |
| 388 | void SupervisedUserService::RemoveObserver( |
| 389 | SupervisedUserServiceObserver* observer) { |
| 390 | observer_list_.RemoveObserver(observer); |
| 391 | } |
| 392 | |
treib | 531fc731 | 2014-12-09 12:49:20 | [diff] [blame] | 393 | void SupervisedUserService::AddPermissionRequestCreator( |
| 394 | scoped_ptr<PermissionRequestCreator> creator) { |
| 395 | permissions_creators_.push_back(creator.release()); |
bauerb | 646019b1 | 2014-10-16 16:23:09 | [diff] [blame] | 396 | } |
| 397 | |
[email protected] | 3a276ff | 2014-08-12 14:22:09 | [diff] [blame] | 398 | syncer::ModelTypeSet SupervisedUserService::GetPreferredDataTypes() const { |
| 399 | if (!ProfileIsSupervised()) |
| 400 | return syncer::ModelTypeSet(); |
| 401 | |
| 402 | syncer::ModelTypeSet result; |
fhorschig | 1f351f0 | 2014-09-30 12:30:22 | [diff] [blame] | 403 | if (IncludesSyncSessionsType()) |
| 404 | result.Put(syncer::SESSIONS); |
[email protected] | 3a276ff | 2014-08-12 14:22:09 | [diff] [blame] | 405 | result.Put(syncer::EXTENSIONS); |
| 406 | result.Put(syncer::EXTENSION_SETTINGS); |
| 407 | result.Put(syncer::APPS); |
| 408 | result.Put(syncer::APP_SETTINGS); |
| 409 | result.Put(syncer::APP_NOTIFICATIONS); |
| 410 | result.Put(syncer::APP_LIST); |
| 411 | return result; |
| 412 | } |
| 413 | |
fhorschig | 1f351f0 | 2014-09-30 12:30:22 | [diff] [blame] | 414 | void SupervisedUserService::OnHistoryRecordingStateChanged() { |
treib | 6f959801 | 2014-11-11 12:21:24 | [diff] [blame] | 415 | bool record_history = |
fhorschig | 1f351f0 | 2014-09-30 12:30:22 | [diff] [blame] | 416 | profile_->GetPrefs()->GetBoolean(prefs::kRecordHistory); |
treib | 6f959801 | 2014-11-11 12:21:24 | [diff] [blame] | 417 | includes_sync_sessions_type_ = record_history; |
fhorschig | 1f351f0 | 2014-09-30 12:30:22 | [diff] [blame] | 418 | ProfileSyncServiceFactory::GetForProfile(profile_) |
| 419 | ->ReconfigureDatatypeManager(); |
| 420 | } |
| 421 | |
| 422 | bool SupervisedUserService::IncludesSyncSessionsType() const { |
| 423 | return includes_sync_sessions_type_; |
| 424 | } |
| 425 | |
[email protected] | c14a680 | 2014-07-11 21:51:12 | [diff] [blame] | 426 | void SupervisedUserService::OnStateChanged() { |
| 427 | ProfileSyncService* service = |
| 428 | ProfileSyncServiceFactory::GetForProfile(profile_); |
zea | 09acc93 | 2014-10-14 21:06:20 | [diff] [blame] | 429 | if (waiting_for_sync_initialization_ && service->backend_initialized() && |
| 430 | service->backend_mode() == ProfileSyncService::SYNC) { |
[email protected] | c14a680 | 2014-07-11 21:51:12 | [diff] [blame] | 431 | waiting_for_sync_initialization_ = false; |
| 432 | service->RemoveObserver(this); |
| 433 | FinishSetupSync(); |
| 434 | return; |
| 435 | } |
| 436 | |
| 437 | DLOG_IF(ERROR, service->GetAuthError().state() == |
| 438 | GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS) |
| 439 | << "Credentials rejected"; |
| 440 | } |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 441 | |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 442 | void SupervisedUserService::SetupSync() { |
[email protected] | 6e08b9a6 | 2014-07-08 00:32:48 | [diff] [blame] | 443 | StartSetupSync(); |
| 444 | FinishSetupSyncWhenReady(); |
| 445 | } |
| 446 | |
| 447 | void SupervisedUserService::StartSetupSync() { |
| 448 | // Tell the sync service that setup is in progress so we don't start syncing |
| 449 | // until we've finished configuration. |
| 450 | ProfileSyncServiceFactory::GetForProfile(profile_)->SetSetupInProgress(true); |
| 451 | } |
| 452 | |
| 453 | void SupervisedUserService::FinishSetupSyncWhenReady() { |
| 454 | // If we're already waiting for the Sync backend, there's nothing to do here. |
| 455 | if (waiting_for_sync_initialization_) |
| 456 | return; |
| 457 | |
| 458 | // Continue in FinishSetupSync() once the Sync backend has been initialized. |
| 459 | ProfileSyncService* service = |
| 460 | ProfileSyncServiceFactory::GetForProfile(profile_); |
zea | 09acc93 | 2014-10-14 21:06:20 | [diff] [blame] | 461 | if (service->backend_initialized() && |
| 462 | service->backend_mode() == ProfileSyncService::SYNC) { |
[email protected] | 6e08b9a6 | 2014-07-08 00:32:48 | [diff] [blame] | 463 | FinishSetupSync(); |
| 464 | } else { |
| 465 | service->AddObserver(this); |
| 466 | waiting_for_sync_initialization_ = true; |
| 467 | } |
| 468 | } |
| 469 | |
| 470 | void SupervisedUserService::FinishSetupSync() { |
[email protected] | a243d644c | 2013-06-20 18:37:55 | [diff] [blame] | 471 | ProfileSyncService* service = |
| 472 | ProfileSyncServiceFactory::GetForProfile(profile_); |
zea | 09acc93 | 2014-10-14 21:06:20 | [diff] [blame] | 473 | DCHECK(service->backend_initialized()); |
| 474 | DCHECK(service->backend_mode() == ProfileSyncService::SYNC); |
[email protected] | a243d644c | 2013-06-20 18:37:55 | [diff] [blame] | 475 | |
[email protected] | 3a276ff | 2014-08-12 14:22:09 | [diff] [blame] | 476 | // Sync nothing (except types which are set via GetPreferredDataTypes). |
[email protected] | a243d644c | 2013-06-20 18:37:55 | [diff] [blame] | 477 | bool sync_everything = false; |
| 478 | syncer::ModelTypeSet synced_datatypes; |
[email protected] | a243d644c | 2013-06-20 18:37:55 | [diff] [blame] | 479 | service->OnUserChoseDatatypes(sync_everything, synced_datatypes); |
| 480 | |
| 481 | // Notify ProfileSyncService that we are done with configuration. |
| 482 | service->SetSetupInProgress(false); |
| 483 | service->SetSyncSetupCompleted(); |
| 484 | } |
| 485 | |
[email protected] | c14a680 | 2014-07-11 21:51:12 | [diff] [blame] | 486 | #if defined(ENABLE_EXTENSIONS) |
treib | bb9a196 | 2015-02-25 13:40:59 | [diff] [blame] | 487 | std::string SupervisedUserService::GetDebugPolicyProviderName() const { |
| 488 | // Save the string space in official builds. |
| 489 | #ifdef NDEBUG |
| 490 | NOTREACHED(); |
| 491 | return std::string(); |
| 492 | #else |
| 493 | return "Supervised User Service"; |
| 494 | #endif |
| 495 | } |
| 496 | |
| 497 | bool SupervisedUserService::UserMayLoad(const extensions::Extension* extension, |
| 498 | base::string16* error) const { |
| 499 | DCHECK(ProfileIsSupervised()); |
| 500 | ExtensionState result = GetExtensionState(extension); |
| 501 | bool may_load = (result != EXTENSION_BLOCKED); |
| 502 | if (!may_load && error) |
| 503 | *error = l10n_util::GetStringUTF16(IDS_EXTENSIONS_LOCKED_SUPERVISED_USER); |
| 504 | return may_load; |
| 505 | } |
| 506 | |
treib | 755c12d | 2015-03-30 08:46:25 | [diff] [blame] | 507 | bool SupervisedUserService::UserMayModifySettings( |
| 508 | const extensions::Extension* extension, |
| 509 | base::string16* error) const { |
| 510 | DCHECK(ProfileIsSupervised()); |
| 511 | ExtensionState result = GetExtensionState(extension); |
| 512 | bool may_modify = (result == EXTENSION_ALLOWED); |
| 513 | if (!may_modify && error) |
| 514 | *error = l10n_util::GetStringUTF16(IDS_EXTENSIONS_LOCKED_SUPERVISED_USER); |
| 515 | return may_modify; |
| 516 | } |
| 517 | |
treib | bb9a196 | 2015-02-25 13:40:59 | [diff] [blame] | 518 | // Note: Having MustRemainInstalled always say "true" for custodian-installed |
| 519 | // extensions does NOT prevent remote uninstalls (which is a bit unexpected, but |
| 520 | // exactly what we want). |
| 521 | bool SupervisedUserService::MustRemainInstalled( |
[email protected] | 38b7fb9 | 2013-07-26 16:32:26 | [diff] [blame] | 522 | const extensions::Extension* extension, |
[email protected] | 0085863a | 2013-12-06 21:19:03 | [diff] [blame] | 523 | base::string16* error) const { |
treib | bb9a196 | 2015-02-25 13:40:59 | [diff] [blame] | 524 | DCHECK(ProfileIsSupervised()); |
| 525 | ExtensionState result = GetExtensionState(extension); |
| 526 | bool may_not_uninstall = (result == EXTENSION_FORCED); |
| 527 | if (may_not_uninstall && error) |
[email protected] | a7340d61 | 2014-06-25 22:09:15 | [diff] [blame] | 528 | *error = l10n_util::GetStringUTF16(IDS_EXTENSIONS_LOCKED_SUPERVISED_USER); |
treib | bb9a196 | 2015-02-25 13:40:59 | [diff] [blame] | 529 | return may_not_uninstall; |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 530 | } |
| 531 | |
[email protected] | c14a680 | 2014-07-11 21:51:12 | [diff] [blame] | 532 | void SupervisedUserService::SetExtensionsActive() { |
| 533 | extensions::ExtensionSystem* extension_system = |
| 534 | extensions::ExtensionSystem::Get(profile_); |
| 535 | extensions::ManagementPolicy* management_policy = |
| 536 | extension_system->management_policy(); |
| 537 | |
bauerb | 16ccc5e1 | 2015-01-05 10:58:31 | [diff] [blame] | 538 | if (management_policy) { |
| 539 | if (active_) |
[email protected] | c14a680 | 2014-07-11 21:51:12 | [diff] [blame] | 540 | management_policy->RegisterProvider(this); |
bauerb | 16ccc5e1 | 2015-01-05 10:58:31 | [diff] [blame] | 541 | else |
[email protected] | c14a680 | 2014-07-11 21:51:12 | [diff] [blame] | 542 | management_policy->UnregisterProvider(this); |
treib | 9e30e30 | 2015-04-15 08:12:16 | [diff] [blame^] | 543 | |
| 544 | // Re-check the policy to make sure any new settings get applied. |
| 545 | extension_system->extension_service()->CheckManagementPolicy(); |
[email protected] | c14a680 | 2014-07-11 21:51:12 | [diff] [blame] | 546 | } |
| 547 | } |
| 548 | #endif // defined(ENABLE_EXTENSIONS) |
| 549 | |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 550 | SupervisedUserSettingsService* SupervisedUserService::GetSettingsService() { |
| 551 | return SupervisedUserSettingsServiceFactory::GetForProfile(profile_); |
[email protected] | e861bba | 2013-06-17 15:20:54 | [diff] [blame] | 552 | } |
| 553 | |
bauerb | d3a36cc4 | 2014-10-01 13:05:49 | [diff] [blame] | 554 | size_t SupervisedUserService::FindEnabledPermissionRequestCreator( |
| 555 | size_t start) { |
| 556 | for (size_t i = start; i < permissions_creators_.size(); ++i) { |
| 557 | if (permissions_creators_[i]->IsEnabled()) |
| 558 | return i; |
| 559 | } |
| 560 | return permissions_creators_.size(); |
| 561 | } |
| 562 | |
treib | 8ecc1eb5 | 2015-03-04 18:29:06 | [diff] [blame] | 563 | void SupervisedUserService::AddPermissionRequestInternal( |
| 564 | const CreatePermissionRequestCallback& create_request, |
bauerb | 646019b1 | 2014-10-16 16:23:09 | [diff] [blame] | 565 | const SuccessCallback& callback, |
| 566 | size_t index) { |
bauerb | d3a36cc4 | 2014-10-01 13:05:49 | [diff] [blame] | 567 | // Find a permission request creator that is enabled. |
| 568 | size_t next_index = FindEnabledPermissionRequestCreator(index); |
bauerb | 646019b1 | 2014-10-16 16:23:09 | [diff] [blame] | 569 | if (next_index >= permissions_creators_.size()) { |
| 570 | callback.Run(false); |
bauerb | d3a36cc4 | 2014-10-01 13:05:49 | [diff] [blame] | 571 | return; |
bauerb | 646019b1 | 2014-10-16 16:23:09 | [diff] [blame] | 572 | } |
bauerb | d3a36cc4 | 2014-10-01 13:05:49 | [diff] [blame] | 573 | |
treib | 8ecc1eb5 | 2015-03-04 18:29:06 | [diff] [blame] | 574 | create_request.Run( |
| 575 | permissions_creators_[next_index], |
bauerb | d3a36cc4 | 2014-10-01 13:05:49 | [diff] [blame] | 576 | base::Bind(&SupervisedUserService::OnPermissionRequestIssued, |
treib | 8ecc1eb5 | 2015-03-04 18:29:06 | [diff] [blame] | 577 | weak_ptr_factory_.GetWeakPtr(), create_request, |
| 578 | callback, next_index)); |
bauerb | d3a36cc4 | 2014-10-01 13:05:49 | [diff] [blame] | 579 | } |
| 580 | |
bauerb | 646019b1 | 2014-10-16 16:23:09 | [diff] [blame] | 581 | void SupervisedUserService::OnPermissionRequestIssued( |
treib | 8ecc1eb5 | 2015-03-04 18:29:06 | [diff] [blame] | 582 | const CreatePermissionRequestCallback& create_request, |
bauerb | 646019b1 | 2014-10-16 16:23:09 | [diff] [blame] | 583 | const SuccessCallback& callback, |
| 584 | size_t index, |
| 585 | bool success) { |
| 586 | if (success) { |
| 587 | callback.Run(true); |
bauerb | d3a36cc4 | 2014-10-01 13:05:49 | [diff] [blame] | 588 | return; |
bauerb | 646019b1 | 2014-10-16 16:23:09 | [diff] [blame] | 589 | } |
bauerb | d3a36cc4 | 2014-10-01 13:05:49 | [diff] [blame] | 590 | |
treib | 8ecc1eb5 | 2015-03-04 18:29:06 | [diff] [blame] | 591 | AddPermissionRequestInternal(create_request, callback, index + 1); |
bauerb | d3a36cc4 | 2014-10-01 13:05:49 | [diff] [blame] | 592 | } |
| 593 | |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 594 | void SupervisedUserService::OnSupervisedUserIdChanged() { |
treib | f813dfc | 2014-12-08 11:26:33 | [diff] [blame] | 595 | SetActive(ProfileIsSupervised()); |
[email protected] | f085fdd5 | 2014-06-11 18:09:20 | [diff] [blame] | 596 | } |
| 597 | |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 598 | void SupervisedUserService::OnDefaultFilteringBehaviorChanged() { |
| 599 | DCHECK(ProfileIsSupervised()); |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 600 | |
| 601 | int behavior_value = profile_->GetPrefs()->GetInteger( |
[email protected] | d20d043 | 2014-06-12 17:14:05 | [diff] [blame] | 602 | prefs::kDefaultSupervisedUserFilteringBehavior); |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 603 | SupervisedUserURLFilter::FilteringBehavior behavior = |
| 604 | SupervisedUserURLFilter::BehaviorFromInt(behavior_value); |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 605 | url_filter_context_.SetDefaultFilteringBehavior(behavior); |
treib | ab0a39e | 2014-09-24 14:48:28 | [diff] [blame] | 606 | |
| 607 | FOR_EACH_OBSERVER( |
| 608 | SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged()); |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 609 | } |
| 610 | |
bauerb | 16ccc5e1 | 2015-01-05 10:58:31 | [diff] [blame] | 611 | void SupervisedUserService::OnSiteListsChanged( |
bauerb | 95a5068 | 2015-01-07 17:04:15 | [diff] [blame] | 612 | const std::vector<scoped_refptr<SupervisedUserSiteList> >& site_lists) { |
| 613 | url_filter_context_.LoadWhitelists(site_lists); |
bauerb | ce9a1a8 | 2014-12-18 13:34:24 | [diff] [blame] | 614 | } |
treib | ab0a39e | 2014-09-24 14:48:28 | [diff] [blame] | 615 | |
bauerb | ce9a1a8 | 2014-12-18 13:34:24 | [diff] [blame] | 616 | void SupervisedUserService::OnSiteListUpdated() { |
treib | ab0a39e | 2014-09-24 14:48:28 | [diff] [blame] | 617 | FOR_EACH_OBSERVER( |
| 618 | SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged()); |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 619 | } |
| 620 | |
treib | f136dfb | 2014-09-25 17:37:47 | [diff] [blame] | 621 | void SupervisedUserService::LoadBlacklist(const base::FilePath& path, |
| 622 | const GURL& url) { |
treib | d3f8b7a | 2015-04-10 11:41:33 | [diff] [blame] | 623 | // TODO(treib): Don't re-download the blacklist if the local file exists! |
treib | f136dfb | 2014-09-25 17:37:47 | [diff] [blame] | 624 | if (!url.is_valid()) { |
| 625 | LoadBlacklistFromFile(path); |
| 626 | return; |
| 627 | } |
| 628 | |
bauerb | ce9a1a8 | 2014-12-18 13:34:24 | [diff] [blame] | 629 | DCHECK(!blacklist_downloader_); |
treib | f136dfb | 2014-09-25 17:37:47 | [diff] [blame] | 630 | blacklist_downloader_.reset(new SupervisedUserBlacklistDownloader( |
| 631 | url, |
| 632 | path, |
| 633 | profile_->GetRequestContext(), |
| 634 | base::Bind(&SupervisedUserService::OnBlacklistDownloadDone, |
| 635 | base::Unretained(this), path))); |
| 636 | } |
| 637 | |
| 638 | void SupervisedUserService::LoadBlacklistFromFile(const base::FilePath& path) { |
bauerb | ce9a1a8 | 2014-12-18 13:34:24 | [diff] [blame] | 639 | // This object is guaranteed to outlive the URLFilterContext, so we can bind a |
| 640 | // raw pointer to it in the callback. |
| 641 | url_filter_context_.LoadBlacklist( |
| 642 | path, base::Bind(&SupervisedUserService::OnBlacklistLoaded, |
| 643 | base::Unretained(this))); |
treib | 4edbded | 2014-09-05 08:43:55 | [diff] [blame] | 644 | } |
| 645 | |
treib | f136dfb | 2014-09-25 17:37:47 | [diff] [blame] | 646 | void SupervisedUserService::OnBlacklistDownloadDone(const base::FilePath& path, |
| 647 | bool success) { |
| 648 | if (success) { |
| 649 | LoadBlacklistFromFile(path); |
| 650 | } else { |
| 651 | LOG(WARNING) << "Blacklist download failed"; |
| 652 | } |
| 653 | blacklist_downloader_.reset(); |
| 654 | } |
| 655 | |
bauerb | ce9a1a8 | 2014-12-18 13:34:24 | [diff] [blame] | 656 | void SupervisedUserService::OnBlacklistLoaded() { |
| 657 | FOR_EACH_OBSERVER( |
| 658 | SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged()); |
| 659 | } |
| 660 | |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 661 | bool SupervisedUserService::AccessRequestsEnabled() { |
bauerb | d3a36cc4 | 2014-10-01 13:05:49 | [diff] [blame] | 662 | return FindEnabledPermissionRequestCreator(0) < permissions_creators_.size(); |
[email protected] | 4db65f95 | 2014-05-20 15:46:30 | [diff] [blame] | 663 | } |
| 664 | |
treib | 8ecc1eb5 | 2015-03-04 18:29:06 | [diff] [blame] | 665 | void SupervisedUserService::AddURLAccessRequest( |
| 666 | const GURL& url, |
| 667 | const SuccessCallback& callback) { |
| 668 | AddPermissionRequestInternal( |
| 669 | base::Bind(CreateURLAccessRequest, |
| 670 | SupervisedUserURLFilter::Normalize(url)), |
| 671 | callback, 0); |
| 672 | } |
| 673 | |
| 674 | void SupervisedUserService::AddExtensionUpdateRequest( |
| 675 | const std::string& extension_id, |
treib | f832a99 | 2015-03-24 18:09:24 | [diff] [blame] | 676 | const base::Version& version, |
treib | 8ecc1eb5 | 2015-03-04 18:29:06 | [diff] [blame] | 677 | const SuccessCallback& callback) { |
treib | f832a99 | 2015-03-24 18:09:24 | [diff] [blame] | 678 | std::string id = extension_id + ":" + version.GetString(); |
treib | 8ecc1eb5 | 2015-03-04 18:29:06 | [diff] [blame] | 679 | AddPermissionRequestInternal( |
treib | f832a99 | 2015-03-24 18:09:24 | [diff] [blame] | 680 | base::Bind(CreateExtensionUpdateRequest, id), |
treib | 8ecc1eb5 | 2015-03-04 18:29:06 | [diff] [blame] | 681 | callback, 0); |
[email protected] | e861bba | 2013-06-17 15:20:54 | [diff] [blame] | 682 | } |
| 683 | |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 684 | void SupervisedUserService::InitSync(const std::string& refresh_token) { |
[email protected] | 6e08b9a6 | 2014-07-08 00:32:48 | [diff] [blame] | 685 | StartSetupSync(); |
[email protected] | a19df3e | 2013-05-21 00:03:03 | [diff] [blame] | 686 | |
[email protected] | aab94691 | 2013-11-06 22:18:51 | [diff] [blame] | 687 | ProfileOAuth2TokenService* token_service = |
| 688 | ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 689 | token_service->UpdateCredentials(supervised_users::kSupervisedUserPseudoEmail, |
[email protected] | aab94691 | 2013-11-06 22:18:51 | [diff] [blame] | 690 | refresh_token); |
[email protected] | a19df3e | 2013-05-21 00:03:03 | [diff] [blame] | 691 | |
[email protected] | 6e08b9a6 | 2014-07-08 00:32:48 | [diff] [blame] | 692 | FinishSetupSyncWhenReady(); |
[email protected] | a19df3e | 2013-05-21 00:03:03 | [diff] [blame] | 693 | } |
| 694 | |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 695 | void SupervisedUserService::Init() { |
[email protected] | 3a276ff | 2014-08-12 14:22:09 | [diff] [blame] | 696 | DCHECK(!did_init_); |
| 697 | did_init_ = true; |
[email protected] | f085fdd5 | 2014-06-11 18:09:20 | [diff] [blame] | 698 | DCHECK(GetSettingsService()->IsReady()); |
| 699 | |
| 700 | pref_change_registrar_.Init(profile_->GetPrefs()); |
| 701 | pref_change_registrar_.Add( |
[email protected] | d20d043 | 2014-06-12 17:14:05 | [diff] [blame] | 702 | prefs::kSupervisedUserId, |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 703 | base::Bind(&SupervisedUserService::OnSupervisedUserIdChanged, |
[email protected] | f085fdd5 | 2014-06-11 18:09:20 | [diff] [blame] | 704 | base::Unretained(this))); |
fhorschig | 1f351f0 | 2014-09-30 12:30:22 | [diff] [blame] | 705 | pref_change_registrar_.Add( |
| 706 | prefs::kRecordHistory, |
| 707 | base::Bind(&SupervisedUserService::OnHistoryRecordingStateChanged, |
| 708 | base::Unretained(this))); |
[email protected] | f085fdd5 | 2014-06-11 18:09:20 | [diff] [blame] | 709 | |
[email protected] | 3a276ff | 2014-08-12 14:22:09 | [diff] [blame] | 710 | ProfileSyncService* sync_service = |
| 711 | ProfileSyncServiceFactory::GetForProfile(profile_); |
| 712 | // Can be null in tests. |
| 713 | if (sync_service) |
| 714 | sync_service->AddPreferenceProvider(this); |
| 715 | |
bauerb | 22951c3 | 2015-02-12 13:18:17 | [diff] [blame] | 716 | std::string client_id = component_updater::SupervisedUserWhitelistInstaller:: |
| 717 | ClientIdForProfilePath(profile_->GetPath()); |
bauerb | 4da3613 | 2014-12-26 19:53:13 | [diff] [blame] | 718 | whitelist_service_.reset(new SupervisedUserWhitelistService( |
| 719 | profile_->GetPrefs(), |
bauerb | 22951c3 | 2015-02-12 13:18:17 | [diff] [blame] | 720 | g_browser_process->supervised_user_whitelist_installer(), client_id)); |
bauerb | 16ccc5e1 | 2015-01-05 10:58:31 | [diff] [blame] | 721 | whitelist_service_->AddSiteListsChangedCallback( |
| 722 | base::Bind(&SupervisedUserService::OnSiteListsChanged, |
| 723 | weak_ptr_factory_.GetWeakPtr())); |
bauerb | 4da3613 | 2014-12-26 19:53:13 | [diff] [blame] | 724 | |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 725 | SetActive(ProfileIsSupervised()); |
[email protected] | f085fdd5 | 2014-06-11 18:09:20 | [diff] [blame] | 726 | } |
| 727 | |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 728 | void SupervisedUserService::SetActive(bool active) { |
[email protected] | f085fdd5 | 2014-06-11 18:09:20 | [diff] [blame] | 729 | if (active_ == active) |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 730 | return; |
[email protected] | f085fdd5 | 2014-06-11 18:09:20 | [diff] [blame] | 731 | active_ = active; |
| 732 | |
| 733 | if (!delegate_ || !delegate_->SetActive(active_)) { |
| 734 | if (active_) { |
| 735 | SupervisedUserPrefMappingServiceFactory::GetForBrowserContext(profile_) |
| 736 | ->Init(); |
| 737 | |
avi | 556c0502 | 2014-12-22 23:31:43 | [diff] [blame] | 738 | base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
[email protected] | d20d043 | 2014-06-12 17:14:05 | [diff] [blame] | 739 | if (command_line->HasSwitch(switches::kSupervisedUserSyncToken)) { |
[email protected] | f085fdd5 | 2014-06-11 18:09:20 | [diff] [blame] | 740 | InitSync( |
[email protected] | d20d043 | 2014-06-12 17:14:05 | [diff] [blame] | 741 | command_line->GetSwitchValueASCII( |
| 742 | switches::kSupervisedUserSyncToken)); |
[email protected] | f085fdd5 | 2014-06-11 18:09:20 | [diff] [blame] | 743 | } |
| 744 | |
| 745 | ProfileOAuth2TokenService* token_service = |
| 746 | ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 747 | token_service->LoadCredentials( |
| 748 | supervised_users::kSupervisedUserPseudoEmail); |
[email protected] | 6e08b9a6 | 2014-07-08 00:32:48 | [diff] [blame] | 749 | |
treib | 531fc731 | 2014-12-09 12:49:20 | [diff] [blame] | 750 | permissions_creators_.push_back(new PermissionRequestCreatorSync( |
| 751 | GetSettingsService(), |
| 752 | SupervisedUserSharedSettingsServiceFactory::GetForBrowserContext( |
| 753 | profile_), |
| 754 | ProfileSyncServiceFactory::GetForProfile(profile_), |
| 755 | GetSupervisedUserName(), |
| 756 | profile_->GetPrefs()->GetString(prefs::kSupervisedUserId))); |
| 757 | |
[email protected] | 6e08b9a6 | 2014-07-08 00:32:48 | [diff] [blame] | 758 | SetupSync(); |
[email protected] | f085fdd5 | 2014-06-11 18:09:20 | [diff] [blame] | 759 | } |
[email protected] | e861bba | 2013-06-17 15:20:54 | [diff] [blame] | 760 | } |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 761 | |
[email protected] | f085fdd5 | 2014-06-11 18:09:20 | [diff] [blame] | 762 | // Now activate/deactivate anything not handled by the delegate yet. |
[email protected] | e148048 | 2013-09-11 11:49:58 | [diff] [blame] | 763 | |
[email protected] | f085fdd5 | 2014-06-11 18:09:20 | [diff] [blame] | 764 | #if defined(ENABLE_THEMES) |
| 765 | // Re-set the default theme to turn the SU theme on/off. |
| 766 | ThemeService* theme_service = ThemeServiceFactory::GetForProfile(profile_); |
treib | 9e30e30 | 2015-04-15 08:12:16 | [diff] [blame^] | 767 | if (theme_service->UsingDefaultTheme() || theme_service->UsingSystemTheme()) |
| 768 | theme_service->UseDefaultTheme(); |
[email protected] | f085fdd5 | 2014-06-11 18:09:20 | [diff] [blame] | 769 | #endif |
[email protected] | a19df3e | 2013-05-21 00:03:03 | [diff] [blame] | 770 | |
bauerb | f03588b9 | 2014-10-27 13:40:15 | [diff] [blame] | 771 | ProfileSyncService* sync_service = |
| 772 | ProfileSyncServiceFactory::GetForProfile(profile_); |
| 773 | sync_service->SetEncryptEverythingAllowed(!active_); |
| 774 | |
bauerb | d3a36cc4 | 2014-10-01 13:05:49 | [diff] [blame] | 775 | GetSettingsService()->SetActive(active_); |
[email protected] | a243d644c | 2013-06-20 18:37:55 | [diff] [blame] | 776 | |
[email protected] | c14a680 | 2014-07-11 21:51:12 | [diff] [blame] | 777 | #if defined(ENABLE_EXTENSIONS) |
| 778 | SetExtensionsActive(); |
| 779 | #endif |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 780 | |
[email protected] | f085fdd5 | 2014-06-11 18:09:20 | [diff] [blame] | 781 | if (active_) { |
[email protected] | f085fdd5 | 2014-06-11 18:09:20 | [diff] [blame] | 782 | pref_change_registrar_.Add( |
[email protected] | d20d043 | 2014-06-12 17:14:05 | [diff] [blame] | 783 | prefs::kDefaultSupervisedUserFilteringBehavior, |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 784 | base::Bind(&SupervisedUserService::OnDefaultFilteringBehaviorChanged, |
[email protected] | f085fdd5 | 2014-06-11 18:09:20 | [diff] [blame] | 785 | base::Unretained(this))); |
[email protected] | d20d043 | 2014-06-12 17:14:05 | [diff] [blame] | 786 | pref_change_registrar_.Add(prefs::kSupervisedUserManualHosts, |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 787 | base::Bind(&SupervisedUserService::UpdateManualHosts, |
[email protected] | f085fdd5 | 2014-06-11 18:09:20 | [diff] [blame] | 788 | base::Unretained(this))); |
[email protected] | d20d043 | 2014-06-12 17:14:05 | [diff] [blame] | 789 | pref_change_registrar_.Add(prefs::kSupervisedUserManualURLs, |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 790 | base::Bind(&SupervisedUserService::UpdateManualURLs, |
[email protected] | f085fdd5 | 2014-06-11 18:09:20 | [diff] [blame] | 791 | base::Unretained(this))); |
treib | 22c3a04 | 2015-01-15 21:30:13 | [diff] [blame] | 792 | for (const char* pref : kCustodianInfoPrefs) { |
| 793 | pref_change_registrar_.Add(pref, |
| 794 | base::Bind(&SupervisedUserService::OnCustodianInfoChanged, |
| 795 | base::Unretained(this))); |
| 796 | } |
[email protected] | f085fdd5 | 2014-06-11 18:09:20 | [diff] [blame] | 797 | |
| 798 | // Initialize the filter. |
| 799 | OnDefaultFilteringBehaviorChanged(); |
bauerb | 4da3613 | 2014-12-26 19:53:13 | [diff] [blame] | 800 | whitelist_service_->Init(); |
[email protected] | f085fdd5 | 2014-06-11 18:09:20 | [diff] [blame] | 801 | UpdateManualHosts(); |
| 802 | UpdateManualURLs(); |
treib | 9e30e30 | 2015-04-15 08:12:16 | [diff] [blame^] | 803 | if (profile_->IsChild() && delegate_ && |
treib | e2082a0e | 2015-04-08 10:15:30 | [diff] [blame] | 804 | supervised_users::IsSafeSitesBlacklistEnabled()) { |
treib | d3f8b7a | 2015-04-10 11:41:33 | [diff] [blame] | 805 | LoadBlacklist(GetBlacklistPath(), GURL(kBlacklistURL)); |
treib | daece84f | 2014-09-05 12:58:15 | [diff] [blame] | 806 | } |
treib | 9e30e30 | 2015-04-15 08:12:16 | [diff] [blame^] | 807 | if (profile_->IsChild() && delegate_ && |
treib | e2082a0e | 2015-04-08 10:15:30 | [diff] [blame] | 808 | supervised_users::IsSafeSitesOnlineCheckEnabled()) { |
treib | d3f8b7a | 2015-04-10 11:41:33 | [diff] [blame] | 809 | url_filter_context_.InitAsyncURLChecker(profile_->GetRequestContext()); |
treib | 9e4fab90 | 2014-10-29 14:25:26 | [diff] [blame] | 810 | } |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 811 | |
[email protected] | 975677d | 2013-11-14 16:15:34 | [diff] [blame] | 812 | #if !defined(OS_ANDROID) |
[email protected] | f085fdd5 | 2014-06-11 18:09:20 | [diff] [blame] | 813 | // TODO(bauerb): Get rid of the platform-specific #ifdef here. |
| 814 | // http://crbug.com/313377 |
| 815 | BrowserList::AddObserver(this); |
[email protected] | 975677d | 2013-11-14 16:15:34 | [diff] [blame] | 816 | #endif |
[email protected] | f085fdd5 | 2014-06-11 18:09:20 | [diff] [blame] | 817 | } else { |
bauerb | d3a36cc4 | 2014-10-01 13:05:49 | [diff] [blame] | 818 | permissions_creators_.clear(); |
[email protected] | dfddd02 | 2013-07-10 17:29:48 | [diff] [blame] | 819 | |
[email protected] | d20d043 | 2014-06-12 17:14:05 | [diff] [blame] | 820 | pref_change_registrar_.Remove( |
| 821 | prefs::kDefaultSupervisedUserFilteringBehavior); |
| 822 | pref_change_registrar_.Remove(prefs::kSupervisedUserManualHosts); |
| 823 | pref_change_registrar_.Remove(prefs::kSupervisedUserManualURLs); |
treib | 22c3a04 | 2015-01-15 21:30:13 | [diff] [blame] | 824 | for (const char* pref : kCustodianInfoPrefs) { |
| 825 | pref_change_registrar_.Remove(pref); |
| 826 | } |
| 827 | |
| 828 | url_filter_context_.Clear(); |
| 829 | FOR_EACH_OBSERVER( |
| 830 | SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged()); |
[email protected] | f085fdd5 | 2014-06-11 18:09:20 | [diff] [blame] | 831 | |
[email protected] | 3a276ff | 2014-08-12 14:22:09 | [diff] [blame] | 832 | if (waiting_for_sync_initialization_) |
| 833 | ProfileSyncServiceFactory::GetForProfile(profile_)->RemoveObserver(this); |
[email protected] | f085fdd5 | 2014-06-11 18:09:20 | [diff] [blame] | 834 | |
| 835 | #if !defined(OS_ANDROID) |
| 836 | // TODO(bauerb): Get rid of the platform-specific #ifdef here. |
| 837 | // http://crbug.com/313377 |
| 838 | BrowserList::RemoveObserver(this); |
| 839 | #endif |
| 840 | } |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 841 | } |
| 842 | |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 843 | void SupervisedUserService::RegisterAndInitSync( |
| 844 | SupervisedUserRegistrationUtility* registration_utility, |
[email protected] | f252df2e | 2013-06-06 23:47:19 | [diff] [blame] | 845 | Profile* custodian_profile, |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 846 | const std::string& supervised_user_id, |
[email protected] | 514fcf2 | 2013-08-13 06:37:24 | [diff] [blame] | 847 | const AuthErrorCallback& callback) { |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 848 | DCHECK(ProfileIsSupervised()); |
[email protected] | d20d043 | 2014-06-12 17:14:05 | [diff] [blame] | 849 | DCHECK(!custodian_profile->IsSupervised()); |
[email protected] | 200729f8 | 2013-06-22 07:05:55 | [diff] [blame] | 850 | |
[email protected] | 6778fed | 2013-12-24 20:09:37 | [diff] [blame] | 851 | base::string16 name = base::UTF8ToUTF16( |
[email protected] | 4e2b6f3 | 2013-06-04 16:38:34 | [diff] [blame] | 852 | profile_->GetPrefs()->GetString(prefs::kProfileName)); |
[email protected] | b6c626e | 2013-09-09 13:51:08 | [diff] [blame] | 853 | int avatar_index = profile_->GetPrefs()->GetInteger( |
| 854 | prefs::kProfileAvatarIndex); |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 855 | SupervisedUserRegistrationInfo info(name, avatar_index); |
[email protected] | 458d5944 | 2013-08-01 14:19:32 | [diff] [blame] | 856 | registration_utility->Register( |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 857 | supervised_user_id, |
[email protected] | a96e6fd | 2013-06-17 14:36:58 | [diff] [blame] | 858 | info, |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 859 | base::Bind(&SupervisedUserService::OnSupervisedUserRegistered, |
[email protected] | f252df2e | 2013-06-06 23:47:19 | [diff] [blame] | 860 | weak_ptr_factory_.GetWeakPtr(), callback, custodian_profile)); |
[email protected] | 200729f8 | 2013-06-22 07:05:55 | [diff] [blame] | 861 | |
| 862 | // Fetch the custodian's profile information, to store the name. |
[email protected] | 115d5728c | 2013-10-23 18:06:14 | [diff] [blame] | 863 | // TODO(pamg): If --google-profile-info (flag: switches::kGoogleProfileInfo) |
[email protected] | 200729f8 | 2013-06-22 07:05:55 | [diff] [blame] | 864 | // is ever enabled, take the name from the ProfileInfoCache instead. |
[email protected] | 458d5944 | 2013-08-01 14:19:32 | [diff] [blame] | 865 | CustodianProfileDownloaderService* profile_downloader_service = |
| 866 | CustodianProfileDownloaderServiceFactory::GetForProfile( |
| 867 | custodian_profile); |
| 868 | profile_downloader_service->DownloadProfile( |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 869 | base::Bind(&SupervisedUserService::OnCustodianProfileDownloaded, |
[email protected] | 458d5944 | 2013-08-01 14:19:32 | [diff] [blame] | 870 | weak_ptr_factory_.GetWeakPtr())); |
[email protected] | 200729f8 | 2013-06-22 07:05:55 | [diff] [blame] | 871 | } |
| 872 | |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 873 | void SupervisedUserService::OnCustodianProfileDownloaded( |
[email protected] | 0085863a | 2013-12-06 21:19:03 | [diff] [blame] | 874 | const base::string16& full_name) { |
[email protected] | d20d043 | 2014-06-12 17:14:05 | [diff] [blame] | 875 | profile_->GetPrefs()->SetString(prefs::kSupervisedUserCustodianName, |
[email protected] | 6778fed | 2013-12-24 20:09:37 | [diff] [blame] | 876 | base::UTF16ToUTF8(full_name)); |
[email protected] | acfcfbb | 2013-05-13 18:01:27 | [diff] [blame] | 877 | } |
| 878 | |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 879 | void SupervisedUserService::OnSupervisedUserRegistered( |
[email protected] | 514fcf2 | 2013-08-13 06:37:24 | [diff] [blame] | 880 | const AuthErrorCallback& callback, |
[email protected] | f252df2e | 2013-06-06 23:47:19 | [diff] [blame] | 881 | Profile* custodian_profile, |
[email protected] | acfcfbb | 2013-05-13 18:01:27 | [diff] [blame] | 882 | const GoogleServiceAuthError& auth_error, |
| 883 | const std::string& token) { |
[email protected] | 514fcf2 | 2013-08-13 06:37:24 | [diff] [blame] | 884 | if (auth_error.state() == GoogleServiceAuthError::NONE) { |
| 885 | InitSync(token); |
| 886 | SigninManagerBase* signin = |
| 887 | SigninManagerFactory::GetForProfile(custodian_profile); |
[email protected] | d20d043 | 2014-06-12 17:14:05 | [diff] [blame] | 888 | profile_->GetPrefs()->SetString(prefs::kSupervisedUserCustodianEmail, |
[email protected] | 514fcf2 | 2013-08-13 06:37:24 | [diff] [blame] | 889 | signin->GetAuthenticatedUsername()); |
[email protected] | 5ddfade | 2014-02-03 10:24:53 | [diff] [blame] | 890 | |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 891 | // The supervised user profile is now ready for use. |
[email protected] | 5ddfade | 2014-02-03 10:24:53 | [diff] [blame] | 892 | ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 893 | ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); |
| 894 | size_t index = cache.GetIndexOfProfileWithPath(profile_->GetPath()); |
| 895 | cache.SetIsOmittedProfileAtIndex(index, false); |
[email protected] | 514fcf2 | 2013-08-13 06:37:24 | [diff] [blame] | 896 | } else { |
[email protected] | acfcfbb | 2013-05-13 18:01:27 | [diff] [blame] | 897 | DCHECK_EQ(std::string(), token); |
[email protected] | acfcfbb | 2013-05-13 18:01:27 | [diff] [blame] | 898 | } |
| 899 | |
[email protected] | 514fcf2 | 2013-08-13 06:37:24 | [diff] [blame] | 900 | callback.Run(auth_error); |
[email protected] | acfcfbb | 2013-05-13 18:01:27 | [diff] [blame] | 901 | } |
| 902 | |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 903 | void SupervisedUserService::UpdateManualHosts() { |
[email protected] | cb1078de | 2013-12-23 20:04:22 | [diff] [blame] | 904 | const base::DictionaryValue* dict = |
[email protected] | d20d043 | 2014-06-12 17:14:05 | [diff] [blame] | 905 | profile_->GetPrefs()->GetDictionary(prefs::kSupervisedUserManualHosts); |
[email protected] | 5e02229 | 2013-02-06 16:42:17 | [diff] [blame] | 906 | scoped_ptr<std::map<std::string, bool> > host_map( |
| 907 | new std::map<std::string, bool>()); |
[email protected] | cb1078de | 2013-12-23 20:04:22 | [diff] [blame] | 908 | for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { |
[email protected] | 5e02229 | 2013-02-06 16:42:17 | [diff] [blame] | 909 | bool allow = false; |
| 910 | bool result = it.value().GetAsBoolean(&allow); |
| 911 | DCHECK(result); |
| 912 | (*host_map)[it.key()] = allow; |
| 913 | } |
| 914 | url_filter_context_.SetManualHosts(host_map.Pass()); |
treib | ab0a39e | 2014-09-24 14:48:28 | [diff] [blame] | 915 | |
| 916 | FOR_EACH_OBSERVER( |
| 917 | SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged()); |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 918 | } |
| 919 | |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 920 | void SupervisedUserService::UpdateManualURLs() { |
[email protected] | cb1078de | 2013-12-23 20:04:22 | [diff] [blame] | 921 | const base::DictionaryValue* dict = |
[email protected] | d20d043 | 2014-06-12 17:14:05 | [diff] [blame] | 922 | profile_->GetPrefs()->GetDictionary(prefs::kSupervisedUserManualURLs); |
[email protected] | 5e02229 | 2013-02-06 16:42:17 | [diff] [blame] | 923 | scoped_ptr<std::map<GURL, bool> > url_map(new std::map<GURL, bool>()); |
[email protected] | cb1078de | 2013-12-23 20:04:22 | [diff] [blame] | 924 | for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { |
[email protected] | 5e02229 | 2013-02-06 16:42:17 | [diff] [blame] | 925 | bool allow = false; |
| 926 | bool result = it.value().GetAsBoolean(&allow); |
| 927 | DCHECK(result); |
| 928 | (*url_map)[GURL(it.key())] = allow; |
| 929 | } |
| 930 | url_filter_context_.SetManualURLs(url_map.Pass()); |
treib | ab0a39e | 2014-09-24 14:48:28 | [diff] [blame] | 931 | |
| 932 | FOR_EACH_OBSERVER( |
| 933 | SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged()); |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 934 | } |
[email protected] | dfddd02 | 2013-07-10 17:29:48 | [diff] [blame] | 935 | |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 936 | void SupervisedUserService::OnBrowserSetLastActive(Browser* browser) { |
[email protected] | dfddd02 | 2013-07-10 17:29:48 | [diff] [blame] | 937 | bool profile_became_active = profile_->IsSameProfile(browser->profile()); |
| 938 | if (!is_profile_active_ && profile_became_active) |
[email protected] | 2056c3b | 2014-04-07 18:08:50 | [diff] [blame] | 939 | content::RecordAction(UserMetricsAction("ManagedUsers_OpenProfile")); |
[email protected] | dfddd02 | 2013-07-10 17:29:48 | [diff] [blame] | 940 | else if (is_profile_active_ && !profile_became_active) |
[email protected] | 2056c3b | 2014-04-07 18:08:50 | [diff] [blame] | 941 | content::RecordAction(UserMetricsAction("ManagedUsers_SwitchProfile")); |
[email protected] | dfddd02 | 2013-07-10 17:29:48 | [diff] [blame] | 942 | |
| 943 | is_profile_active_ = profile_became_active; |
| 944 | } |
[email protected] | 0b4c6b2 | 2014-08-04 09:46:31 | [diff] [blame] | 945 | |
| 946 | std::string SupervisedUserService::GetSupervisedUserName() const { |
| 947 | #if defined(OS_CHROMEOS) |
| 948 | // The active user can be NULL in unit tests. |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 949 | if (user_manager::UserManager::Get()->GetActiveUser()) { |
| 950 | return UTF16ToUTF8(user_manager::UserManager::Get()->GetUserDisplayName( |
| 951 | user_manager::UserManager::Get()->GetActiveUser()->GetUserID())); |
[email protected] | 0b4c6b2 | 2014-08-04 09:46:31 | [diff] [blame] | 952 | } |
| 953 | return std::string(); |
| 954 | #else |
| 955 | return profile_->GetPrefs()->GetString(prefs::kProfileName); |
| 956 | #endif |
| 957 | } |