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

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

Issue 33173005: Correctly deal with tokens for supervised users in ProfileOAuth2TokenService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 1 month 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/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_constants.h"
21 #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" 22 #include "chrome/browser/managed_mode/managed_user_settings_service.h"
23 #include "chrome/browser/managed_mode/managed_user_settings_service_factory.h" 23 #include "chrome/browser/managed_mode/managed_user_settings_service_factory.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/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/profile_oauth2_token_service.h"
29 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
28 #include "chrome/browser/signin/signin_manager.h" 30 #include "chrome/browser/signin/signin_manager.h"
29 #include "chrome/browser/signin/signin_manager_base.h" 31 #include "chrome/browser/signin/signin_manager_base.h"
30 #include "chrome/browser/signin/signin_manager_factory.h" 32 #include "chrome/browser/signin/signin_manager_factory.h"
31 #include "chrome/browser/signin/token_service.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"
(...skipping 16 matching lines...) Expand all
59 using base::Value; 59 using base::Value;
60 using content::BrowserThread; 60 using content::BrowserThread;
61 61
62 namespace { 62 namespace {
63 63
64 const char kManagedModeFinchActive[] = "Active"; 64 const char kManagedModeFinchActive[] = "Active";
65 const char kManagedModeFinchName[] = "ManagedModeLaunch"; 65 const char kManagedModeFinchName[] = "ManagedModeLaunch";
66 const char kManagedUserAccessRequestKeyPrefix[] = 66 const char kManagedUserAccessRequestKeyPrefix[] =
67 "X-ManagedUser-AccessRequests"; 67 "X-ManagedUser-AccessRequests";
68 const char kManagedUserAccessRequestTime[] = "timestamp"; 68 const char kManagedUserAccessRequestTime[] = "timestamp";
69 const char kManagedUserPseudoEmail[] = "managed_user@localhost";
70 const char kOpenManagedProfileKeyPrefix[] = "X-ManagedUser-Events-OpenProfile"; 69 const char kOpenManagedProfileKeyPrefix[] = "X-ManagedUser-Events-OpenProfile";
71 const char kQuitBrowserKeyPrefix[] = "X-ManagedUser-Events-QuitBrowser"; 70 const char kQuitBrowserKeyPrefix[] = "X-ManagedUser-Events-QuitBrowser";
72 const char kSwitchFromManagedProfileKeyPrefix[] = 71 const char kSwitchFromManagedProfileKeyPrefix[] =
73 "X-ManagedUser-Events-SwitchProfile"; 72 "X-ManagedUser-Events-SwitchProfile";
74 const char kEventTimestamp[] = "timestamp"; 73 const char kEventTimestamp[] = "timestamp";
75 74
76 std::string CanonicalizeHostname(const std::string& hostname) { 75 std::string CanonicalizeHostname(const std::string& hostname) {
77 std::string canonicalized; 76 std::string canonicalized;
78 url_canon::StdStringCanonOutput output(&canonicalized); 77 url_canon::StdStringCanonOutput output(&canonicalized);
79 url_parse::Component in_comp(0, hostname.length()); 78 url_parse::Component in_comp(0, hostname.length());
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 } 523 }
525 } 524 }
526 525
527 void ManagedUserService::InitSync(const std::string& refresh_token) { 526 void ManagedUserService::InitSync(const std::string& refresh_token) {
528 ProfileSyncService* service = 527 ProfileSyncService* service =
529 ProfileSyncServiceFactory::GetForProfile(profile_); 528 ProfileSyncServiceFactory::GetForProfile(profile_);
530 // Tell the sync service that setup is in progress so we don't start syncing 529 // Tell the sync service that setup is in progress so we don't start syncing
531 // until we've finished configuration. 530 // until we've finished configuration.
532 service->SetSetupInProgress(true); 531 service->SetSetupInProgress(true);
533 532
534 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_); 533 ProfileOAuth2TokenService* token_service =
535 token_service->UpdateCredentialsWithOAuth2( 534 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_);
536 GaiaAuthConsumer::ClientOAuthResult(refresh_token, std::string(), 0)); 535 token_service->UpdateCredentials(managed_users::kManagedUserPseudoEmail,
536 refresh_token);
537 537
538 // Continue in SetupSync() once the Sync backend has been initialized. 538 // Continue in SetupSync() once the Sync backend has been initialized.
539 if (service->sync_initialized()) { 539 if (service->sync_initialized()) {
540 SetupSync(); 540 SetupSync();
541 } else { 541 } else {
542 ProfileSyncServiceFactory::GetForProfile(profile_)->AddObserver(this); 542 ProfileSyncServiceFactory::GetForProfile(profile_)->AddObserver(this);
543 waiting_for_sync_initialization_ = true; 543 waiting_for_sync_initialization_ = true;
544 } 544 }
545 } 545 }
546 546
547 // static
548 const char* ManagedUserService::GetManagedUserPseudoEmail() {
549 return kManagedUserPseudoEmail;
550 }
551
552 void ManagedUserService::Init() { 547 void ManagedUserService::Init() {
553 ManagedUserSettingsService* settings_service = GetSettingsService(); 548 ManagedUserSettingsService* settings_service = GetSettingsService();
554 DCHECK(settings_service->IsReady()); 549 DCHECK(settings_service->IsReady());
555 if (!ProfileIsManaged()) { 550 if (!ProfileIsManaged()) {
556 settings_service->Clear(); 551 settings_service->Clear();
557 return; 552 return;
558 } 553 }
559 554
560 settings_service->Activate(); 555 settings_service->Activate();
561 556
562 CommandLine* command_line = CommandLine::ForCurrentProcess(); 557 CommandLine* command_line = CommandLine::ForCurrentProcess();
563 if (command_line->HasSwitch(switches::kManagedUserSyncToken)) { 558 if (command_line->HasSwitch(switches::kManagedUserSyncToken)) {
564 InitSync( 559 InitSync(
565 command_line->GetSwitchValueASCII(switches::kManagedUserSyncToken)); 560 command_line->GetSwitchValueASCII(switches::kManagedUserSyncToken));
566 } 561 }
567 562
568 // TokenService only loads tokens automatically if we're signed in, so we have 563 // TODO(rogerta): Remove this once PO2TS has replaced TokenService.
569 // to nudge it ourselves. 564 ProfileOAuth2TokenService* token_service =
570 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_); 565 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_);
571 token_service->LoadTokensFromDB(); 566 token_service->LoadCredentials();
572 567
573 extensions::ExtensionSystem* extension_system = 568 extensions::ExtensionSystem* extension_system =
574 extensions::ExtensionSystem::Get(profile_); 569 extensions::ExtensionSystem::Get(profile_);
575 extensions::ManagementPolicy* management_policy = 570 extensions::ManagementPolicy* management_policy =
576 extension_system->management_policy(); 571 extension_system->management_policy();
577 if (management_policy) 572 if (management_policy)
578 extension_system->management_policy()->RegisterProvider(this); 573 extension_system->management_policy()->RegisterProvider(this);
579 574
580 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, 575 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED,
581 content::Source<Profile>(profile_)); 576 content::Source<Profile>(profile_));
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 key_prefix, 695 key_prefix,
701 base::Int64ToString(base::TimeTicks::Now().ToInternalValue())); 696 base::Int64ToString(base::TimeTicks::Now().ToInternalValue()));
702 697
703 scoped_ptr<DictionaryValue> dict(new DictionaryValue); 698 scoped_ptr<DictionaryValue> dict(new DictionaryValue);
704 699
705 // TODO(bauerb): Use sane time when ready. 700 // TODO(bauerb): Use sane time when ready.
706 dict->SetDouble(kEventTimestamp, base::Time::Now().ToJsTime()); 701 dict->SetDouble(kEventTimestamp, base::Time::Now().ToJsTime());
707 702
708 GetSettingsService()->UploadItem(key, dict.PassAs<Value>()); 703 GetSettingsService()->UploadItem(key, dict.PassAs<Value>());
709 } 704 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698