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

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: Upload flaked. 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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 local_state->RegisterListPref(kRegularUsers, PrefService::UNSYNCABLE_PREF); 152 local_state->RegisterListPref(kRegularUsers, PrefService::UNSYNCABLE_PREF);
152 local_state->RegisterListPref(kPublicAccounts, PrefService::UNSYNCABLE_PREF); 153 local_state->RegisterListPref(kPublicAccounts, PrefService::UNSYNCABLE_PREF);
153 local_state->RegisterStringPref(kPublicAccountPendingDataRemoval, "", 154 local_state->RegisterStringPref(kPublicAccountPendingDataRemoval, "",
154 PrefService::UNSYNCABLE_PREF); 155 PrefService::UNSYNCABLE_PREF);
155 local_state->RegisterDictionaryPref(kUserOAuthTokenStatus, 156 local_state->RegisterDictionaryPref(kUserOAuthTokenStatus,
156 PrefService::UNSYNCABLE_PREF); 157 PrefService::UNSYNCABLE_PREF);
157 local_state->RegisterDictionaryPref(kUserDisplayName, 158 local_state->RegisterDictionaryPref(kUserDisplayName,
158 PrefService::UNSYNCABLE_PREF); 159 PrefService::UNSYNCABLE_PREF);
159 local_state->RegisterDictionaryPref(kUserDisplayEmail, 160 local_state->RegisterDictionaryPref(kUserDisplayEmail,
160 PrefService::UNSYNCABLE_PREF); 161 PrefService::UNSYNCABLE_PREF);
162 SessionLengthLimiter::RegisterPrefs(local_state);
161 } 163 }
162 164
163 UserManagerImpl::UserManagerImpl() 165 UserManagerImpl::UserManagerImpl()
164 : cros_settings_(CrosSettings::Get()), 166 : cros_settings_(CrosSettings::Get()),
165 device_local_account_policy_service_(NULL), 167 device_local_account_policy_service_(NULL),
166 users_loaded_(false), 168 users_loaded_(false),
167 logged_in_user_(NULL), 169 logged_in_user_(NULL),
168 session_started_(false), 170 session_started_(false),
169 is_current_user_owner_(false), 171 is_current_user_owner_(false),
170 is_current_user_new_(false), 172 is_current_user_new_(false),
(...skipping 18 matching lines...) Expand all
189 logged_in_user_ = NULL; 191 logged_in_user_ = NULL;
190 delete *it; 192 delete *it;
191 } 193 }
192 delete logged_in_user_; 194 delete logged_in_user_;
193 } 195 }
194 196
195 void UserManagerImpl::Shutdown() { 197 void UserManagerImpl::Shutdown() {
196 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 198 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
197 cros_settings_->RemoveSettingsObserver(kAccountsPrefDeviceLocalAccounts, 199 cros_settings_->RemoveSettingsObserver(kAccountsPrefDeviceLocalAccounts,
198 this); 200 this);
201 // Stop the session length limiter.
202 session_length_limiter_.reset();
203
199 if (device_local_account_policy_service_) 204 if (device_local_account_policy_service_)
200 device_local_account_policy_service_->RemoveObserver(this); 205 device_local_account_policy_service_->RemoveObserver(this);
201 } 206 }
202 207
203 UserImageManager* UserManagerImpl::GetUserImageManager() { 208 UserImageManager* UserManagerImpl::GetUserImageManager() {
204 return user_image_manager_.get(); 209 return user_image_manager_.get();
205 } 210 }
206 211
207 const UserList& UserManagerImpl::GetUsers() const { 212 const UserList& UserManagerImpl::GetUsers() const {
208 const_cast<UserManagerImpl*>(this)->EnsureUsersLoaded(); 213 const_cast<UserManagerImpl*>(this)->EnsureUsersLoaded();
(...skipping 17 matching lines...) Expand all
226 PublicAccountUserLoggedIn(user); 231 PublicAccountUserLoggedIn(user);
227 } else if (browser_restart && email == g_browser_process->local_state()-> 232 } else if (browser_restart && email == g_browser_process->local_state()->
228 GetString(kPublicAccountPendingDataRemoval)) { 233 GetString(kPublicAccountPendingDataRemoval)) {
229 PublicAccountUserLoggedIn(User::CreatePublicAccountUser(email)); 234 PublicAccountUserLoggedIn(User::CreatePublicAccountUser(email));
230 } else if (email != owner_email_ && !user && 235 } else if (email != owner_email_ && !user &&
231 (AreEphemeralUsersEnabled() || browser_restart)) { 236 (AreEphemeralUsersEnabled() || browser_restart)) {
232 RegularUserLoggedInAsEphemeral(email); 237 RegularUserLoggedInAsEphemeral(email);
233 } else { 238 } else {
234 RegularUserLoggedIn(email, browser_restart); 239 RegularUserLoggedIn(email, browser_restart);
235 } 240 }
241
242 // Start the session length limiter.
243 session_length_limiter_.reset(new SessionLengthLimiter(NULL,
244 browser_restart));
236 } 245 }
237 246
238 NotifyOnLogin(); 247 NotifyOnLogin();
239 } 248 }
240 249
241 void UserManagerImpl::RetailModeUserLoggedIn() { 250 void UserManagerImpl::RetailModeUserLoggedIn() {
242 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 251 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
243 is_current_user_new_ = true; 252 is_current_user_new_ = true;
244 logged_in_user_ = User::CreateRetailModeUser(); 253 logged_in_user_ = User::CreateRetailModeUser();
245 user_image_manager_->UserLoggedIn(kRetailModeUserEMail, is_current_user_new_); 254 user_image_manager_->UserLoggedIn(kRetailModeUserEMail, is_current_user_new_);
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 bool UserManagerImpl::IsLoggedInAsStub() const { 604 bool UserManagerImpl::IsLoggedInAsStub() const {
596 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 605 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
597 return IsUserLoggedIn() && logged_in_user_->email() == kStubUser; 606 return IsUserLoggedIn() && logged_in_user_->email() == kStubUser;
598 } 607 }
599 608
600 bool UserManagerImpl::IsSessionStarted() const { 609 bool UserManagerImpl::IsSessionStarted() const {
601 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 610 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
602 return session_started_; 611 return session_started_;
603 } 612 }
604 613
614 bool UserManagerImpl::HasBrowserRestarted() const {
615 CommandLine* command_line = CommandLine::ForCurrentProcess();
616 return base::chromeos::IsRunningOnChromeOS() &&
617 command_line->HasSwitch(switches::kLoginUser) &&
618 !command_line->HasSwitch(switches::kLoginPassword);
619 }
620
605 bool UserManagerImpl::IsUserNonCryptohomeDataEphemeral( 621 bool UserManagerImpl::IsUserNonCryptohomeDataEphemeral(
606 const std::string& email) const { 622 const std::string& email) const {
607 // Data belonging to the guest, retail mode and stub users is always 623 // Data belonging to the guest, retail mode and stub users is always
608 // ephemeral. 624 // ephemeral.
609 if (email == kGuestUserEMail || email == kRetailModeUserEMail || 625 if (email == kGuestUserEMail || email == kRetailModeUserEMail ||
610 email == kStubUser) { 626 email == kStubUser) {
611 return true; 627 return true;
612 } 628 }
613 629
614 // Data belonging to the owner, anyone found on the user list and obsolete 630 // Data belonging to the owner, anyone found on the user list and obsolete
(...skipping 12 matching lines...) Expand all
627 if (IsUserLoggedIn() && (email == GetLoggedInUser()->email()) && 643 if (IsUserLoggedIn() && (email == GetLoggedInUser()->email()) &&
628 (is_current_user_ephemeral_regular_user_ || !IsLoggedInAsRegularUser())) { 644 (is_current_user_ephemeral_regular_user_ || !IsLoggedInAsRegularUser())) {
629 return true; 645 return true;
630 } 646 }
631 647
632 // Data belonging to any other user is ephemeral when: 648 // Data belonging to any other user is ephemeral when:
633 // a) Going through the regular login flow and the ephemeral users policy is 649 // a) Going through the regular login flow and the ephemeral users policy is
634 // enabled. 650 // enabled.
635 // - or - 651 // - or -
636 // b) The browser is restarting after a crash. 652 // b) The browser is restarting after a crash.
637 return AreEphemeralUsersEnabled() || 653 return AreEphemeralUsersEnabled() || HasBrowserRestarted();
638 (base::chromeos::IsRunningOnChromeOS() &&
639 !CommandLine::ForCurrentProcess()->
640 HasSwitch(switches::kLoginManager));
641 } 654 }
642 655
643 void UserManagerImpl::AddObserver(UserManager::Observer* obs) { 656 void UserManagerImpl::AddObserver(UserManager::Observer* obs) {
644 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 657 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
645 observer_list_.AddObserver(obs); 658 observer_list_.AddObserver(obs);
646 } 659 }
647 660
648 void UserManagerImpl::RemoveObserver(UserManager::Observer* obs) { 661 void UserManagerImpl::RemoveObserver(UserManager::Observer* obs) {
649 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 662 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
650 observer_list_.RemoveObserver(obs); 663 observer_list_.RemoveObserver(obs);
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
942 device_local_account_policy_service_->GetBrokerForAccount(username); 955 device_local_account_policy_service_->GetBrokerForAccount(username);
943 if (broker) 956 if (broker)
944 display_name = broker->GetDisplayName(); 957 display_name = broker->GetDisplayName();
945 } 958 }
946 959
947 // Set or clear the display name. 960 // Set or clear the display name.
948 SaveUserDisplayName(username, UTF8ToUTF16(display_name)); 961 SaveUserDisplayName(username, UTF8ToUTF16(display_name));
949 } 962 }
950 963
951 } // namespace chromeos 964 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/user_manager_impl.h ('k') | chrome/browser/chromeos/power/session_length_limiter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698