Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(166)

Side by Side Diff: chrome/browser/managed_mode/managed_user_service.cc

Issue 288913003: Add permission request creator class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use base::Closure, and simplify things. Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
23 #include "chrome/browser/managed_mode/managed_user_shared_settings_service_facto ry.h" 22 #include "chrome/browser/managed_mode/managed_user_shared_settings_service_facto ry.h"
24 #include "chrome/browser/managed_mode/managed_user_sync_service.h" 23 #include "chrome/browser/managed_mode/managed_user_sync_service.h"
25 #include "chrome/browser/managed_mode/managed_user_sync_service_factory.h" 24 #include "chrome/browser/managed_mode/managed_user_sync_service_factory.h"
25 #include "chrome/browser/managed_mode/permission_request_creator_apiary.h"
26 #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.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 18 matching lines...) Expand all
54 55
55 #if defined(OS_CHROMEOS) 56 #if defined(OS_CHROMEOS)
56 #include "chrome/browser/chromeos/login/users/supervised_user_manager.h" 57 #include "chrome/browser/chromeos/login/users/supervised_user_manager.h"
57 #include "chrome/browser/chromeos/login/users/user_manager.h" 58 #include "chrome/browser/chromeos/login/users/user_manager.h"
58 #endif 59 #endif
59 60
60 using base::DictionaryValue; 61 using base::DictionaryValue;
61 using base::UserMetricsAction; 62 using base::UserMetricsAction;
62 using content::BrowserThread; 63 using content::BrowserThread;
63 64
64 const char kManagedUserAccessRequestKeyPrefix[] =
65 "X-ManagedUser-AccessRequests";
66 const char kManagedUserAccessRequestTime[] = "timestamp";
67 const char kManagedUserName[] = "name";
68
69 // Key for the notification setting of the custodian. This is a shared setting
70 // so we can include the setting in the access request data that is used to
71 // trigger notifications.
72 const char kNotificationSetting[] = "custodian-notification-setting";
73
74 ManagedUserService::URLFilterContext::URLFilterContext() 65 ManagedUserService::URLFilterContext::URLFilterContext()
75 : ui_url_filter_(new ManagedModeURLFilter), 66 : ui_url_filter_(new ManagedModeURLFilter),
76 io_url_filter_(new ManagedModeURLFilter) {} 67 io_url_filter_(new ManagedModeURLFilter) {}
77 ManagedUserService::URLFilterContext::~URLFilterContext() {} 68 ManagedUserService::URLFilterContext::~URLFilterContext() {}
78 69
79 ManagedModeURLFilter* 70 ManagedModeURLFilter*
80 ManagedUserService::URLFilterContext::ui_url_filter() const { 71 ManagedUserService::URLFilterContext::ui_url_filter() const {
81 return ui_url_filter_.get(); 72 return ui_url_filter_.get();
82 } 73 }
83 74
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 base::Bind(&ManagedModeURLFilter::SetManualURLs, 124 base::Bind(&ManagedModeURLFilter::SetManualURLs,
134 io_url_filter_, base::Owned(url_map.release()))); 125 io_url_filter_, base::Owned(url_map.release())));
135 } 126 }
136 127
137 ManagedUserService::ManagedUserService(Profile* profile) 128 ManagedUserService::ManagedUserService(Profile* profile)
138 : profile_(profile), 129 : profile_(profile),
139 waiting_for_sync_initialization_(false), 130 waiting_for_sync_initialization_(false),
140 is_profile_active_(false), 131 is_profile_active_(false),
141 elevated_for_testing_(false), 132 elevated_for_testing_(false),
142 did_shutdown_(false), 133 did_shutdown_(false),
134 waiting_for_permissions_(false),
143 weak_ptr_factory_(this) { 135 weak_ptr_factory_(this) {
144 } 136 }
145 137
146 ManagedUserService::~ManagedUserService() { 138 ManagedUserService::~ManagedUserService() {
147 DCHECK(did_shutdown_); 139 DCHECK(did_shutdown_);
148 } 140 }
149 141
150 void ManagedUserService::Shutdown() { 142 void ManagedUserService::Shutdown() {
151 did_shutdown_ = true; 143 did_shutdown_ = true;
152 if (ProfileIsManaged()) { 144 if (ProfileIsManaged()) {
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 ManagedModeURLFilter::FilteringBehavior behavior = 429 ManagedModeURLFilter::FilteringBehavior behavior =
438 ManagedModeURLFilter::BehaviorFromInt(behavior_value); 430 ManagedModeURLFilter::BehaviorFromInt(behavior_value);
439 url_filter_context_.SetDefaultFilteringBehavior(behavior); 431 url_filter_context_.SetDefaultFilteringBehavior(behavior);
440 } 432 }
441 433
442 void ManagedUserService::UpdateSiteLists() { 434 void ManagedUserService::UpdateSiteLists() {
443 url_filter_context_.LoadWhitelists(GetActiveSiteLists()); 435 url_filter_context_.LoadWhitelists(GetActiveSiteLists());
444 } 436 }
445 437
446 bool ManagedUserService::AccessRequestsEnabled() { 438 bool ManagedUserService::AccessRequestsEnabled() {
439 if (waiting_for_permissions_)
440 return false;
441
447 ProfileSyncService* service = 442 ProfileSyncService* service =
448 ProfileSyncServiceFactory::GetForProfile(profile_); 443 ProfileSyncServiceFactory::GetForProfile(profile_);
449 GoogleServiceAuthError::State state = service->GetAuthError().state(); 444 GoogleServiceAuthError::State state = service->GetAuthError().state();
450 // We allow requesting access if Sync is working or has a transient error. 445 // We allow requesting access if Sync is working or has a transient error.
451 return (state == GoogleServiceAuthError::NONE || 446 return (state == GoogleServiceAuthError::NONE ||
452 state == GoogleServiceAuthError::CONNECTION_FAILED || 447 state == GoogleServiceAuthError::CONNECTION_FAILED ||
453 state == GoogleServiceAuthError::SERVICE_UNAVAILABLE); 448 state == GoogleServiceAuthError::SERVICE_UNAVAILABLE);
454 } 449 }
455 450
451 void ManagedUserService::OnPermissionRequestIssued() {
452 waiting_for_permissions_ = false;
453 // 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 // successfully.
456 }
457
456 void ManagedUserService::AddAccessRequest(const GURL& url) { 458 void ManagedUserService::AddAccessRequest(const GURL& url) {
457 // Normalize the URL. 459 // Normalize the URL.
458 GURL normalized_url = ManagedModeURLFilter::Normalize(url); 460 GURL normalized_url = ManagedModeURLFilter::Normalize(url);
459 461
460 // Escape the URL. 462 // Escape the URL.
461 std::string output(net::EscapeQueryParamValue(normalized_url.spec(), true)); 463 std::string output(net::EscapeQueryParamValue(normalized_url.spec(), true));
462 464
463 // Add the prefix. 465 waiting_for_permissions_ = true;
464 std::string key = ManagedUserSettingsService::MakeSplitSettingKey( 466 permissions_creator_->CreatePermissionRequest(
465 kManagedUserAccessRequestKeyPrefix, output); 467 output,
466 468 base::Bind(&ManagedUserService::OnPermissionRequestIssued,
467 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue); 469 weak_ptr_factory_.GetWeakPtr()));
468
469 // TODO(sergiu): Use sane time here when it's ready.
470 dict->SetDouble(kManagedUserAccessRequestTime, base::Time::Now().ToJsTime());
471
472 dict->SetString(kManagedUserName,
473 profile_->GetPrefs()->GetString(prefs::kProfileName));
474
475 // Copy the notification setting of the custodian.
476 std::string managed_user_id =
477 profile_->GetPrefs()->GetString(prefs::kManagedUserId);
478 const base::Value* value =
479 ManagedUserSharedSettingsServiceFactory::GetForBrowserContext(profile_)
480 ->GetValue(managed_user_id, kNotificationSetting);
481 bool notifications_enabled = false;
482 if (CommandLine::ForCurrentProcess()->HasSwitch(
483 switches::kEnableAccessRequestNotifications)) {
484 notifications_enabled = true;
485 } else if (value) {
486 bool success = value->GetAsBoolean(&notifications_enabled);
487 DCHECK(success);
488 }
489 dict->SetBoolean(kNotificationSetting, notifications_enabled);
490
491 GetSettingsService()->UploadItem(key, dict.PassAs<base::Value>());
492 } 470 }
493 471
494 ManagedUserService::ManualBehavior ManagedUserService::GetManualBehaviorForHost( 472 ManagedUserService::ManualBehavior ManagedUserService::GetManualBehaviorForHost(
495 const std::string& hostname) { 473 const std::string& hostname) {
496 const base::DictionaryValue* dict = 474 const base::DictionaryValue* dict =
497 profile_->GetPrefs()->GetDictionary(prefs::kManagedModeManualHosts); 475 profile_->GetPrefs()->GetDictionary(prefs::kManagedModeManualHosts);
498 bool allow = false; 476 bool allow = false;
499 if (!dict->GetBooleanWithoutPathExpansion(hostname, &allow)) 477 if (!dict->GetBooleanWithoutPathExpansion(hostname, &allow))
500 return MANUAL_NONE; 478 return MANUAL_NONE;
501 479
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 539
562 CommandLine* command_line = CommandLine::ForCurrentProcess(); 540 CommandLine* command_line = CommandLine::ForCurrentProcess();
563 if (command_line->HasSwitch(switches::kManagedUserSyncToken)) { 541 if (command_line->HasSwitch(switches::kManagedUserSyncToken)) {
564 InitSync( 542 InitSync(
565 command_line->GetSwitchValueASCII(switches::kManagedUserSyncToken)); 543 command_line->GetSwitchValueASCII(switches::kManagedUserSyncToken));
566 } 544 }
567 545
568 ProfileOAuth2TokenService* token_service = 546 ProfileOAuth2TokenService* token_service =
569 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); 547 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_);
570 token_service->LoadCredentials(managed_users::kManagedUserPseudoEmail); 548 token_service->LoadCredentials(managed_users::kManagedUserPseudoEmail);
549 if (CommandLine::ForCurrentProcess()->HasSwitch(
550 switches::kPermissionRequestApiUrl)) {
551 permissions_creator_ =
552 PermissionRequestCreatorApiary::CreateWithProfile(profile_);
553 } else {
554 PrefService* pref_service = profile_->GetPrefs();
555 permissions_creator_.reset(new PermissionRequestCreatorSync(
556 settings_service,
557 ManagedUserSharedSettingsServiceFactory::GetForBrowserContext(profile_),
558 pref_service->GetString(prefs::kProfileName),
559 pref_service->GetString(prefs::kManagedUserId)));
560 }
571 561
572 extensions::ExtensionSystem* extension_system = 562 extensions::ExtensionSystem* extension_system =
573 extensions::ExtensionSystem::Get(profile_); 563 extensions::ExtensionSystem::Get(profile_);
574 extensions::ManagementPolicy* management_policy = 564 extensions::ManagementPolicy* management_policy =
575 extension_system->management_policy(); 565 extension_system->management_policy();
576 if (management_policy) 566 if (management_policy)
577 extension_system->management_policy()->RegisterProvider(this); 567 extension_system->management_policy()->RegisterProvider(this);
578 568
579 registrar_.Add(this, 569 registrar_.Add(this,
580 chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, 570 chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED,
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 686
697 void ManagedUserService::OnBrowserSetLastActive(Browser* browser) { 687 void ManagedUserService::OnBrowserSetLastActive(Browser* browser) {
698 bool profile_became_active = profile_->IsSameProfile(browser->profile()); 688 bool profile_became_active = profile_->IsSameProfile(browser->profile());
699 if (!is_profile_active_ && profile_became_active) 689 if (!is_profile_active_ && profile_became_active)
700 content::RecordAction(UserMetricsAction("ManagedUsers_OpenProfile")); 690 content::RecordAction(UserMetricsAction("ManagedUsers_OpenProfile"));
701 else if (is_profile_active_ && !profile_became_active) 691 else if (is_profile_active_ && !profile_became_active)
702 content::RecordAction(UserMetricsAction("ManagedUsers_SwitchProfile")); 692 content::RecordAction(UserMetricsAction("ManagedUsers_SwitchProfile"));
703 693
704 is_profile_active_ = profile_became_active; 694 is_profile_active_ = profile_became_active;
705 } 695 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698