Chromium Code Reviews| 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/managed_mode/managed_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/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
| 14 #include "chrome/browser/extensions/extension_service.h" | 14 #include "chrome/browser/extensions/extension_service.h" |
| 15 #include "chrome/browser/managed_mode/custodian_profile_downloader_service.h" | 15 #include "chrome/browser/managed_mode/custodian_profile_downloader_service.h" |
| 16 #include "chrome/browser/managed_mode/custodian_profile_downloader_service_facto ry.h" | 16 #include "chrome/browser/managed_mode/custodian_profile_downloader_service_facto ry.h" |
| 17 #include "chrome/browser/managed_mode/managed_mode_site_list.h" | 17 #include "chrome/browser/managed_mode/managed_mode_site_list.h" |
| 18 #include "chrome/browser/managed_mode/managed_user_constants.h" | 18 #include "chrome/browser/managed_mode/managed_user_constants.h" |
| 19 #include "chrome/browser/managed_mode/managed_user_registration_utility.h" | 19 #include "chrome/browser/managed_mode/managed_user_registration_utility.h" |
| 20 #include "chrome/browser/managed_mode/managed_user_settings_service.h" | 20 #include "chrome/browser/managed_mode/managed_user_settings_service.h" |
| 21 #include "chrome/browser/managed_mode/managed_user_settings_service_factory.h" | 21 #include "chrome/browser/managed_mode/managed_user_settings_service_factory.h" |
| 22 #include "chrome/browser/managed_mode/managed_user_shared_settings_service.h" | 22 #include "chrome/browser/managed_mode/managed_user_shared_settings_service.h" |
| 23 #include "chrome/browser/managed_mode/managed_user_shared_settings_service_facto ry.h" | 23 #include "chrome/browser/managed_mode/managed_user_shared_settings_service_facto ry.h" |
| 24 #include "chrome/browser/managed_mode/managed_user_sync_service.h" | 24 #include "chrome/browser/managed_mode/managed_user_sync_service.h" |
| 25 #include "chrome/browser/managed_mode/managed_user_sync_service_factory.h" | 25 #include "chrome/browser/managed_mode/managed_user_sync_service_factory.h" |
| 26 #include "chrome/browser/managed_mode/permission_request_creator.h" | |
| 26 #include "chrome/browser/managed_mode/supervised_user_pref_mapping_service.h" | 27 #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/managed_mode/supervised_user_pref_mapping_service_facto ry.h" |
| 28 #include "chrome/browser/profiles/profile.h" | 29 #include "chrome/browser/profiles/profile.h" |
| 29 #include "chrome/browser/profiles/profile_info_cache.h" | 30 #include "chrome/browser/profiles/profile_info_cache.h" |
| 30 #include "chrome/browser/profiles/profile_manager.h" | 31 #include "chrome/browser/profiles/profile_manager.h" |
| 31 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 32 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 32 #include "chrome/browser/signin/signin_manager_factory.h" | 33 #include "chrome/browser/signin/signin_manager_factory.h" |
| 33 #include "chrome/browser/sync/profile_sync_service.h" | 34 #include "chrome/browser/sync/profile_sync_service.h" |
| 34 #include "chrome/browser/sync/profile_sync_service_factory.h" | 35 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 35 #include "chrome/browser/ui/browser.h" | 36 #include "chrome/browser/ui/browser.h" |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 133 base::Bind(&ManagedModeURLFilter::SetManualURLs, | 134 base::Bind(&ManagedModeURLFilter::SetManualURLs, |
| 134 io_url_filter_, base::Owned(url_map.release()))); | 135 io_url_filter_, base::Owned(url_map.release()))); |
| 135 } | 136 } |
| 136 | 137 |
| 137 ManagedUserService::ManagedUserService(Profile* profile) | 138 ManagedUserService::ManagedUserService(Profile* profile) |
| 138 : profile_(profile), | 139 : profile_(profile), |
| 139 waiting_for_sync_initialization_(false), | 140 waiting_for_sync_initialization_(false), |
| 140 is_profile_active_(false), | 141 is_profile_active_(false), |
| 141 elevated_for_testing_(false), | 142 elevated_for_testing_(false), |
| 142 did_shutdown_(false), | 143 did_shutdown_(false), |
| 144 waiting_for_permissions_(false), | |
| 143 weak_ptr_factory_(this) { | 145 weak_ptr_factory_(this) { |
| 144 } | 146 } |
| 145 | 147 |
| 146 ManagedUserService::~ManagedUserService() { | 148 ManagedUserService::~ManagedUserService() { |
| 147 DCHECK(did_shutdown_); | 149 DCHECK(did_shutdown_); |
| 148 } | 150 } |
| 149 | 151 |
| 150 void ManagedUserService::Shutdown() { | 152 void ManagedUserService::Shutdown() { |
| 151 did_shutdown_ = true; | 153 did_shutdown_ = true; |
| 152 if (ProfileIsManaged()) { | 154 if (ProfileIsManaged()) { |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 437 ManagedModeURLFilter::FilteringBehavior behavior = | 439 ManagedModeURLFilter::FilteringBehavior behavior = |
| 438 ManagedModeURLFilter::BehaviorFromInt(behavior_value); | 440 ManagedModeURLFilter::BehaviorFromInt(behavior_value); |
| 439 url_filter_context_.SetDefaultFilteringBehavior(behavior); | 441 url_filter_context_.SetDefaultFilteringBehavior(behavior); |
| 440 } | 442 } |
| 441 | 443 |
| 442 void ManagedUserService::UpdateSiteLists() { | 444 void ManagedUserService::UpdateSiteLists() { |
| 443 url_filter_context_.LoadWhitelists(GetActiveSiteLists()); | 445 url_filter_context_.LoadWhitelists(GetActiveSiteLists()); |
| 444 } | 446 } |
| 445 | 447 |
| 446 bool ManagedUserService::AccessRequestsEnabled() { | 448 bool ManagedUserService::AccessRequestsEnabled() { |
| 449 if (waiting_for_permissions_) { | |
| 450 return false; | |
| 451 } | |
| 452 | |
| 447 ProfileSyncService* service = | 453 ProfileSyncService* service = |
| 448 ProfileSyncServiceFactory::GetForProfile(profile_); | 454 ProfileSyncServiceFactory::GetForProfile(profile_); |
| 449 GoogleServiceAuthError::State state = service->GetAuthError().state(); | 455 GoogleServiceAuthError::State state = service->GetAuthError().state(); |
| 450 // We allow requesting access if Sync is working or has a transient error. | 456 // We allow requesting access if Sync is working or has a transient error. |
| 451 return (state == GoogleServiceAuthError::NONE || | 457 return (state == GoogleServiceAuthError::NONE || |
| 452 state == GoogleServiceAuthError::CONNECTION_FAILED || | 458 state == GoogleServiceAuthError::CONNECTION_FAILED || |
| 453 state == GoogleServiceAuthError::SERVICE_UNAVAILABLE); | 459 state == GoogleServiceAuthError::SERVICE_UNAVAILABLE); |
| 454 } | 460 } |
| 455 | 461 |
| 462 void ManagedUserService::OnPermissionRequestIssued( | |
| 463 const GoogleServiceAuthError& error) { | |
| 464 waiting_for_permissions_ = false; | |
| 465 // TODO(akuegel): Figure out how to show the result of issuing the permission | |
| 466 // in the UI. | |
| 467 } | |
| 468 | |
| 456 void ManagedUserService::AddAccessRequest(const GURL& url) { | 469 void ManagedUserService::AddAccessRequest(const GURL& url) { |
| 457 // Normalize the URL. | 470 // Normalize the URL. |
| 458 GURL normalized_url = ManagedModeURLFilter::Normalize(url); | 471 GURL normalized_url = ManagedModeURLFilter::Normalize(url); |
| 459 | 472 |
| 460 // Escape the URL. | 473 // Escape the URL. |
| 461 std::string output(net::EscapeQueryParamValue(normalized_url.spec(), true)); | 474 std::string output(net::EscapeQueryParamValue(normalized_url.spec(), true)); |
| 462 | 475 |
| 476 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
| 477 switches::kPermissionRequestAPI)) { | |
| 478 waiting_for_permissions_ = true; | |
| 479 permissions_creator_->CreatePermissionRequest( | |
| 480 output, | |
|
Bernhard Bauer
2014/05/15 13:56:40
Nit: Indent (4 spaces)
Adrian Kuegel
2014/05/15 14:35:32
Done.
| |
| 481 base::Bind(&ManagedUserService::OnPermissionRequestIssued, | |
| 482 weak_ptr_factory_.GetWeakPtr())); | |
| 483 return; | |
| 484 } | |
| 485 | |
| 463 // Add the prefix. | 486 // Add the prefix. |
| 464 std::string key = ManagedUserSettingsService::MakeSplitSettingKey( | 487 std::string key = ManagedUserSettingsService::MakeSplitSettingKey( |
| 465 kManagedUserAccessRequestKeyPrefix, output); | 488 kManagedUserAccessRequestKeyPrefix, output); |
| 466 | 489 |
| 467 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue); | 490 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue); |
| 468 | 491 |
| 469 // TODO(sergiu): Use sane time here when it's ready. | 492 // TODO(sergiu): Use sane time here when it's ready. |
| 470 dict->SetDouble(kManagedUserAccessRequestTime, base::Time::Now().ToJsTime()); | 493 dict->SetDouble(kManagedUserAccessRequestTime, base::Time::Now().ToJsTime()); |
| 471 | 494 |
| 472 dict->SetString(kManagedUserName, | 495 dict->SetString(kManagedUserName, |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 561 | 584 |
| 562 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 585 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 563 if (command_line->HasSwitch(switches::kManagedUserSyncToken)) { | 586 if (command_line->HasSwitch(switches::kManagedUserSyncToken)) { |
| 564 InitSync( | 587 InitSync( |
| 565 command_line->GetSwitchValueASCII(switches::kManagedUserSyncToken)); | 588 command_line->GetSwitchValueASCII(switches::kManagedUserSyncToken)); |
| 566 } | 589 } |
| 567 | 590 |
| 568 ProfileOAuth2TokenService* token_service = | 591 ProfileOAuth2TokenService* token_service = |
| 569 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); | 592 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); |
| 570 token_service->LoadCredentials(managed_users::kManagedUserPseudoEmail); | 593 token_service->LoadCredentials(managed_users::kManagedUserPseudoEmail); |
| 594 std::string account_id = SigninManagerFactory::GetForProfile(profile_) | |
| 595 ->GetAuthenticatedAccountId(); | |
|
Bernhard Bauer
2014/05/15 13:56:40
This is going to be empty for a supervised user (b
Adrian Kuegel
2014/05/15 14:35:32
Right. This explains why fetching the access token
Bernhard Bauer
2014/05/15 15:04:54
An alternative would be to use ManagedUserSigninMa
Adrian Kuegel
2014/05/15 15:42:16
Right. I refactored this a bit, and pass now only
Bernhard Bauer
2014/05/15 15:58:18
Passing only the profile to Create() is okay, but
Adrian Kuegel
2014/05/16 13:21:57
Makes sense. Done.
| |
| 596 permissions_creator_ = PermissionRequestCreator::Create( | |
| 597 token_service, account_id, profile_->GetRequestContext()); | |
| 571 | 598 |
| 572 extensions::ExtensionSystem* extension_system = | 599 extensions::ExtensionSystem* extension_system = |
| 573 extensions::ExtensionSystem::Get(profile_); | 600 extensions::ExtensionSystem::Get(profile_); |
| 574 extensions::ManagementPolicy* management_policy = | 601 extensions::ManagementPolicy* management_policy = |
| 575 extension_system->management_policy(); | 602 extension_system->management_policy(); |
| 576 if (management_policy) | 603 if (management_policy) |
| 577 extension_system->management_policy()->RegisterProvider(this); | 604 extension_system->management_policy()->RegisterProvider(this); |
| 578 | 605 |
| 579 registrar_.Add(this, | 606 registrar_.Add(this, |
| 580 chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, | 607 chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 696 | 723 |
| 697 void ManagedUserService::OnBrowserSetLastActive(Browser* browser) { | 724 void ManagedUserService::OnBrowserSetLastActive(Browser* browser) { |
| 698 bool profile_became_active = profile_->IsSameProfile(browser->profile()); | 725 bool profile_became_active = profile_->IsSameProfile(browser->profile()); |
| 699 if (!is_profile_active_ && profile_became_active) | 726 if (!is_profile_active_ && profile_became_active) |
| 700 content::RecordAction(UserMetricsAction("ManagedUsers_OpenProfile")); | 727 content::RecordAction(UserMetricsAction("ManagedUsers_OpenProfile")); |
| 701 else if (is_profile_active_ && !profile_became_active) | 728 else if (is_profile_active_ && !profile_became_active) |
| 702 content::RecordAction(UserMetricsAction("ManagedUsers_SwitchProfile")); | 729 content::RecordAction(UserMetricsAction("ManagedUsers_SwitchProfile")); |
| 703 | 730 |
| 704 is_profile_active_ = profile_became_active; | 731 is_profile_active_ = profile_became_active; |
| 705 } | 732 } |
| OLD | NEW |