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

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: Sync and move scoped_ptr include to subclass header files. 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 const GoogleServiceAuthError& error) {
Bernhard Bauer 2014/05/19 17:11:26 Given that GoogleServiceAuthError leaks the (Apiar
Adrian Kuegel 2014/05/20 08:38:06 Done. Should I keep the basic structure to suppor
Bernhard Bauer 2014/05/20 09:04:04 I think keeping the structure in PermissionRequest
453 waiting_for_permissions_ = false;
454 // TODO(akuegel): Figure out how to show the result of issuing the permission
455 // request in the UI. Currently, we assume the permission request was created
456 // successfully.
457 }
458
456 void ManagedUserService::AddAccessRequest(const GURL& url) { 459 void ManagedUserService::AddAccessRequest(const GURL& url) {
457 // Normalize the URL. 460 // Normalize the URL.
458 GURL normalized_url = ManagedModeURLFilter::Normalize(url); 461 GURL normalized_url = ManagedModeURLFilter::Normalize(url);
459 462
460 // Escape the URL. 463 // Escape the URL.
461 std::string output(net::EscapeQueryParamValue(normalized_url.spec(), true)); 464 std::string output(net::EscapeQueryParamValue(normalized_url.spec(), true));
462 465
463 // Add the prefix. 466 waiting_for_permissions_ = true;
464 std::string key = ManagedUserSettingsService::MakeSplitSettingKey( 467 permissions_creator_->CreatePermissionRequest(
465 kManagedUserAccessRequestKeyPrefix, output); 468 output,
466 469 base::Bind(&ManagedUserService::OnPermissionRequestIssued,
467 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue); 470 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 } 471 }
493 472
494 ManagedUserService::ManualBehavior ManagedUserService::GetManualBehaviorForHost( 473 ManagedUserService::ManualBehavior ManagedUserService::GetManualBehaviorForHost(
495 const std::string& hostname) { 474 const std::string& hostname) {
496 const base::DictionaryValue* dict = 475 const base::DictionaryValue* dict =
497 profile_->GetPrefs()->GetDictionary(prefs::kManagedModeManualHosts); 476 profile_->GetPrefs()->GetDictionary(prefs::kManagedModeManualHosts);
498 bool allow = false; 477 bool allow = false;
499 if (!dict->GetBooleanWithoutPathExpansion(hostname, &allow)) 478 if (!dict->GetBooleanWithoutPathExpansion(hostname, &allow))
500 return MANUAL_NONE; 479 return MANUAL_NONE;
501 480
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 540
562 CommandLine* command_line = CommandLine::ForCurrentProcess(); 541 CommandLine* command_line = CommandLine::ForCurrentProcess();
563 if (command_line->HasSwitch(switches::kManagedUserSyncToken)) { 542 if (command_line->HasSwitch(switches::kManagedUserSyncToken)) {
564 InitSync( 543 InitSync(
565 command_line->GetSwitchValueASCII(switches::kManagedUserSyncToken)); 544 command_line->GetSwitchValueASCII(switches::kManagedUserSyncToken));
566 } 545 }
567 546
568 ProfileOAuth2TokenService* token_service = 547 ProfileOAuth2TokenService* token_service =
569 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); 548 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_);
570 token_service->LoadCredentials(managed_users::kManagedUserPseudoEmail); 549 token_service->LoadCredentials(managed_users::kManagedUserPseudoEmail);
550 if (CommandLine::ForCurrentProcess()->HasSwitch(
551 switches::kPermissionRequestApiUrl)) {
552 permissions_creator_ =
553 PermissionRequestCreatorApiary::CreateWithProfile(profile_);
554 } else {
555 PrefService* pref_service = profile_->GetPrefs();
556 permissions_creator_ = PermissionRequestCreatorSync::Create(
557 settings_service,
558 ManagedUserSharedSettingsServiceFactory::GetForBrowserContext(profile_),
559 pref_service->GetString(prefs::kProfileName),
560 pref_service->GetString(prefs::kManagedUserId));
561 }
571 562
572 extensions::ExtensionSystem* extension_system = 563 extensions::ExtensionSystem* extension_system =
573 extensions::ExtensionSystem::Get(profile_); 564 extensions::ExtensionSystem::Get(profile_);
574 extensions::ManagementPolicy* management_policy = 565 extensions::ManagementPolicy* management_policy =
575 extension_system->management_policy(); 566 extension_system->management_policy();
576 if (management_policy) 567 if (management_policy)
577 extension_system->management_policy()->RegisterProvider(this); 568 extension_system->management_policy()->RegisterProvider(this);
578 569
579 registrar_.Add(this, 570 registrar_.Add(this,
580 chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, 571 chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED,
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 687
697 void ManagedUserService::OnBrowserSetLastActive(Browser* browser) { 688 void ManagedUserService::OnBrowserSetLastActive(Browser* browser) {
698 bool profile_became_active = profile_->IsSameProfile(browser->profile()); 689 bool profile_became_active = profile_->IsSameProfile(browser->profile());
699 if (!is_profile_active_ && profile_became_active) 690 if (!is_profile_active_ && profile_became_active)
700 content::RecordAction(UserMetricsAction("ManagedUsers_OpenProfile")); 691 content::RecordAction(UserMetricsAction("ManagedUsers_OpenProfile"));
701 else if (is_profile_active_ && !profile_became_active) 692 else if (is_profile_active_ && !profile_became_active)
702 content::RecordAction(UserMetricsAction("ManagedUsers_SwitchProfile")); 693 content::RecordAction(UserMetricsAction("ManagedUsers_SwitchProfile"));
703 694
704 is_profile_active_ = profile_became_active; 695 is_profile_active_ = profile_became_active;
705 } 696 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698