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

Side by Side Diff: chrome/browser/chromeos/login/user_manager_impl.cc

Issue 11499012: Add policy for limiting the session length (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix include order. Created 8 years 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/chromeos/login/user_manager_impl.h" 5 #include "chrome/browser/chromeos/login/user_manager_impl.h"
6 6
7 #include <cstddef> 7 #include <cstddef>
8 #include <set> 8 #include <set>
9 #include <vector> 9 #include <vector>
10 10
11 #include "ash/shell.h" 11 #include "ash/shell.h"
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/chromeos/chromeos_version.h" 13 #include "base/chromeos/chromeos_version.h"
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/compiler_specific.h" 15 #include "base/compiler_specific.h"
16 #include "base/file_path.h" 16 #include "base/file_path.h"
17 #include "base/file_util.h" 17 #include "base/file_util.h"
18 #include "base/logging.h" 18 #include "base/logging.h"
19 #include "base/rand_util.h" 19 #include "base/rand_util.h"
20 #include "base/utf_string_conversions.h" 20 #include "base/utf_string_conversions.h"
21 #include "base/values.h" 21 #include "base/values.h"
22 #include "chrome/browser/browser_process.h" 22 #include "chrome/browser/browser_process.h"
23 #include "chrome/browser/chromeos/cros/cert_library.h" 23 #include "chrome/browser/chromeos/cros/cert_library.h"
24 #include "chrome/browser/chromeos/cros/cros_library.h" 24 #include "chrome/browser/chromeos/cros/cros_library.h"
25 #include "chrome/browser/chromeos/input_method/input_method_manager.h" 25 #include "chrome/browser/chromeos/input_method/input_method_manager.h"
26 #include "chrome/browser/chromeos/login/login_display.h" 26 #include "chrome/browser/chromeos/login/login_display.h"
27 #include "chrome/browser/chromeos/login/remove_user_delegate.h" 27 #include "chrome/browser/chromeos/login/remove_user_delegate.h"
28 #include "chrome/browser/chromeos/login/user_image_manager_impl.h" 28 #include "chrome/browser/chromeos/login/user_image_manager_impl.h"
29 #include "chrome/browser/chromeos/login/wizard_controller.h" 29 #include "chrome/browser/chromeos/login/wizard_controller.h"
30 #include "chrome/browser/chromeos/power/session_length_limiter.h"
30 #include "chrome/browser/policy/browser_policy_connector.h" 31 #include "chrome/browser/policy/browser_policy_connector.h"
31 #include "chrome/browser/prefs/pref_service.h" 32 #include "chrome/browser/prefs/pref_service.h"
32 #include "chrome/browser/prefs/scoped_user_pref_update.h" 33 #include "chrome/browser/prefs/scoped_user_pref_update.h"
33 #include "chrome/browser/profiles/profile_manager.h" 34 #include "chrome/browser/profiles/profile_manager.h"
34 #include "chrome/browser/sync/profile_sync_service.h" 35 #include "chrome/browser/sync/profile_sync_service.h"
35 #include "chrome/browser/sync/profile_sync_service_factory.h" 36 #include "chrome/browser/sync/profile_sync_service_factory.h"
36 #include "chrome/common/chrome_notification_types.h" 37 #include "chrome/common/chrome_notification_types.h"
37 #include "chrome/common/chrome_switches.h" 38 #include "chrome/common/chrome_switches.h"
38 #include "chrome/common/pref_names.h" 39 #include "chrome/common/pref_names.h"
39 #include "chromeos/cryptohome/async_method_caller.h" 40 #include "chromeos/cryptohome/async_method_caller.h"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 local_state->RegisterListPref(kRegularUsers, PrefService::UNSYNCABLE_PREF); 151 local_state->RegisterListPref(kRegularUsers, PrefService::UNSYNCABLE_PREF);
151 local_state->RegisterListPref(kPublicAccounts, PrefService::UNSYNCABLE_PREF); 152 local_state->RegisterListPref(kPublicAccounts, PrefService::UNSYNCABLE_PREF);
152 local_state->RegisterStringPref(kPublicAccountPendingDataRemoval, "", 153 local_state->RegisterStringPref(kPublicAccountPendingDataRemoval, "",
153 PrefService::UNSYNCABLE_PREF); 154 PrefService::UNSYNCABLE_PREF);
154 local_state->RegisterDictionaryPref(kUserOAuthTokenStatus, 155 local_state->RegisterDictionaryPref(kUserOAuthTokenStatus,
155 PrefService::UNSYNCABLE_PREF); 156 PrefService::UNSYNCABLE_PREF);
156 local_state->RegisterDictionaryPref(kUserDisplayName, 157 local_state->RegisterDictionaryPref(kUserDisplayName,
157 PrefService::UNSYNCABLE_PREF); 158 PrefService::UNSYNCABLE_PREF);
158 local_state->RegisterDictionaryPref(kUserDisplayEmail, 159 local_state->RegisterDictionaryPref(kUserDisplayEmail,
159 PrefService::UNSYNCABLE_PREF); 160 PrefService::UNSYNCABLE_PREF);
161 SessionLengthLimiter::RegisterPrefs(local_state);
160 } 162 }
161 163
162 UserManagerImpl::UserManagerImpl() 164 UserManagerImpl::UserManagerImpl()
163 : cros_settings_(CrosSettings::Get()), 165 : cros_settings_(CrosSettings::Get()),
164 users_loaded_(false), 166 users_loaded_(false),
165 logged_in_user_(NULL), 167 logged_in_user_(NULL),
166 session_started_(false), 168 session_started_(false),
167 is_current_user_owner_(false), 169 is_current_user_owner_(false),
168 is_current_user_new_(false), 170 is_current_user_new_(false),
169 is_current_user_ephemeral_regular_user_(false), 171 is_current_user_ephemeral_regular_user_(false),
(...skipping 17 matching lines...) Expand all
187 logged_in_user_ = NULL; 189 logged_in_user_ = NULL;
188 delete *it; 190 delete *it;
189 } 191 }
190 delete logged_in_user_; 192 delete logged_in_user_;
191 } 193 }
192 194
193 void UserManagerImpl::Shutdown() { 195 void UserManagerImpl::Shutdown() {
194 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 196 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
195 cros_settings_->RemoveSettingsObserver(kAccountsPrefDeviceLocalAccounts, 197 cros_settings_->RemoveSettingsObserver(kAccountsPrefDeviceLocalAccounts,
196 this); 198 this);
199 // Stop the session length limiter.
200 session_length_limiter_.reset();
197 } 201 }
198 202
199 UserImageManager* UserManagerImpl::GetUserImageManager() { 203 UserImageManager* UserManagerImpl::GetUserImageManager() {
200 return user_image_manager_.get(); 204 return user_image_manager_.get();
201 } 205 }
202 206
203 const UserList& UserManagerImpl::GetUsers() const { 207 const UserList& UserManagerImpl::GetUsers() const {
204 const_cast<UserManagerImpl*>(this)->EnsureUsersLoaded(); 208 const_cast<UserManagerImpl*>(this)->EnsureUsersLoaded();
205 return users_; 209 return users_;
206 } 210 }
(...skipping 15 matching lines...) Expand all
222 PublicAccountUserLoggedIn(user); 226 PublicAccountUserLoggedIn(user);
223 } else if (browser_restart && email == g_browser_process->local_state()-> 227 } else if (browser_restart && email == g_browser_process->local_state()->
224 GetString(kPublicAccountPendingDataRemoval)) { 228 GetString(kPublicAccountPendingDataRemoval)) {
225 PublicAccountUserLoggedIn(User::CreatePublicAccountUser(email)); 229 PublicAccountUserLoggedIn(User::CreatePublicAccountUser(email));
226 } else if (email != owner_email_ && !user && 230 } else if (email != owner_email_ && !user &&
227 (AreEphemeralUsersEnabled() || browser_restart)) { 231 (AreEphemeralUsersEnabled() || browser_restart)) {
228 RegularUserLoggedInAsEphemeral(email); 232 RegularUserLoggedInAsEphemeral(email);
229 } else { 233 } else {
230 RegularUserLoggedIn(email, browser_restart); 234 RegularUserLoggedIn(email, browser_restart);
231 } 235 }
236
237 // Start the session length limiter.
238 session_length_limiter_.reset(new SessionLengthLimiter(NULL,
239 browser_restart));
232 } 240 }
233 241
234 NotifyOnLogin(); 242 NotifyOnLogin();
235 } 243 }
236 244
237 void UserManagerImpl::RetailModeUserLoggedIn() { 245 void UserManagerImpl::RetailModeUserLoggedIn() {
238 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 246 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
239 is_current_user_new_ = true; 247 is_current_user_new_ = true;
240 logged_in_user_ = User::CreateRetailModeUser(); 248 logged_in_user_ = User::CreateRetailModeUser();
241 user_image_manager_->UserLoggedIn(kRetailModeUserEMail, is_current_user_new_); 249 user_image_manager_->UserLoggedIn(kRetailModeUserEMail, is_current_user_new_);
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 bool UserManagerImpl::IsLoggedInAsStub() const { 583 bool UserManagerImpl::IsLoggedInAsStub() const {
576 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 584 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
577 return IsUserLoggedIn() && logged_in_user_->email() == kStubUser; 585 return IsUserLoggedIn() && logged_in_user_->email() == kStubUser;
578 } 586 }
579 587
580 bool UserManagerImpl::IsSessionStarted() const { 588 bool UserManagerImpl::IsSessionStarted() const {
581 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 589 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
582 return session_started_; 590 return session_started_;
583 } 591 }
584 592
593 bool UserManagerImpl::HasBrowserRestarted() const {
594 CommandLine* command_line = CommandLine::ForCurrentProcess();
595 return base::chromeos::IsRunningOnChromeOS() &&
596 command_line->HasSwitch(switches::kLoginUser) &&
597 !command_line->HasSwitch(switches::kLoginPassword);
598 }
599
585 bool UserManagerImpl::IsUserNonCryptohomeDataEphemeral( 600 bool UserManagerImpl::IsUserNonCryptohomeDataEphemeral(
586 const std::string& email) const { 601 const std::string& email) const {
587 // Data belonging to the guest, retail mode and stub users is always 602 // Data belonging to the guest, retail mode and stub users is always
588 // ephemeral. 603 // ephemeral.
589 if (email == kGuestUserEMail || email == kRetailModeUserEMail || 604 if (email == kGuestUserEMail || email == kRetailModeUserEMail ||
590 email == kStubUser) { 605 email == kStubUser) {
591 return true; 606 return true;
592 } 607 }
593 608
594 // Data belonging to the owner, anyone found on the user list and obsolete 609 // Data belonging to the owner, anyone found on the user list and obsolete
(...skipping 12 matching lines...) Expand all
607 if (IsUserLoggedIn() && (email == GetLoggedInUser()->email()) && 622 if (IsUserLoggedIn() && (email == GetLoggedInUser()->email()) &&
608 (is_current_user_ephemeral_regular_user_ || !IsLoggedInAsRegularUser())) { 623 (is_current_user_ephemeral_regular_user_ || !IsLoggedInAsRegularUser())) {
609 return true; 624 return true;
610 } 625 }
611 626
612 // Data belonging to any other user is ephemeral when: 627 // Data belonging to any other user is ephemeral when:
613 // a) Going through the regular login flow and the ephemeral users policy is 628 // a) Going through the regular login flow and the ephemeral users policy is
614 // enabled. 629 // enabled.
615 // - or - 630 // - or -
616 // b) The browser is restarting after a crash. 631 // b) The browser is restarting after a crash.
617 return AreEphemeralUsersEnabled() || 632 return AreEphemeralUsersEnabled() || HasBrowserRestarted();
618 (base::chromeos::IsRunningOnChromeOS() &&
619 !CommandLine::ForCurrentProcess()->
620 HasSwitch(switches::kLoginManager));
621 } 633 }
622 634
623 void UserManagerImpl::AddObserver(UserManager::Observer* obs) { 635 void UserManagerImpl::AddObserver(UserManager::Observer* obs) {
624 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 636 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
625 observer_list_.AddObserver(obs); 637 observer_list_.AddObserver(obs);
626 } 638 }
627 639
628 void UserManagerImpl::RemoveObserver(UserManager::Observer* obs) { 640 void UserManagerImpl::RemoveObserver(UserManager::Observer* obs) {
629 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 641 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
630 observer_list_.RemoveObserver(obs); 642 observer_list_.RemoveObserver(obs);
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
905 users_.insert(users_.begin(), User::CreatePublicAccountUser(*it)); 917 users_.insert(users_.begin(), User::CreatePublicAccountUser(*it));
906 } 918 }
907 919
908 user_image_manager_->LoadUserImages( 920 user_image_manager_->LoadUserImages(
909 UserList(users_.begin(), users_.begin() + new_public_accounts.size())); 921 UserList(users_.begin(), users_.begin() + new_public_accounts.size()));
910 922
911 return true; 923 return true;
912 } 924 }
913 925
914 } // namespace chromeos 926 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698