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/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
11 #include "base/sequenced_task_runner.h" | 11 #include "base/sequenced_task_runner.h" |
12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "chrome/browser/chrome_notification_types.h" | 14 #include "chrome/browser/chrome_notification_types.h" |
15 #include "chrome/browser/extensions/extension_service.h" | 15 #include "chrome/browser/extensions/extension_service.h" |
16 #include "chrome/browser/extensions/extension_system.h" | 16 #include "chrome/browser/extensions/extension_system.h" |
17 #include "chrome/browser/managed_mode/custodian_profile_downloader_service.h" | 17 #include "chrome/browser/managed_mode/custodian_profile_downloader_service.h" |
18 #include "chrome/browser/managed_mode/custodian_profile_downloader_service_facto
ry.h" | 18 #include "chrome/browser/managed_mode/custodian_profile_downloader_service_facto
ry.h" |
19 #include "chrome/browser/managed_mode/managed_mode_site_list.h" | 19 #include "chrome/browser/managed_mode/managed_mode_site_list.h" |
| 20 #include "chrome/browser/managed_mode/managed_user_constants.h" |
20 #include "chrome/browser/managed_mode/managed_user_registration_utility.h" | 21 #include "chrome/browser/managed_mode/managed_user_registration_utility.h" |
| 22 #include "chrome/browser/managed_mode/managed_user_settings_service.h" |
| 23 #include "chrome/browser/managed_mode/managed_user_settings_service_factory.h" |
21 #include "chrome/browser/managed_mode/managed_user_sync_service.h" | 24 #include "chrome/browser/managed_mode/managed_user_sync_service.h" |
22 #include "chrome/browser/managed_mode/managed_user_sync_service_factory.h" | 25 #include "chrome/browser/managed_mode/managed_user_sync_service_factory.h" |
23 #include "chrome/browser/policy/managed_mode_policy_provider.h" | |
24 #include "chrome/browser/policy/profile_policy_connector.h" | |
25 #include "chrome/browser/policy/profile_policy_connector_factory.h" | |
26 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 26 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
27 #include "chrome/browser/profiles/profile.h" | 27 #include "chrome/browser/profiles/profile.h" |
28 #include "chrome/browser/signin/signin_manager.h" | 28 #include "chrome/browser/signin/signin_manager.h" |
29 #include "chrome/browser/signin/signin_manager_base.h" | 29 #include "chrome/browser/signin/signin_manager_base.h" |
30 #include "chrome/browser/signin/signin_manager_factory.h" | 30 #include "chrome/browser/signin/signin_manager_factory.h" |
31 #include "chrome/browser/signin/token_service.h" | 31 #include "chrome/browser/signin/token_service.h" |
32 #include "chrome/browser/signin/token_service_factory.h" | 32 #include "chrome/browser/signin/token_service_factory.h" |
33 #include "chrome/browser/sync/glue/session_model_associator.h" | 33 #include "chrome/browser/sync/glue/session_model_associator.h" |
34 #include "chrome/browser/sync/profile_sync_service.h" | 34 #include "chrome/browser/sync/profile_sync_service.h" |
35 #include "chrome/browser/sync/profile_sync_service_factory.h" | 35 #include "chrome/browser/sync/profile_sync_service_factory.h" |
36 #include "chrome/browser/ui/browser.h" | 36 #include "chrome/browser/ui/browser.h" |
37 #include "chrome/browser/ui/browser_list.h" | 37 #include "chrome/browser/ui/browser_list.h" |
38 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 38 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
39 #include "chrome/common/chrome_switches.h" | 39 #include "chrome/common/chrome_switches.h" |
40 #include "chrome/common/extensions/api/managed_mode_private/managed_mode_handler
.h" | 40 #include "chrome/common/extensions/api/managed_mode_private/managed_mode_handler
.h" |
41 #include "chrome/common/extensions/extension_set.h" | 41 #include "chrome/common/extensions/extension_set.h" |
42 #include "chrome/common/pref_names.h" | 42 #include "chrome/common/pref_names.h" |
43 #include "components/user_prefs/pref_registry_syncable.h" | 43 #include "components/user_prefs/pref_registry_syncable.h" |
44 #include "content/public/browser/browser_thread.h" | 44 #include "content/public/browser/browser_thread.h" |
45 #include "content/public/browser/notification_details.h" | 45 #include "content/public/browser/notification_details.h" |
46 #include "content/public/browser/notification_source.h" | 46 #include "content/public/browser/notification_source.h" |
47 #include "google_apis/gaia/gaia_constants.h" | 47 #include "google_apis/gaia/gaia_constants.h" |
48 #include "google_apis/gaia/google_service_auth_error.h" | 48 #include "google_apis/gaia/google_service_auth_error.h" |
49 #include "grit/generated_resources.h" | 49 #include "grit/generated_resources.h" |
50 #include "net/base/escape.h" | 50 #include "net/base/escape.h" |
51 #include "policy/policy_constants.h" | |
52 #include "ui/base/l10n/l10n_util.h" | 51 #include "ui/base/l10n/l10n_util.h" |
53 | 52 |
54 #if defined(OS_CHROMEOS) | 53 #if defined(OS_CHROMEOS) |
55 #include "chrome/browser/chromeos/login/user_manager.h" | 54 #include "chrome/browser/chromeos/login/user_manager.h" |
56 #endif | 55 #endif |
57 | 56 |
58 using base::DictionaryValue; | 57 using base::DictionaryValue; |
59 using base::Value; | 58 using base::Value; |
60 using content::BrowserThread; | 59 using content::BrowserThread; |
61 using policy::ManagedModePolicyProvider; | |
62 | 60 |
63 namespace { | 61 namespace { |
64 | 62 |
65 const char kManagedModeFinchActive[] = "Active"; | 63 const char kManagedModeFinchActive[] = "Active"; |
66 const char kManagedModeFinchName[] = "ManagedModeLaunch"; | 64 const char kManagedModeFinchName[] = "ManagedModeLaunch"; |
67 const char kManagedUserAccessRequestKeyPrefix[] = | 65 const char kManagedUserAccessRequestKeyPrefix[] = |
68 "X-ManagedUser-AccessRequests"; | 66 "X-ManagedUser-AccessRequests"; |
69 const char kManagedUserAccessRequestTime[] = "timestamp"; | 67 const char kManagedUserAccessRequestTime[] = "timestamp"; |
70 const char kManagedUserPseudoEmail[] = "managed_user@localhost"; | 68 const char kManagedUserPseudoEmail[] = "managed_user@localhost"; |
71 const char kOpenManagedProfileKeyPrefix[] = "X-ManagedUser-Events-OpenProfile"; | 69 const char kOpenManagedProfileKeyPrefix[] = "X-ManagedUser-Events-OpenProfile"; |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 | 440 |
443 extensions::ExtensionResource site_list = | 441 extensions::ExtensionResource site_list = |
444 extensions::ManagedModeInfo::GetContentPackSiteList(extension); | 442 extensions::ManagedModeInfo::GetContentPackSiteList(extension); |
445 if (!site_list.empty()) | 443 if (!site_list.empty()) |
446 site_lists.push_back(new ManagedModeSiteList(extension->id(), site_list)); | 444 site_lists.push_back(new ManagedModeSiteList(extension->id(), site_list)); |
447 } | 445 } |
448 | 446 |
449 return site_lists.Pass(); | 447 return site_lists.Pass(); |
450 } | 448 } |
451 | 449 |
452 ManagedModePolicyProvider* ManagedUserService::GetPolicyProvider() { | 450 ManagedUserSettingsService* ManagedUserService::GetSettingsService() { |
453 policy::ProfilePolicyConnector* connector = | 451 return ManagedUserSettingsServiceFactory::GetForProfile(profile_); |
454 policy::ProfilePolicyConnectorFactory::GetForProfile(profile_); | |
455 return connector->managed_mode_policy_provider(); | |
456 } | 452 } |
457 | 453 |
458 void ManagedUserService::OnDefaultFilteringBehaviorChanged() { | 454 void ManagedUserService::OnDefaultFilteringBehaviorChanged() { |
459 DCHECK(ProfileIsManaged()); | 455 DCHECK(ProfileIsManaged()); |
460 | 456 |
461 int behavior_value = profile_->GetPrefs()->GetInteger( | 457 int behavior_value = profile_->GetPrefs()->GetInteger( |
462 prefs::kDefaultManagedModeFilteringBehavior); | 458 prefs::kDefaultManagedModeFilteringBehavior); |
463 ManagedModeURLFilter::FilteringBehavior behavior = | 459 ManagedModeURLFilter::FilteringBehavior behavior = |
464 ManagedModeURLFilter::BehaviorFromInt(behavior_value); | 460 ManagedModeURLFilter::BehaviorFromInt(behavior_value); |
465 url_filter_context_.SetDefaultFilteringBehavior(behavior); | 461 url_filter_context_.SetDefaultFilteringBehavior(behavior); |
(...skipping 14 matching lines...) Expand all Loading... |
480 } | 476 } |
481 | 477 |
482 void ManagedUserService::AddAccessRequest(const GURL& url) { | 478 void ManagedUserService::AddAccessRequest(const GURL& url) { |
483 // Normalize the URL. | 479 // Normalize the URL. |
484 GURL normalized_url = ManagedModeURLFilter::Normalize(url); | 480 GURL normalized_url = ManagedModeURLFilter::Normalize(url); |
485 | 481 |
486 // Escape the URL. | 482 // Escape the URL. |
487 std::string output(net::EscapeQueryParamValue(normalized_url.spec(), true)); | 483 std::string output(net::EscapeQueryParamValue(normalized_url.spec(), true)); |
488 | 484 |
489 // Add the prefix. | 485 // Add the prefix. |
490 std::string key = ManagedModePolicyProvider::MakeSplitSettingKey( | 486 std::string key = ManagedUserSettingsService::MakeSplitSettingKey( |
491 kManagedUserAccessRequestKeyPrefix, output); | 487 kManagedUserAccessRequestKeyPrefix, output); |
492 | 488 |
493 scoped_ptr<DictionaryValue> dict(new DictionaryValue); | 489 scoped_ptr<DictionaryValue> dict(new DictionaryValue); |
494 | 490 |
495 // TODO(sergiu): Use sane time here when it's ready. | 491 // TODO(sergiu): Use sane time here when it's ready. |
496 dict->SetDouble(kManagedUserAccessRequestTime, base::Time::Now().ToJsTime()); | 492 dict->SetDouble(kManagedUserAccessRequestTime, base::Time::Now().ToJsTime()); |
497 | 493 |
498 GetPolicyProvider()->UploadItem(key, dict.PassAs<Value>()); | 494 GetSettingsService()->UploadItem(key, dict.PassAs<Value>()); |
499 } | 495 } |
500 | 496 |
501 ManagedUserService::ManualBehavior ManagedUserService::GetManualBehaviorForHost( | 497 ManagedUserService::ManualBehavior ManagedUserService::GetManualBehaviorForHost( |
502 const std::string& hostname) { | 498 const std::string& hostname) { |
503 const DictionaryValue* dict = | 499 const DictionaryValue* dict = |
504 profile_->GetPrefs()->GetDictionary(prefs::kManagedModeManualHosts); | 500 profile_->GetPrefs()->GetDictionary(prefs::kManagedModeManualHosts); |
505 bool allow = false; | 501 bool allow = false; |
506 if (!dict->GetBooleanWithoutPathExpansion(hostname, &allow)) | 502 if (!dict->GetBooleanWithoutPathExpansion(hostname, &allow)) |
507 return MANUAL_NONE; | 503 return MANUAL_NONE; |
508 | 504 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
557 waiting_for_sync_initialization_ = true; | 553 waiting_for_sync_initialization_ = true; |
558 } | 554 } |
559 } | 555 } |
560 | 556 |
561 // static | 557 // static |
562 const char* ManagedUserService::GetManagedUserPseudoEmail() { | 558 const char* ManagedUserService::GetManagedUserPseudoEmail() { |
563 return kManagedUserPseudoEmail; | 559 return kManagedUserPseudoEmail; |
564 } | 560 } |
565 | 561 |
566 void ManagedUserService::Init() { | 562 void ManagedUserService::Init() { |
567 ManagedModePolicyProvider* policy_provider = GetPolicyProvider(); | 563 ManagedUserSettingsService* settings_service = GetSettingsService(); |
| 564 DCHECK(settings_service->IsReady()); |
568 if (!ProfileIsManaged()) { | 565 if (!ProfileIsManaged()) { |
569 if (policy_provider) | 566 settings_service->Clear(); |
570 policy_provider->Clear(); | |
571 | |
572 return; | 567 return; |
573 } | 568 } |
574 | 569 |
| 570 settings_service->Activate(); |
| 571 |
575 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 572 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
576 if (command_line->HasSwitch(switches::kManagedUserSyncToken)) { | 573 if (command_line->HasSwitch(switches::kManagedUserSyncToken)) { |
577 InitSync( | 574 InitSync( |
578 command_line->GetSwitchValueASCII(switches::kManagedUserSyncToken)); | 575 command_line->GetSwitchValueASCII(switches::kManagedUserSyncToken)); |
579 } | 576 } |
580 | 577 |
581 // TokenService only loads tokens automatically if we're signed in, so we have | 578 // TokenService only loads tokens automatically if we're signed in, so we have |
582 // to nudge it ourselves. | 579 // to nudge it ourselves. |
583 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_); | 580 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_); |
584 token_service->LoadTokensFromDB(); | 581 token_service->LoadTokensFromDB(); |
(...skipping 17 matching lines...) Expand all Loading... |
602 base::Unretained(this))); | 599 base::Unretained(this))); |
603 pref_change_registrar_.Add(prefs::kManagedModeManualHosts, | 600 pref_change_registrar_.Add(prefs::kManagedModeManualHosts, |
604 base::Bind(&ManagedUserService::UpdateManualHosts, | 601 base::Bind(&ManagedUserService::UpdateManualHosts, |
605 base::Unretained(this))); | 602 base::Unretained(this))); |
606 pref_change_registrar_.Add(prefs::kManagedModeManualURLs, | 603 pref_change_registrar_.Add(prefs::kManagedModeManualURLs, |
607 base::Bind(&ManagedUserService::UpdateManualURLs, | 604 base::Bind(&ManagedUserService::UpdateManualURLs, |
608 base::Unretained(this))); | 605 base::Unretained(this))); |
609 | 606 |
610 BrowserList::AddObserver(this); | 607 BrowserList::AddObserver(this); |
611 | 608 |
612 if (policy_provider) | |
613 policy_provider->InitLocalPolicies(); | |
614 | |
615 // Initialize the filter. | 609 // Initialize the filter. |
616 OnDefaultFilteringBehaviorChanged(); | 610 OnDefaultFilteringBehaviorChanged(); |
617 UpdateSiteLists(); | 611 UpdateSiteLists(); |
618 UpdateManualHosts(); | 612 UpdateManualHosts(); |
619 UpdateManualURLs(); | 613 UpdateManualURLs(); |
620 | 614 |
621 // Call the callbacks to notify that the ManagedUserService has been | 615 // Call the callbacks to notify that the ManagedUserService has been |
622 // initialized. | 616 // initialized. |
623 for (std::vector<base::Closure>::iterator it = init_callbacks_.begin(); | 617 for (std::vector<base::Closure>::iterator it = init_callbacks_.begin(); |
624 it != init_callbacks_.end(); | 618 it != init_callbacks_.end(); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
711 if (!is_profile_active_ && profile_became_active) | 705 if (!is_profile_active_ && profile_became_active) |
712 RecordProfileAndBrowserEventsHelper(kOpenManagedProfileKeyPrefix); | 706 RecordProfileAndBrowserEventsHelper(kOpenManagedProfileKeyPrefix); |
713 else if (is_profile_active_ && !profile_became_active) | 707 else if (is_profile_active_ && !profile_became_active) |
714 RecordProfileAndBrowserEventsHelper(kSwitchFromManagedProfileKeyPrefix); | 708 RecordProfileAndBrowserEventsHelper(kSwitchFromManagedProfileKeyPrefix); |
715 | 709 |
716 is_profile_active_ = profile_became_active; | 710 is_profile_active_ = profile_became_active; |
717 } | 711 } |
718 | 712 |
719 void ManagedUserService::RecordProfileAndBrowserEventsHelper( | 713 void ManagedUserService::RecordProfileAndBrowserEventsHelper( |
720 const char* key_prefix) { | 714 const char* key_prefix) { |
721 std::string key = ManagedModePolicyProvider::MakeSplitSettingKey(key_prefix, | 715 std::string key = ManagedUserSettingsService::MakeSplitSettingKey( |
| 716 key_prefix, |
722 base::Int64ToString(base::TimeTicks::Now().ToInternalValue())); | 717 base::Int64ToString(base::TimeTicks::Now().ToInternalValue())); |
723 | 718 |
724 scoped_ptr<DictionaryValue> dict(new DictionaryValue); | 719 scoped_ptr<DictionaryValue> dict(new DictionaryValue); |
725 | 720 |
726 // TODO(bauerb): Use sane time when ready. | 721 // TODO(bauerb): Use sane time when ready. |
727 dict->SetDouble(kEventTimestamp, base::Time::Now().ToJsTime()); | 722 dict->SetDouble(kEventTimestamp, base::Time::Now().ToJsTime()); |
728 | 723 |
729 ManagedModePolicyProvider* provider = GetPolicyProvider(); | 724 GetSettingsService()->UploadItem(key, dict.PassAs<Value>()); |
730 // It is NULL in tests. | |
731 if (provider) | |
732 provider->UploadItem(key, dict.PassAs<Value>()); | |
733 } | 725 } |
OLD | NEW |