| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/managed_mode/managed_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" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 13 #include "chrome/browser/extensions/extension_service.h" | 13 #include "chrome/browser/extensions/extension_service.h" |
| 14 #include "chrome/browser/managed_mode/custodian_profile_downloader_service.h" | |
| 15 #include "chrome/browser/managed_mode/custodian_profile_downloader_service_facto
ry.h" | |
| 16 #include "chrome/browser/managed_mode/managed_mode_site_list.h" | |
| 17 #include "chrome/browser/managed_mode/managed_user_constants.h" | |
| 18 #include "chrome/browser/managed_mode/managed_user_registration_utility.h" | |
| 19 #include "chrome/browser/managed_mode/managed_user_settings_service.h" | |
| 20 #include "chrome/browser/managed_mode/managed_user_settings_service_factory.h" | |
| 21 #include "chrome/browser/managed_mode/managed_user_shared_settings_service_facto
ry.h" | |
| 22 #include "chrome/browser/managed_mode/managed_user_sync_service.h" | |
| 23 #include "chrome/browser/managed_mode/managed_user_sync_service_factory.h" | |
| 24 #include "chrome/browser/managed_mode/permission_request_creator_apiary.h" | |
| 25 #include "chrome/browser/managed_mode/permission_request_creator_sync.h" | |
| 26 #include "chrome/browser/managed_mode/supervised_user_pref_mapping_service.h" | |
| 27 #include "chrome/browser/managed_mode/supervised_user_pref_mapping_service_facto
ry.h" | |
| 28 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 29 #include "chrome/browser/profiles/profile_info_cache.h" | 15 #include "chrome/browser/profiles/profile_info_cache.h" |
| 30 #include "chrome/browser/profiles/profile_manager.h" | 16 #include "chrome/browser/profiles/profile_manager.h" |
| 31 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 17 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 32 #include "chrome/browser/signin/signin_manager_factory.h" | 18 #include "chrome/browser/signin/signin_manager_factory.h" |
| 19 #include "chrome/browser/supervised_user/custodian_profile_downloader_service.h" |
| 20 #include "chrome/browser/supervised_user/custodian_profile_downloader_service_fa
ctory.h" |
| 21 #include "chrome/browser/supervised_user/permission_request_creator_apiary.h" |
| 22 #include "chrome/browser/supervised_user/permission_request_creator_sync.h" |
| 23 #include "chrome/browser/supervised_user/supervised_user_constants.h" |
| 24 #include "chrome/browser/supervised_user/supervised_user_pref_mapping_service.h" |
| 25 #include "chrome/browser/supervised_user/supervised_user_pref_mapping_service_fa
ctory.h" |
| 26 #include "chrome/browser/supervised_user/supervised_user_registration_utility.h" |
| 27 #include "chrome/browser/supervised_user/supervised_user_settings_service.h" |
| 28 #include "chrome/browser/supervised_user/supervised_user_settings_service_factor
y.h" |
| 29 #include "chrome/browser/supervised_user/supervised_user_shared_settings_service
_factory.h" |
| 30 #include "chrome/browser/supervised_user/supervised_user_site_list.h" |
| 31 #include "chrome/browser/supervised_user/supervised_user_sync_service.h" |
| 32 #include "chrome/browser/supervised_user/supervised_user_sync_service_factory.h" |
| 33 #include "chrome/browser/sync/profile_sync_service.h" | 33 #include "chrome/browser/sync/profile_sync_service.h" |
| 34 #include "chrome/browser/sync/profile_sync_service_factory.h" | 34 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 35 #include "chrome/browser/ui/browser.h" | 35 #include "chrome/browser/ui/browser.h" |
| 36 #include "chrome/browser/ui/browser_list.h" | 36 #include "chrome/browser/ui/browser_list.h" |
| 37 #include "chrome/common/chrome_switches.h" | 37 #include "chrome/common/chrome_switches.h" |
| 38 #include "chrome/common/extensions/api/managed_mode_private/managed_mode_handler
.h" | 38 #include "chrome/common/extensions/api/managed_mode_private/managed_mode_handler
.h" |
| 39 #include "chrome/common/pref_names.h" | 39 #include "chrome/common/pref_names.h" |
| 40 #include "components/pref_registry/pref_registry_syncable.h" | 40 #include "components/pref_registry/pref_registry_syncable.h" |
| 41 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 41 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 42 #include "components/signin/core/browser/signin_manager.h" | 42 #include "components/signin/core/browser/signin_manager.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 58 | 58 |
| 59 #if defined(ENABLE_THEMES) | 59 #if defined(ENABLE_THEMES) |
| 60 #include "chrome/browser/themes/theme_service.h" | 60 #include "chrome/browser/themes/theme_service.h" |
| 61 #include "chrome/browser/themes/theme_service_factory.h" | 61 #include "chrome/browser/themes/theme_service_factory.h" |
| 62 #endif | 62 #endif |
| 63 | 63 |
| 64 using base::DictionaryValue; | 64 using base::DictionaryValue; |
| 65 using base::UserMetricsAction; | 65 using base::UserMetricsAction; |
| 66 using content::BrowserThread; | 66 using content::BrowserThread; |
| 67 | 67 |
| 68 ManagedUserService::URLFilterContext::URLFilterContext() | 68 SupervisedUserService::URLFilterContext::URLFilterContext() |
| 69 : ui_url_filter_(new ManagedModeURLFilter), | 69 : ui_url_filter_(new SupervisedUserURLFilter), |
| 70 io_url_filter_(new ManagedModeURLFilter) {} | 70 io_url_filter_(new SupervisedUserURLFilter) {} |
| 71 ManagedUserService::URLFilterContext::~URLFilterContext() {} | 71 SupervisedUserService::URLFilterContext::~URLFilterContext() {} |
| 72 | 72 |
| 73 ManagedModeURLFilter* | 73 SupervisedUserURLFilter* |
| 74 ManagedUserService::URLFilterContext::ui_url_filter() const { | 74 SupervisedUserService::URLFilterContext::ui_url_filter() const { |
| 75 return ui_url_filter_.get(); | 75 return ui_url_filter_.get(); |
| 76 } | 76 } |
| 77 | 77 |
| 78 ManagedModeURLFilter* | 78 SupervisedUserURLFilter* |
| 79 ManagedUserService::URLFilterContext::io_url_filter() const { | 79 SupervisedUserService::URLFilterContext::io_url_filter() const { |
| 80 return io_url_filter_.get(); | 80 return io_url_filter_.get(); |
| 81 } | 81 } |
| 82 | 82 |
| 83 void ManagedUserService::URLFilterContext::SetDefaultFilteringBehavior( | 83 void SupervisedUserService::URLFilterContext::SetDefaultFilteringBehavior( |
| 84 ManagedModeURLFilter::FilteringBehavior behavior) { | 84 SupervisedUserURLFilter::FilteringBehavior behavior) { |
| 85 ui_url_filter_->SetDefaultFilteringBehavior(behavior); | 85 ui_url_filter_->SetDefaultFilteringBehavior(behavior); |
| 86 BrowserThread::PostTask( | 86 BrowserThread::PostTask( |
| 87 BrowserThread::IO, | 87 BrowserThread::IO, |
| 88 FROM_HERE, | 88 FROM_HERE, |
| 89 base::Bind(&ManagedModeURLFilter::SetDefaultFilteringBehavior, | 89 base::Bind(&SupervisedUserURLFilter::SetDefaultFilteringBehavior, |
| 90 io_url_filter_.get(), behavior)); | 90 io_url_filter_.get(), behavior)); |
| 91 } | 91 } |
| 92 | 92 |
| 93 void ManagedUserService::URLFilterContext::LoadWhitelists( | 93 void SupervisedUserService::URLFilterContext::LoadWhitelists( |
| 94 ScopedVector<ManagedModeSiteList> site_lists) { | 94 ScopedVector<SupervisedUserSiteList> site_lists) { |
| 95 // ManagedModeURLFilter::LoadWhitelists takes ownership of |site_lists|, | 95 // SupervisedUserURLFilter::LoadWhitelists takes ownership of |site_lists|, |
| 96 // so we make an additional copy of it. | 96 // so we make an additional copy of it. |
| 97 /// TODO(bauerb): This is kinda ugly. | 97 /// TODO(bauerb): This is kinda ugly. |
| 98 ScopedVector<ManagedModeSiteList> site_lists_copy; | 98 ScopedVector<SupervisedUserSiteList> site_lists_copy; |
| 99 for (ScopedVector<ManagedModeSiteList>::iterator it = site_lists.begin(); | 99 for (ScopedVector<SupervisedUserSiteList>::iterator it = site_lists.begin(); |
| 100 it != site_lists.end(); ++it) { | 100 it != site_lists.end(); ++it) { |
| 101 site_lists_copy.push_back((*it)->Clone()); | 101 site_lists_copy.push_back((*it)->Clone()); |
| 102 } | 102 } |
| 103 ui_url_filter_->LoadWhitelists(site_lists.Pass()); | 103 ui_url_filter_->LoadWhitelists(site_lists.Pass()); |
| 104 BrowserThread::PostTask( | 104 BrowserThread::PostTask( |
| 105 BrowserThread::IO, | 105 BrowserThread::IO, |
| 106 FROM_HERE, | 106 FROM_HERE, |
| 107 base::Bind(&ManagedModeURLFilter::LoadWhitelists, | 107 base::Bind(&SupervisedUserURLFilter::LoadWhitelists, |
| 108 io_url_filter_, base::Passed(&site_lists_copy))); | 108 io_url_filter_, base::Passed(&site_lists_copy))); |
| 109 } | 109 } |
| 110 | 110 |
| 111 void ManagedUserService::URLFilterContext::SetManualHosts( | 111 void SupervisedUserService::URLFilterContext::SetManualHosts( |
| 112 scoped_ptr<std::map<std::string, bool> > host_map) { | 112 scoped_ptr<std::map<std::string, bool> > host_map) { |
| 113 ui_url_filter_->SetManualHosts(host_map.get()); | 113 ui_url_filter_->SetManualHosts(host_map.get()); |
| 114 BrowserThread::PostTask( | 114 BrowserThread::PostTask( |
| 115 BrowserThread::IO, | 115 BrowserThread::IO, |
| 116 FROM_HERE, | 116 FROM_HERE, |
| 117 base::Bind(&ManagedModeURLFilter::SetManualHosts, | 117 base::Bind(&SupervisedUserURLFilter::SetManualHosts, |
| 118 io_url_filter_, base::Owned(host_map.release()))); | 118 io_url_filter_, base::Owned(host_map.release()))); |
| 119 } | 119 } |
| 120 | 120 |
| 121 void ManagedUserService::URLFilterContext::SetManualURLs( | 121 void SupervisedUserService::URLFilterContext::SetManualURLs( |
| 122 scoped_ptr<std::map<GURL, bool> > url_map) { | 122 scoped_ptr<std::map<GURL, bool> > url_map) { |
| 123 ui_url_filter_->SetManualURLs(url_map.get()); | 123 ui_url_filter_->SetManualURLs(url_map.get()); |
| 124 BrowserThread::PostTask( | 124 BrowserThread::PostTask( |
| 125 BrowserThread::IO, | 125 BrowserThread::IO, |
| 126 FROM_HERE, | 126 FROM_HERE, |
| 127 base::Bind(&ManagedModeURLFilter::SetManualURLs, | 127 base::Bind(&SupervisedUserURLFilter::SetManualURLs, |
| 128 io_url_filter_, base::Owned(url_map.release()))); | 128 io_url_filter_, base::Owned(url_map.release()))); |
| 129 } | 129 } |
| 130 | 130 |
| 131 ManagedUserService::ManagedUserService(Profile* profile) | 131 SupervisedUserService::SupervisedUserService(Profile* profile) |
| 132 : profile_(profile), | 132 : profile_(profile), |
| 133 active_(false), | 133 active_(false), |
| 134 delegate_(NULL), | 134 delegate_(NULL), |
| 135 extension_registry_observer_(this), | 135 extension_registry_observer_(this), |
| 136 waiting_for_sync_initialization_(false), | 136 waiting_for_sync_initialization_(false), |
| 137 is_profile_active_(false), | 137 is_profile_active_(false), |
| 138 elevated_for_testing_(false), | 138 elevated_for_testing_(false), |
| 139 did_shutdown_(false), | 139 did_shutdown_(false), |
| 140 waiting_for_permissions_(false), | 140 waiting_for_permissions_(false), |
| 141 weak_ptr_factory_(this) { | 141 weak_ptr_factory_(this) { |
| 142 } | 142 } |
| 143 | 143 |
| 144 ManagedUserService::~ManagedUserService() { | 144 SupervisedUserService::~SupervisedUserService() { |
| 145 DCHECK(did_shutdown_); | 145 DCHECK(did_shutdown_); |
| 146 } | 146 } |
| 147 | 147 |
| 148 void ManagedUserService::Shutdown() { | 148 void SupervisedUserService::Shutdown() { |
| 149 did_shutdown_ = true; | 149 did_shutdown_ = true; |
| 150 if (ProfileIsManaged()) { | 150 if (ProfileIsSupervised()) { |
| 151 content::RecordAction(UserMetricsAction("ManagedUsers_QuitBrowser")); | 151 content::RecordAction(UserMetricsAction("ManagedUsers_QuitBrowser")); |
| 152 } | 152 } |
| 153 SetActive(false); | 153 SetActive(false); |
| 154 } | 154 } |
| 155 | 155 |
| 156 bool ManagedUserService::ProfileIsManaged() const { | 156 bool SupervisedUserService::ProfileIsSupervised() const { |
| 157 return profile_->IsSupervised(); | 157 return profile_->IsSupervised(); |
| 158 } | 158 } |
| 159 | 159 |
| 160 // static | 160 // static |
| 161 void ManagedUserService::RegisterProfilePrefs( | 161 void SupervisedUserService::RegisterProfilePrefs( |
| 162 user_prefs::PrefRegistrySyncable* registry) { | 162 user_prefs::PrefRegistrySyncable* registry) { |
| 163 registry->RegisterDictionaryPref( | 163 registry->RegisterDictionaryPref( |
| 164 prefs::kSupervisedUserManualHosts, | 164 prefs::kSupervisedUserManualHosts, |
| 165 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 165 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 166 registry->RegisterDictionaryPref( | 166 registry->RegisterDictionaryPref( |
| 167 prefs::kSupervisedUserManualURLs, | 167 prefs::kSupervisedUserManualURLs, |
| 168 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 168 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 169 registry->RegisterIntegerPref( | 169 registry->RegisterIntegerPref( |
| 170 prefs::kDefaultSupervisedUserFilteringBehavior, | 170 prefs::kDefaultSupervisedUserFilteringBehavior, |
| 171 ManagedModeURLFilter::ALLOW, | 171 SupervisedUserURLFilter::ALLOW, |
| 172 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 172 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 173 registry->RegisterStringPref( | 173 registry->RegisterStringPref( |
| 174 prefs::kSupervisedUserCustodianEmail, std::string(), | 174 prefs::kSupervisedUserCustodianEmail, std::string(), |
| 175 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 175 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 176 registry->RegisterStringPref( | 176 registry->RegisterStringPref( |
| 177 prefs::kSupervisedUserCustodianName, std::string(), | 177 prefs::kSupervisedUserCustodianName, std::string(), |
| 178 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 178 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 179 registry->RegisterBooleanPref(prefs::kSupervisedUserCreationAllowed, true, | 179 registry->RegisterBooleanPref(prefs::kSupervisedUserCreationAllowed, true, |
| 180 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 180 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 181 } | 181 } |
| 182 | 182 |
| 183 // static | 183 // static |
| 184 void ManagedUserService::MigrateUserPrefs(PrefService* prefs) { | 184 void SupervisedUserService::MigrateUserPrefs(PrefService* prefs) { |
| 185 if (!prefs->HasPrefPath(prefs::kProfileIsSupervised)) | 185 if (!prefs->HasPrefPath(prefs::kProfileIsSupervised)) |
| 186 return; | 186 return; |
| 187 | 187 |
| 188 bool is_managed = prefs->GetBoolean(prefs::kProfileIsSupervised); | 188 bool is_supervised = prefs->GetBoolean(prefs::kProfileIsSupervised); |
| 189 prefs->ClearPref(prefs::kProfileIsSupervised); | 189 prefs->ClearPref(prefs::kProfileIsSupervised); |
| 190 | 190 |
| 191 if (!is_managed) | 191 if (!is_supervised) |
| 192 return; | 192 return; |
| 193 | 193 |
| 194 std::string managed_user_id = prefs->GetString(prefs::kSupervisedUserId); | 194 std::string supervised_user_id = prefs->GetString(prefs::kSupervisedUserId); |
| 195 if (!managed_user_id.empty()) | 195 if (!supervised_user_id.empty()) |
| 196 return; | 196 return; |
| 197 | 197 |
| 198 prefs->SetString(prefs::kSupervisedUserId, "Dummy ID"); | 198 prefs->SetString(prefs::kSupervisedUserId, "Dummy ID"); |
| 199 } | 199 } |
| 200 | 200 |
| 201 void ManagedUserService::SetDelegate(Delegate* delegate) { | 201 void SupervisedUserService::SetDelegate(Delegate* delegate) { |
| 202 if (delegate_ == delegate) | 202 if (delegate_ == delegate) |
| 203 return; | 203 return; |
| 204 // If the delegate changed, deactivate first to give the old delegate a chance | 204 // If the delegate changed, deactivate first to give the old delegate a chance |
| 205 // to clean up. | 205 // to clean up. |
| 206 SetActive(false); | 206 SetActive(false); |
| 207 delegate_ = delegate; | 207 delegate_ = delegate; |
| 208 } | 208 } |
| 209 | 209 |
| 210 scoped_refptr<const ManagedModeURLFilter> | 210 scoped_refptr<const SupervisedUserURLFilter> |
| 211 ManagedUserService::GetURLFilterForIOThread() { | 211 SupervisedUserService::GetURLFilterForIOThread() { |
| 212 return url_filter_context_.io_url_filter(); | 212 return url_filter_context_.io_url_filter(); |
| 213 } | 213 } |
| 214 | 214 |
| 215 ManagedModeURLFilter* ManagedUserService::GetURLFilterForUIThread() { | 215 SupervisedUserURLFilter* SupervisedUserService::GetURLFilterForUIThread() { |
| 216 return url_filter_context_.ui_url_filter(); | 216 return url_filter_context_.ui_url_filter(); |
| 217 } | 217 } |
| 218 | 218 |
| 219 // Items not on any list must return -1 (CATEGORY_NOT_ON_LIST in history.js). | 219 // Items not on any list must return -1 (CATEGORY_NOT_ON_LIST in history.js). |
| 220 // Items on a list, but with no category, must return 0 (CATEGORY_OTHER). | 220 // Items on a list, but with no category, must return 0 (CATEGORY_OTHER). |
| 221 #define CATEGORY_NOT_ON_LIST -1; | 221 #define CATEGORY_NOT_ON_LIST -1; |
| 222 #define CATEGORY_OTHER 0; | 222 #define CATEGORY_OTHER 0; |
| 223 | 223 |
| 224 int ManagedUserService::GetCategory(const GURL& url) { | 224 int SupervisedUserService::GetCategory(const GURL& url) { |
| 225 std::vector<ManagedModeSiteList::Site*> sites; | 225 std::vector<SupervisedUserSiteList::Site*> sites; |
| 226 GetURLFilterForUIThread()->GetSites(url, &sites); | 226 GetURLFilterForUIThread()->GetSites(url, &sites); |
| 227 if (sites.empty()) | 227 if (sites.empty()) |
| 228 return CATEGORY_NOT_ON_LIST; | 228 return CATEGORY_NOT_ON_LIST; |
| 229 | 229 |
| 230 return (*sites.begin())->category_id; | 230 return (*sites.begin())->category_id; |
| 231 } | 231 } |
| 232 | 232 |
| 233 // static | 233 // static |
| 234 void ManagedUserService::GetCategoryNames(CategoryList* list) { | 234 void SupervisedUserService::GetCategoryNames(CategoryList* list) { |
| 235 ManagedModeSiteList::GetCategoryNames(list); | 235 SupervisedUserSiteList::GetCategoryNames(list); |
| 236 } | 236 } |
| 237 | 237 |
| 238 std::string ManagedUserService::GetCustodianEmailAddress() const { | 238 std::string SupervisedUserService::GetCustodianEmailAddress() const { |
| 239 #if defined(OS_CHROMEOS) | 239 #if defined(OS_CHROMEOS) |
| 240 return chromeos::UserManager::Get()->GetSupervisedUserManager()-> | 240 return chromeos::UserManager::Get()->GetSupervisedUserManager()-> |
| 241 GetManagerDisplayEmail( | 241 GetManagerDisplayEmail( |
| 242 chromeos::UserManager::Get()->GetActiveUser()->email()); | 242 chromeos::UserManager::Get()->GetActiveUser()->email()); |
| 243 #else | 243 #else |
| 244 return profile_->GetPrefs()->GetString(prefs::kSupervisedUserCustodianEmail); | 244 return profile_->GetPrefs()->GetString(prefs::kSupervisedUserCustodianEmail); |
| 245 #endif | 245 #endif |
| 246 } | 246 } |
| 247 | 247 |
| 248 std::string ManagedUserService::GetCustodianName() const { | 248 std::string SupervisedUserService::GetCustodianName() const { |
| 249 #if defined(OS_CHROMEOS) | 249 #if defined(OS_CHROMEOS) |
| 250 return base::UTF16ToUTF8(chromeos::UserManager::Get()-> | 250 return base::UTF16ToUTF8(chromeos::UserManager::Get()-> |
| 251 GetSupervisedUserManager()->GetManagerDisplayName( | 251 GetSupervisedUserManager()->GetManagerDisplayName( |
| 252 chromeos::UserManager::Get()->GetActiveUser()->email())); | 252 chromeos::UserManager::Get()->GetActiveUser()->email())); |
| 253 #else | 253 #else |
| 254 std::string name = profile_->GetPrefs()->GetString( | 254 std::string name = profile_->GetPrefs()->GetString( |
| 255 prefs::kSupervisedUserCustodianName); | 255 prefs::kSupervisedUserCustodianName); |
| 256 return name.empty() ? GetCustodianEmailAddress() : name; | 256 return name.empty() ? GetCustodianEmailAddress() : name; |
| 257 #endif | 257 #endif |
| 258 } | 258 } |
| 259 | 259 |
| 260 void ManagedUserService::AddNavigationBlockedCallback( | 260 void SupervisedUserService::AddNavigationBlockedCallback( |
| 261 const NavigationBlockedCallback& callback) { | 261 const NavigationBlockedCallback& callback) { |
| 262 navigation_blocked_callbacks_.push_back(callback); | 262 navigation_blocked_callbacks_.push_back(callback); |
| 263 } | 263 } |
| 264 | 264 |
| 265 void ManagedUserService::DidBlockNavigation( | 265 void SupervisedUserService::DidBlockNavigation( |
| 266 content::WebContents* web_contents) { | 266 content::WebContents* web_contents) { |
| 267 for (std::vector<NavigationBlockedCallback>::iterator it = | 267 for (std::vector<NavigationBlockedCallback>::iterator it = |
| 268 navigation_blocked_callbacks_.begin(); | 268 navigation_blocked_callbacks_.begin(); |
| 269 it != navigation_blocked_callbacks_.end(); ++it) { | 269 it != navigation_blocked_callbacks_.end(); ++it) { |
| 270 it->Run(web_contents); | 270 it->Run(web_contents); |
| 271 } | 271 } |
| 272 } | 272 } |
| 273 | 273 |
| 274 std::string ManagedUserService::GetDebugPolicyProviderName() const { | 274 std::string SupervisedUserService::GetDebugPolicyProviderName() const { |
| 275 // Save the string space in official builds. | 275 // Save the string space in official builds. |
| 276 #ifdef NDEBUG | 276 #ifdef NDEBUG |
| 277 NOTREACHED(); | 277 NOTREACHED(); |
| 278 return std::string(); | 278 return std::string(); |
| 279 #else | 279 #else |
| 280 return "Managed User Service"; | 280 return "Supervised User Service"; |
| 281 #endif | 281 #endif |
| 282 } | 282 } |
| 283 | 283 |
| 284 bool ManagedUserService::UserMayLoad(const extensions::Extension* extension, | 284 bool SupervisedUserService::UserMayLoad(const extensions::Extension* extension, |
| 285 base::string16* error) const { | 285 base::string16* error) const { |
| 286 base::string16 tmp_error; | 286 base::string16 tmp_error; |
| 287 if (ExtensionManagementPolicyImpl(extension, &tmp_error)) | 287 if (ExtensionManagementPolicyImpl(extension, &tmp_error)) |
| 288 return true; | 288 return true; |
| 289 | 289 |
| 290 // If the extension is already loaded, we allow it, otherwise we'd unload | 290 // If the extension is already loaded, we allow it, otherwise we'd unload |
| 291 // all existing extensions. | 291 // all existing extensions. |
| 292 ExtensionService* extension_service = | 292 ExtensionService* extension_service = |
| 293 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 293 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
| 294 | 294 |
| 295 // |extension_service| can be NULL in a unit test. | 295 // |extension_service| can be NULL in a unit test. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 311 if (extension->location() == extensions::Manifest::COMPONENT || | 311 if (extension->location() == extensions::Manifest::COMPONENT || |
| 312 was_installed_by_default) { | 312 was_installed_by_default) { |
| 313 return true; | 313 return true; |
| 314 } | 314 } |
| 315 | 315 |
| 316 if (error) | 316 if (error) |
| 317 *error = tmp_error; | 317 *error = tmp_error; |
| 318 return false; | 318 return false; |
| 319 } | 319 } |
| 320 | 320 |
| 321 bool ManagedUserService::UserMayModifySettings( | 321 bool SupervisedUserService::UserMayModifySettings( |
| 322 const extensions::Extension* extension, | 322 const extensions::Extension* extension, |
| 323 base::string16* error) const { | 323 base::string16* error) const { |
| 324 return ExtensionManagementPolicyImpl(extension, error); | 324 return ExtensionManagementPolicyImpl(extension, error); |
| 325 } | 325 } |
| 326 | 326 |
| 327 void ManagedUserService::OnStateChanged() { | 327 void SupervisedUserService::OnStateChanged() { |
| 328 ProfileSyncService* service = | 328 ProfileSyncService* service = |
| 329 ProfileSyncServiceFactory::GetForProfile(profile_); | 329 ProfileSyncServiceFactory::GetForProfile(profile_); |
| 330 if (waiting_for_sync_initialization_ && service->sync_initialized()) { | 330 if (waiting_for_sync_initialization_ && service->sync_initialized()) { |
| 331 waiting_for_sync_initialization_ = false; | 331 waiting_for_sync_initialization_ = false; |
| 332 service->RemoveObserver(this); | 332 service->RemoveObserver(this); |
| 333 SetupSync(); | 333 SetupSync(); |
| 334 return; | 334 return; |
| 335 } | 335 } |
| 336 | 336 |
| 337 DLOG_IF(ERROR, service->GetAuthError().state() == | 337 DLOG_IF(ERROR, service->GetAuthError().state() == |
| 338 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS) | 338 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS) |
| 339 << "Credentials rejected"; | 339 << "Credentials rejected"; |
| 340 } | 340 } |
| 341 | 341 |
| 342 void ManagedUserService::OnExtensionLoaded( | 342 void SupervisedUserService::OnExtensionLoaded( |
| 343 content::BrowserContext* browser_context, | 343 content::BrowserContext* browser_context, |
| 344 const extensions::Extension* extension) { | 344 const extensions::Extension* extension) { |
| 345 if (!extensions::ManagedModeInfo::GetContentPackSiteList(extension).empty()) { | 345 if (!extensions::ManagedModeInfo::GetContentPackSiteList(extension).empty()) { |
| 346 UpdateSiteLists(); | 346 UpdateSiteLists(); |
| 347 } | 347 } |
| 348 } | 348 } |
| 349 void ManagedUserService::OnExtensionUnloaded( | 349 void SupervisedUserService::OnExtensionUnloaded( |
| 350 content::BrowserContext* browser_context, | 350 content::BrowserContext* browser_context, |
| 351 const extensions::Extension* extension, | 351 const extensions::Extension* extension, |
| 352 extensions::UnloadedExtensionInfo::Reason reason) { | 352 extensions::UnloadedExtensionInfo::Reason reason) { |
| 353 if (!extensions::ManagedModeInfo::GetContentPackSiteList(extension).empty()) { | 353 if (!extensions::ManagedModeInfo::GetContentPackSiteList(extension).empty()) { |
| 354 UpdateSiteLists(); | 354 UpdateSiteLists(); |
| 355 } | 355 } |
| 356 } | 356 } |
| 357 | 357 |
| 358 void ManagedUserService::SetupSync() { | 358 void SupervisedUserService::SetupSync() { |
| 359 ProfileSyncService* service = | 359 ProfileSyncService* service = |
| 360 ProfileSyncServiceFactory::GetForProfile(profile_); | 360 ProfileSyncServiceFactory::GetForProfile(profile_); |
| 361 DCHECK(service->sync_initialized()); | 361 DCHECK(service->sync_initialized()); |
| 362 | 362 |
| 363 bool sync_everything = false; | 363 bool sync_everything = false; |
| 364 syncer::ModelTypeSet synced_datatypes; | 364 syncer::ModelTypeSet synced_datatypes; |
| 365 synced_datatypes.Put(syncer::SUPERVISED_USER_SETTINGS); | 365 synced_datatypes.Put(syncer::SUPERVISED_USER_SETTINGS); |
| 366 service->OnUserChoseDatatypes(sync_everything, synced_datatypes); | 366 service->OnUserChoseDatatypes(sync_everything, synced_datatypes); |
| 367 | 367 |
| 368 // Notify ProfileSyncService that we are done with configuration. | 368 // Notify ProfileSyncService that we are done with configuration. |
| 369 service->SetSetupInProgress(false); | 369 service->SetSetupInProgress(false); |
| 370 service->SetSyncSetupCompleted(); | 370 service->SetSyncSetupCompleted(); |
| 371 } | 371 } |
| 372 | 372 |
| 373 bool ManagedUserService::ExtensionManagementPolicyImpl( | 373 bool SupervisedUserService::ExtensionManagementPolicyImpl( |
| 374 const extensions::Extension* extension, | 374 const extensions::Extension* extension, |
| 375 base::string16* error) const { | 375 base::string16* error) const { |
| 376 // |extension| can be NULL in unit_tests. | 376 // |extension| can be NULL in unit_tests. |
| 377 if (!ProfileIsManaged() || (extension && extension->is_theme())) | 377 if (!ProfileIsSupervised() || (extension && extension->is_theme())) |
| 378 return true; | 378 return true; |
| 379 | 379 |
| 380 if (elevated_for_testing_) | 380 if (elevated_for_testing_) |
| 381 return true; | 381 return true; |
| 382 | 382 |
| 383 if (error) | 383 if (error) |
| 384 *error = l10n_util::GetStringUTF16(IDS_EXTENSIONS_LOCKED_MANAGED_USER); | 384 *error = l10n_util::GetStringUTF16(IDS_EXTENSIONS_LOCKED_MANAGED_USER); |
| 385 return false; | 385 return false; |
| 386 } | 386 } |
| 387 | 387 |
| 388 ScopedVector<ManagedModeSiteList> ManagedUserService::GetActiveSiteLists() { | 388 ScopedVector<SupervisedUserSiteList> |
| 389 ScopedVector<ManagedModeSiteList> site_lists; | 389 SupervisedUserService::GetActiveSiteLists() { |
| 390 ScopedVector<SupervisedUserSiteList> site_lists; |
| 390 ExtensionService* extension_service = | 391 ExtensionService* extension_service = |
| 391 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 392 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
| 392 // Can be NULL in unit tests. | 393 // Can be NULL in unit tests. |
| 393 if (!extension_service) | 394 if (!extension_service) |
| 394 return site_lists.Pass(); | 395 return site_lists.Pass(); |
| 395 | 396 |
| 396 const extensions::ExtensionSet* extensions = extension_service->extensions(); | 397 const extensions::ExtensionSet* extensions = extension_service->extensions(); |
| 397 for (extensions::ExtensionSet::const_iterator it = extensions->begin(); | 398 for (extensions::ExtensionSet::const_iterator it = extensions->begin(); |
| 398 it != extensions->end(); ++it) { | 399 it != extensions->end(); ++it) { |
| 399 const extensions::Extension* extension = it->get(); | 400 const extensions::Extension* extension = it->get(); |
| 400 if (!extension_service->IsExtensionEnabled(extension->id())) | 401 if (!extension_service->IsExtensionEnabled(extension->id())) |
| 401 continue; | 402 continue; |
| 402 | 403 |
| 403 extensions::ExtensionResource site_list = | 404 extensions::ExtensionResource site_list = |
| 404 extensions::ManagedModeInfo::GetContentPackSiteList(extension); | 405 extensions::ManagedModeInfo::GetContentPackSiteList(extension); |
| 405 if (!site_list.empty()) { | 406 if (!site_list.empty()) { |
| 406 site_lists.push_back(new ManagedModeSiteList(extension->id(), | 407 site_lists.push_back(new SupervisedUserSiteList(extension->id(), |
| 407 site_list.GetFilePath())); | 408 site_list.GetFilePath())); |
| 408 } | 409 } |
| 409 } | 410 } |
| 410 | 411 |
| 411 return site_lists.Pass(); | 412 return site_lists.Pass(); |
| 412 } | 413 } |
| 413 | 414 |
| 414 ManagedUserSettingsService* ManagedUserService::GetSettingsService() { | 415 SupervisedUserSettingsService* SupervisedUserService::GetSettingsService() { |
| 415 return ManagedUserSettingsServiceFactory::GetForProfile(profile_); | 416 return SupervisedUserSettingsServiceFactory::GetForProfile(profile_); |
| 416 } | 417 } |
| 417 | 418 |
| 418 void ManagedUserService::OnManagedUserIdChanged() { | 419 void SupervisedUserService::OnSupervisedUserIdChanged() { |
| 419 std::string managed_user_id = | 420 std::string supervised_user_id = |
| 420 profile_->GetPrefs()->GetString(prefs::kSupervisedUserId); | 421 profile_->GetPrefs()->GetString(prefs::kSupervisedUserId); |
| 421 SetActive(!managed_user_id.empty()); | 422 SetActive(!supervised_user_id.empty()); |
| 422 } | 423 } |
| 423 | 424 |
| 424 void ManagedUserService::OnDefaultFilteringBehaviorChanged() { | 425 void SupervisedUserService::OnDefaultFilteringBehaviorChanged() { |
| 425 DCHECK(ProfileIsManaged()); | 426 DCHECK(ProfileIsSupervised()); |
| 426 | 427 |
| 427 int behavior_value = profile_->GetPrefs()->GetInteger( | 428 int behavior_value = profile_->GetPrefs()->GetInteger( |
| 428 prefs::kDefaultSupervisedUserFilteringBehavior); | 429 prefs::kDefaultSupervisedUserFilteringBehavior); |
| 429 ManagedModeURLFilter::FilteringBehavior behavior = | 430 SupervisedUserURLFilter::FilteringBehavior behavior = |
| 430 ManagedModeURLFilter::BehaviorFromInt(behavior_value); | 431 SupervisedUserURLFilter::BehaviorFromInt(behavior_value); |
| 431 url_filter_context_.SetDefaultFilteringBehavior(behavior); | 432 url_filter_context_.SetDefaultFilteringBehavior(behavior); |
| 432 } | 433 } |
| 433 | 434 |
| 434 void ManagedUserService::UpdateSiteLists() { | 435 void SupervisedUserService::UpdateSiteLists() { |
| 435 url_filter_context_.LoadWhitelists(GetActiveSiteLists()); | 436 url_filter_context_.LoadWhitelists(GetActiveSiteLists()); |
| 436 } | 437 } |
| 437 | 438 |
| 438 bool ManagedUserService::AccessRequestsEnabled() { | 439 bool SupervisedUserService::AccessRequestsEnabled() { |
| 439 if (waiting_for_permissions_) | 440 if (waiting_for_permissions_) |
| 440 return false; | 441 return false; |
| 441 | 442 |
| 442 ProfileSyncService* service = | 443 ProfileSyncService* service = |
| 443 ProfileSyncServiceFactory::GetForProfile(profile_); | 444 ProfileSyncServiceFactory::GetForProfile(profile_); |
| 444 GoogleServiceAuthError::State state = service->GetAuthError().state(); | 445 GoogleServiceAuthError::State state = service->GetAuthError().state(); |
| 445 // We allow requesting access if Sync is working or has a transient error. | 446 // We allow requesting access if Sync is working or has a transient error. |
| 446 return (state == GoogleServiceAuthError::NONE || | 447 return (state == GoogleServiceAuthError::NONE || |
| 447 state == GoogleServiceAuthError::CONNECTION_FAILED || | 448 state == GoogleServiceAuthError::CONNECTION_FAILED || |
| 448 state == GoogleServiceAuthError::SERVICE_UNAVAILABLE); | 449 state == GoogleServiceAuthError::SERVICE_UNAVAILABLE); |
| 449 } | 450 } |
| 450 | 451 |
| 451 void ManagedUserService::OnPermissionRequestIssued() { | 452 void SupervisedUserService::OnPermissionRequestIssued() { |
| 452 waiting_for_permissions_ = false; | 453 waiting_for_permissions_ = false; |
| 453 // TODO(akuegel): Figure out how to show the result of issuing the permission | 454 // TODO(akuegel): Figure out how to show the result of issuing the permission |
| 454 // request in the UI. Currently, we assume the permission request was created | 455 // request in the UI. Currently, we assume the permission request was created |
| 455 // successfully. | 456 // successfully. |
| 456 } | 457 } |
| 457 | 458 |
| 458 void ManagedUserService::AddAccessRequest(const GURL& url) { | 459 void SupervisedUserService::AddAccessRequest(const GURL& url) { |
| 459 // Normalize the URL. | 460 // Normalize the URL. |
| 460 GURL normalized_url = ManagedModeURLFilter::Normalize(url); | 461 GURL normalized_url = SupervisedUserURLFilter::Normalize(url); |
| 461 | 462 |
| 462 // Escape the URL. | 463 // Escape the URL. |
| 463 std::string output(net::EscapeQueryParamValue(normalized_url.spec(), true)); | 464 std::string output(net::EscapeQueryParamValue(normalized_url.spec(), true)); |
| 464 | 465 |
| 465 waiting_for_permissions_ = true; | 466 waiting_for_permissions_ = true; |
| 466 permissions_creator_->CreatePermissionRequest( | 467 permissions_creator_->CreatePermissionRequest( |
| 467 output, | 468 output, |
| 468 base::Bind(&ManagedUserService::OnPermissionRequestIssued, | 469 base::Bind(&SupervisedUserService::OnPermissionRequestIssued, |
| 469 weak_ptr_factory_.GetWeakPtr())); | 470 weak_ptr_factory_.GetWeakPtr())); |
| 470 } | 471 } |
| 471 | 472 |
| 472 ManagedUserService::ManualBehavior ManagedUserService::GetManualBehaviorForHost( | 473 SupervisedUserService::ManualBehavior |
| 474 SupervisedUserService::GetManualBehaviorForHost( |
| 473 const std::string& hostname) { | 475 const std::string& hostname) { |
| 474 const base::DictionaryValue* dict = | 476 const base::DictionaryValue* dict = |
| 475 profile_->GetPrefs()->GetDictionary(prefs::kSupervisedUserManualHosts); | 477 profile_->GetPrefs()->GetDictionary(prefs::kSupervisedUserManualHosts); |
| 476 bool allow = false; | 478 bool allow = false; |
| 477 if (!dict->GetBooleanWithoutPathExpansion(hostname, &allow)) | 479 if (!dict->GetBooleanWithoutPathExpansion(hostname, &allow)) |
| 478 return MANUAL_NONE; | 480 return MANUAL_NONE; |
| 479 | 481 |
| 480 return allow ? MANUAL_ALLOW : MANUAL_BLOCK; | 482 return allow ? MANUAL_ALLOW : MANUAL_BLOCK; |
| 481 } | 483 } |
| 482 | 484 |
| 483 ManagedUserService::ManualBehavior ManagedUserService::GetManualBehaviorForURL( | 485 SupervisedUserService::ManualBehavior |
| 486 SupervisedUserService::GetManualBehaviorForURL( |
| 484 const GURL& url) { | 487 const GURL& url) { |
| 485 const base::DictionaryValue* dict = | 488 const base::DictionaryValue* dict = |
| 486 profile_->GetPrefs()->GetDictionary(prefs::kSupervisedUserManualURLs); | 489 profile_->GetPrefs()->GetDictionary(prefs::kSupervisedUserManualURLs); |
| 487 GURL normalized_url = ManagedModeURLFilter::Normalize(url); | 490 GURL normalized_url = SupervisedUserURLFilter::Normalize(url); |
| 488 bool allow = false; | 491 bool allow = false; |
| 489 if (!dict->GetBooleanWithoutPathExpansion(normalized_url.spec(), &allow)) | 492 if (!dict->GetBooleanWithoutPathExpansion(normalized_url.spec(), &allow)) |
| 490 return MANUAL_NONE; | 493 return MANUAL_NONE; |
| 491 | 494 |
| 492 return allow ? MANUAL_ALLOW : MANUAL_BLOCK; | 495 return allow ? MANUAL_ALLOW : MANUAL_BLOCK; |
| 493 } | 496 } |
| 494 | 497 |
| 495 void ManagedUserService::GetManualExceptionsForHost(const std::string& host, | 498 void SupervisedUserService::GetManualExceptionsForHost( |
| 496 std::vector<GURL>* urls) { | 499 const std::string& host, |
| 500 std::vector<GURL>* urls) { |
| 497 const base::DictionaryValue* dict = | 501 const base::DictionaryValue* dict = |
| 498 profile_->GetPrefs()->GetDictionary(prefs::kSupervisedUserManualURLs); | 502 profile_->GetPrefs()->GetDictionary(prefs::kSupervisedUserManualURLs); |
| 499 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { | 503 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { |
| 500 GURL url(it.key()); | 504 GURL url(it.key()); |
| 501 if (url.host() == host) | 505 if (url.host() == host) |
| 502 urls->push_back(url); | 506 urls->push_back(url); |
| 503 } | 507 } |
| 504 } | 508 } |
| 505 | 509 |
| 506 void ManagedUserService::InitSync(const std::string& refresh_token) { | 510 void SupervisedUserService::InitSync(const std::string& refresh_token) { |
| 507 ProfileSyncService* service = | 511 ProfileSyncService* service = |
| 508 ProfileSyncServiceFactory::GetForProfile(profile_); | 512 ProfileSyncServiceFactory::GetForProfile(profile_); |
| 509 // Tell the sync service that setup is in progress so we don't start syncing | 513 // Tell the sync service that setup is in progress so we don't start syncing |
| 510 // until we've finished configuration. | 514 // until we've finished configuration. |
| 511 service->SetSetupInProgress(true); | 515 service->SetSetupInProgress(true); |
| 512 | 516 |
| 513 ProfileOAuth2TokenService* token_service = | 517 ProfileOAuth2TokenService* token_service = |
| 514 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); | 518 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); |
| 515 token_service->UpdateCredentials(managed_users::kManagedUserPseudoEmail, | 519 token_service->UpdateCredentials(supervised_users::kSupervisedUserPseudoEmail, |
| 516 refresh_token); | 520 refresh_token); |
| 517 | 521 |
| 518 // Continue in SetupSync() once the Sync backend has been initialized. | 522 // Continue in SetupSync() once the Sync backend has been initialized. |
| 519 if (service->sync_initialized()) { | 523 if (service->sync_initialized()) { |
| 520 SetupSync(); | 524 SetupSync(); |
| 521 } else { | 525 } else { |
| 522 ProfileSyncServiceFactory::GetForProfile(profile_)->AddObserver(this); | 526 ProfileSyncServiceFactory::GetForProfile(profile_)->AddObserver(this); |
| 523 waiting_for_sync_initialization_ = true; | 527 waiting_for_sync_initialization_ = true; |
| 524 } | 528 } |
| 525 } | 529 } |
| 526 | 530 |
| 527 void ManagedUserService::Init() { | 531 void SupervisedUserService::Init() { |
| 528 DCHECK(GetSettingsService()->IsReady()); | 532 DCHECK(GetSettingsService()->IsReady()); |
| 529 | 533 |
| 530 pref_change_registrar_.Init(profile_->GetPrefs()); | 534 pref_change_registrar_.Init(profile_->GetPrefs()); |
| 531 pref_change_registrar_.Add( | 535 pref_change_registrar_.Add( |
| 532 prefs::kSupervisedUserId, | 536 prefs::kSupervisedUserId, |
| 533 base::Bind(&ManagedUserService::OnManagedUserIdChanged, | 537 base::Bind(&SupervisedUserService::OnSupervisedUserIdChanged, |
| 534 base::Unretained(this))); | 538 base::Unretained(this))); |
| 535 | 539 |
| 536 SetActive(ProfileIsManaged()); | 540 SetActive(ProfileIsSupervised()); |
| 537 } | 541 } |
| 538 | 542 |
| 539 void ManagedUserService::SetActive(bool active) { | 543 void SupervisedUserService::SetActive(bool active) { |
| 540 if (active_ == active) | 544 if (active_ == active) |
| 541 return; | 545 return; |
| 542 active_ = active; | 546 active_ = active; |
| 543 | 547 |
| 544 if (!delegate_ || !delegate_->SetActive(active_)) { | 548 if (!delegate_ || !delegate_->SetActive(active_)) { |
| 545 if (active_) { | 549 if (active_) { |
| 546 SupervisedUserPrefMappingServiceFactory::GetForBrowserContext(profile_) | 550 SupervisedUserPrefMappingServiceFactory::GetForBrowserContext(profile_) |
| 547 ->Init(); | 551 ->Init(); |
| 548 | 552 |
| 549 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 553 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 550 if (command_line->HasSwitch(switches::kSupervisedUserSyncToken)) { | 554 if (command_line->HasSwitch(switches::kSupervisedUserSyncToken)) { |
| 551 InitSync( | 555 InitSync( |
| 552 command_line->GetSwitchValueASCII( | 556 command_line->GetSwitchValueASCII( |
| 553 switches::kSupervisedUserSyncToken)); | 557 switches::kSupervisedUserSyncToken)); |
| 554 } | 558 } |
| 555 | 559 |
| 556 ProfileOAuth2TokenService* token_service = | 560 ProfileOAuth2TokenService* token_service = |
| 557 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); | 561 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); |
| 558 token_service->LoadCredentials(managed_users::kManagedUserPseudoEmail); | 562 token_service->LoadCredentials( |
| 563 supervised_users::kSupervisedUserPseudoEmail); |
| 559 } | 564 } |
| 560 } | 565 } |
| 561 | 566 |
| 562 // Now activate/deactivate anything not handled by the delegate yet. | 567 // Now activate/deactivate anything not handled by the delegate yet. |
| 563 | 568 |
| 564 #if defined(ENABLE_THEMES) | 569 #if defined(ENABLE_THEMES) |
| 565 // Re-set the default theme to turn the SU theme on/off. | 570 // Re-set the default theme to turn the SU theme on/off. |
| 566 ThemeService* theme_service = ThemeServiceFactory::GetForProfile(profile_); | 571 ThemeService* theme_service = ThemeServiceFactory::GetForProfile(profile_); |
| 567 if (theme_service->UsingDefaultTheme() || theme_service->UsingSystemTheme()) { | 572 if (theme_service->UsingDefaultTheme() || theme_service->UsingSystemTheme()) { |
| 568 ThemeServiceFactory::GetForProfile(profile_)->UseDefaultTheme(); | 573 ThemeServiceFactory::GetForProfile(profile_)->UseDefaultTheme(); |
| 569 } | 574 } |
| 570 #endif | 575 #endif |
| 571 | 576 |
| 572 ManagedUserSettingsService* settings_service = GetSettingsService(); | 577 SupervisedUserSettingsService* settings_service = GetSettingsService(); |
| 573 settings_service->SetActive(active_); | 578 settings_service->SetActive(active_); |
| 574 | 579 |
| 575 extensions::ExtensionSystem* extension_system = | 580 extensions::ExtensionSystem* extension_system = |
| 576 extensions::ExtensionSystem::Get(profile_); | 581 extensions::ExtensionSystem::Get(profile_); |
| 577 extensions::ManagementPolicy* management_policy = | 582 extensions::ManagementPolicy* management_policy = |
| 578 extension_system->management_policy(); | 583 extension_system->management_policy(); |
| 579 | 584 |
| 580 if (active_) { | 585 if (active_) { |
| 581 if (CommandLine::ForCurrentProcess()->HasSwitch( | 586 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 582 switches::kPermissionRequestApiUrl)) { | 587 switches::kPermissionRequestApiUrl)) { |
| 583 permissions_creator_ = | 588 permissions_creator_ = |
| 584 PermissionRequestCreatorApiary::CreateWithProfile(profile_); | 589 PermissionRequestCreatorApiary::CreateWithProfile(profile_); |
| 585 } else { | 590 } else { |
| 586 PrefService* pref_service = profile_->GetPrefs(); | 591 PrefService* pref_service = profile_->GetPrefs(); |
| 587 permissions_creator_.reset(new PermissionRequestCreatorSync( | 592 permissions_creator_.reset(new PermissionRequestCreatorSync( |
| 588 settings_service, | 593 settings_service, |
| 589 ManagedUserSharedSettingsServiceFactory::GetForBrowserContext( | 594 SupervisedUserSharedSettingsServiceFactory::GetForBrowserContext( |
| 590 profile_), | 595 profile_), |
| 591 pref_service->GetString(prefs::kProfileName), | 596 pref_service->GetString(prefs::kProfileName), |
| 592 pref_service->GetString(prefs::kSupervisedUserId))); | 597 pref_service->GetString(prefs::kSupervisedUserId))); |
| 593 } | 598 } |
| 594 | 599 |
| 595 if (management_policy) | 600 if (management_policy) |
| 596 management_policy->RegisterProvider(this); | 601 management_policy->RegisterProvider(this); |
| 597 | 602 |
| 598 extension_registry_observer_.Add( | 603 extension_registry_observer_.Add( |
| 599 extensions::ExtensionRegistry::Get(profile_)); | 604 extensions::ExtensionRegistry::Get(profile_)); |
| 600 | 605 |
| 601 pref_change_registrar_.Add( | 606 pref_change_registrar_.Add( |
| 602 prefs::kDefaultSupervisedUserFilteringBehavior, | 607 prefs::kDefaultSupervisedUserFilteringBehavior, |
| 603 base::Bind(&ManagedUserService::OnDefaultFilteringBehaviorChanged, | 608 base::Bind(&SupervisedUserService::OnDefaultFilteringBehaviorChanged, |
| 604 base::Unretained(this))); | 609 base::Unretained(this))); |
| 605 pref_change_registrar_.Add(prefs::kSupervisedUserManualHosts, | 610 pref_change_registrar_.Add(prefs::kSupervisedUserManualHosts, |
| 606 base::Bind(&ManagedUserService::UpdateManualHosts, | 611 base::Bind(&SupervisedUserService::UpdateManualHosts, |
| 607 base::Unretained(this))); | 612 base::Unretained(this))); |
| 608 pref_change_registrar_.Add(prefs::kSupervisedUserManualURLs, | 613 pref_change_registrar_.Add(prefs::kSupervisedUserManualURLs, |
| 609 base::Bind(&ManagedUserService::UpdateManualURLs, | 614 base::Bind(&SupervisedUserService::UpdateManualURLs, |
| 610 base::Unretained(this))); | 615 base::Unretained(this))); |
| 611 | 616 |
| 612 // Initialize the filter. | 617 // Initialize the filter. |
| 613 OnDefaultFilteringBehaviorChanged(); | 618 OnDefaultFilteringBehaviorChanged(); |
| 614 UpdateSiteLists(); | 619 UpdateSiteLists(); |
| 615 UpdateManualHosts(); | 620 UpdateManualHosts(); |
| 616 UpdateManualURLs(); | 621 UpdateManualURLs(); |
| 617 | 622 |
| 618 #if !defined(OS_ANDROID) | 623 #if !defined(OS_ANDROID) |
| 619 // TODO(bauerb): Get rid of the platform-specific #ifdef here. | 624 // TODO(bauerb): Get rid of the platform-specific #ifdef here. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 640 } | 645 } |
| 641 | 646 |
| 642 #if !defined(OS_ANDROID) | 647 #if !defined(OS_ANDROID) |
| 643 // TODO(bauerb): Get rid of the platform-specific #ifdef here. | 648 // TODO(bauerb): Get rid of the platform-specific #ifdef here. |
| 644 // http://crbug.com/313377 | 649 // http://crbug.com/313377 |
| 645 BrowserList::RemoveObserver(this); | 650 BrowserList::RemoveObserver(this); |
| 646 #endif | 651 #endif |
| 647 } | 652 } |
| 648 } | 653 } |
| 649 | 654 |
| 650 void ManagedUserService::RegisterAndInitSync( | 655 void SupervisedUserService::RegisterAndInitSync( |
| 651 ManagedUserRegistrationUtility* registration_utility, | 656 SupervisedUserRegistrationUtility* registration_utility, |
| 652 Profile* custodian_profile, | 657 Profile* custodian_profile, |
| 653 const std::string& managed_user_id, | 658 const std::string& supervised_user_id, |
| 654 const AuthErrorCallback& callback) { | 659 const AuthErrorCallback& callback) { |
| 655 DCHECK(ProfileIsManaged()); | 660 DCHECK(ProfileIsSupervised()); |
| 656 DCHECK(!custodian_profile->IsSupervised()); | 661 DCHECK(!custodian_profile->IsSupervised()); |
| 657 | 662 |
| 658 base::string16 name = base::UTF8ToUTF16( | 663 base::string16 name = base::UTF8ToUTF16( |
| 659 profile_->GetPrefs()->GetString(prefs::kProfileName)); | 664 profile_->GetPrefs()->GetString(prefs::kProfileName)); |
| 660 int avatar_index = profile_->GetPrefs()->GetInteger( | 665 int avatar_index = profile_->GetPrefs()->GetInteger( |
| 661 prefs::kProfileAvatarIndex); | 666 prefs::kProfileAvatarIndex); |
| 662 ManagedUserRegistrationInfo info(name, avatar_index); | 667 SupervisedUserRegistrationInfo info(name, avatar_index); |
| 663 registration_utility->Register( | 668 registration_utility->Register( |
| 664 managed_user_id, | 669 supervised_user_id, |
| 665 info, | 670 info, |
| 666 base::Bind(&ManagedUserService::OnManagedUserRegistered, | 671 base::Bind(&SupervisedUserService::OnSupervisedUserRegistered, |
| 667 weak_ptr_factory_.GetWeakPtr(), callback, custodian_profile)); | 672 weak_ptr_factory_.GetWeakPtr(), callback, custodian_profile)); |
| 668 | 673 |
| 669 // Fetch the custodian's profile information, to store the name. | 674 // Fetch the custodian's profile information, to store the name. |
| 670 // TODO(pamg): If --google-profile-info (flag: switches::kGoogleProfileInfo) | 675 // TODO(pamg): If --google-profile-info (flag: switches::kGoogleProfileInfo) |
| 671 // is ever enabled, take the name from the ProfileInfoCache instead. | 676 // is ever enabled, take the name from the ProfileInfoCache instead. |
| 672 CustodianProfileDownloaderService* profile_downloader_service = | 677 CustodianProfileDownloaderService* profile_downloader_service = |
| 673 CustodianProfileDownloaderServiceFactory::GetForProfile( | 678 CustodianProfileDownloaderServiceFactory::GetForProfile( |
| 674 custodian_profile); | 679 custodian_profile); |
| 675 profile_downloader_service->DownloadProfile( | 680 profile_downloader_service->DownloadProfile( |
| 676 base::Bind(&ManagedUserService::OnCustodianProfileDownloaded, | 681 base::Bind(&SupervisedUserService::OnCustodianProfileDownloaded, |
| 677 weak_ptr_factory_.GetWeakPtr())); | 682 weak_ptr_factory_.GetWeakPtr())); |
| 678 } | 683 } |
| 679 | 684 |
| 680 void ManagedUserService::OnCustodianProfileDownloaded( | 685 void SupervisedUserService::OnCustodianProfileDownloaded( |
| 681 const base::string16& full_name) { | 686 const base::string16& full_name) { |
| 682 profile_->GetPrefs()->SetString(prefs::kSupervisedUserCustodianName, | 687 profile_->GetPrefs()->SetString(prefs::kSupervisedUserCustodianName, |
| 683 base::UTF16ToUTF8(full_name)); | 688 base::UTF16ToUTF8(full_name)); |
| 684 } | 689 } |
| 685 | 690 |
| 686 void ManagedUserService::OnManagedUserRegistered( | 691 void SupervisedUserService::OnSupervisedUserRegistered( |
| 687 const AuthErrorCallback& callback, | 692 const AuthErrorCallback& callback, |
| 688 Profile* custodian_profile, | 693 Profile* custodian_profile, |
| 689 const GoogleServiceAuthError& auth_error, | 694 const GoogleServiceAuthError& auth_error, |
| 690 const std::string& token) { | 695 const std::string& token) { |
| 691 if (auth_error.state() == GoogleServiceAuthError::NONE) { | 696 if (auth_error.state() == GoogleServiceAuthError::NONE) { |
| 692 InitSync(token); | 697 InitSync(token); |
| 693 SigninManagerBase* signin = | 698 SigninManagerBase* signin = |
| 694 SigninManagerFactory::GetForProfile(custodian_profile); | 699 SigninManagerFactory::GetForProfile(custodian_profile); |
| 695 profile_->GetPrefs()->SetString(prefs::kSupervisedUserCustodianEmail, | 700 profile_->GetPrefs()->SetString(prefs::kSupervisedUserCustodianEmail, |
| 696 signin->GetAuthenticatedUsername()); | 701 signin->GetAuthenticatedUsername()); |
| 697 | 702 |
| 698 // The managed-user profile is now ready for use. | 703 // The supervised user profile is now ready for use. |
| 699 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 704 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 700 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 705 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); |
| 701 size_t index = cache.GetIndexOfProfileWithPath(profile_->GetPath()); | 706 size_t index = cache.GetIndexOfProfileWithPath(profile_->GetPath()); |
| 702 cache.SetIsOmittedProfileAtIndex(index, false); | 707 cache.SetIsOmittedProfileAtIndex(index, false); |
| 703 } else { | 708 } else { |
| 704 DCHECK_EQ(std::string(), token); | 709 DCHECK_EQ(std::string(), token); |
| 705 } | 710 } |
| 706 | 711 |
| 707 callback.Run(auth_error); | 712 callback.Run(auth_error); |
| 708 } | 713 } |
| 709 | 714 |
| 710 void ManagedUserService::UpdateManualHosts() { | 715 void SupervisedUserService::UpdateManualHosts() { |
| 711 const base::DictionaryValue* dict = | 716 const base::DictionaryValue* dict = |
| 712 profile_->GetPrefs()->GetDictionary(prefs::kSupervisedUserManualHosts); | 717 profile_->GetPrefs()->GetDictionary(prefs::kSupervisedUserManualHosts); |
| 713 scoped_ptr<std::map<std::string, bool> > host_map( | 718 scoped_ptr<std::map<std::string, bool> > host_map( |
| 714 new std::map<std::string, bool>()); | 719 new std::map<std::string, bool>()); |
| 715 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { | 720 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { |
| 716 bool allow = false; | 721 bool allow = false; |
| 717 bool result = it.value().GetAsBoolean(&allow); | 722 bool result = it.value().GetAsBoolean(&allow); |
| 718 DCHECK(result); | 723 DCHECK(result); |
| 719 (*host_map)[it.key()] = allow; | 724 (*host_map)[it.key()] = allow; |
| 720 } | 725 } |
| 721 url_filter_context_.SetManualHosts(host_map.Pass()); | 726 url_filter_context_.SetManualHosts(host_map.Pass()); |
| 722 } | 727 } |
| 723 | 728 |
| 724 void ManagedUserService::UpdateManualURLs() { | 729 void SupervisedUserService::UpdateManualURLs() { |
| 725 const base::DictionaryValue* dict = | 730 const base::DictionaryValue* dict = |
| 726 profile_->GetPrefs()->GetDictionary(prefs::kSupervisedUserManualURLs); | 731 profile_->GetPrefs()->GetDictionary(prefs::kSupervisedUserManualURLs); |
| 727 scoped_ptr<std::map<GURL, bool> > url_map(new std::map<GURL, bool>()); | 732 scoped_ptr<std::map<GURL, bool> > url_map(new std::map<GURL, bool>()); |
| 728 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { | 733 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { |
| 729 bool allow = false; | 734 bool allow = false; |
| 730 bool result = it.value().GetAsBoolean(&allow); | 735 bool result = it.value().GetAsBoolean(&allow); |
| 731 DCHECK(result); | 736 DCHECK(result); |
| 732 (*url_map)[GURL(it.key())] = allow; | 737 (*url_map)[GURL(it.key())] = allow; |
| 733 } | 738 } |
| 734 url_filter_context_.SetManualURLs(url_map.Pass()); | 739 url_filter_context_.SetManualURLs(url_map.Pass()); |
| 735 } | 740 } |
| 736 | 741 |
| 737 void ManagedUserService::OnBrowserSetLastActive(Browser* browser) { | 742 void SupervisedUserService::OnBrowserSetLastActive(Browser* browser) { |
| 738 bool profile_became_active = profile_->IsSameProfile(browser->profile()); | 743 bool profile_became_active = profile_->IsSameProfile(browser->profile()); |
| 739 if (!is_profile_active_ && profile_became_active) | 744 if (!is_profile_active_ && profile_became_active) |
| 740 content::RecordAction(UserMetricsAction("ManagedUsers_OpenProfile")); | 745 content::RecordAction(UserMetricsAction("ManagedUsers_OpenProfile")); |
| 741 else if (is_profile_active_ && !profile_became_active) | 746 else if (is_profile_active_ && !profile_became_active) |
| 742 content::RecordAction(UserMetricsAction("ManagedUsers_SwitchProfile")); | 747 content::RecordAction(UserMetricsAction("ManagedUsers_SwitchProfile")); |
| 743 | 748 |
| 744 is_profile_active_ = profile_became_active; | 749 is_profile_active_ = profile_became_active; |
| 745 } | 750 } |
| OLD | NEW |