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

Side by Side Diff: chrome/browser/signin/chrome_signin_client.cc

Issue 2442843002: Override SigninManager::SignOut if force-signin is enabled. (Closed)
Patch Set: fix try bot Created 4 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/signin/chrome_signin_client.h" 5 #include "chrome/browser/signin/chrome_signin_client.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h"
10 #include "base/command_line.h" 11 #include "base/command_line.h"
11 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
12 #include "build/build_config.h" 13 #include "build/build_config.h"
13 #include "chrome/browser/browser_process.h" 14 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/content_settings/cookie_settings_factory.h" 15 #include "chrome/browser/content_settings/cookie_settings_factory.h"
15 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 16 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
16 #include "chrome/browser/profiles/profile_attributes_entry.h" 17 #include "chrome/browser/profiles/profile_attributes_entry.h"
17 #include "chrome/browser/profiles/profile_attributes_storage.h" 18 #include "chrome/browser/profiles/profile_attributes_storage.h"
18 #include "chrome/browser/profiles/profile_manager.h" 19 #include "chrome/browser/profiles/profile_manager.h"
19 #include "chrome/browser/profiles/profile_metrics.h" 20 #include "chrome/browser/profiles/profile_metrics.h"
20 #include "chrome/browser/profiles/profile_window.h" 21 #include "chrome/browser/profiles/profile_window.h"
21 #include "chrome/browser/signin/local_auth.h" 22 #include "chrome/browser/signin/local_auth.h"
22 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 23 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
23 #include "chrome/browser/signin/signin_manager_factory.h" 24 #include "chrome/browser/signin/signin_manager_factory.h"
25 #include "chrome/browser/ui/browser_list.h"
26 #include "chrome/browser/ui/user_manager.h"
24 #include "chrome/browser/web_data_service_factory.h" 27 #include "chrome/browser/web_data_service_factory.h"
25 #include "chrome/common/channel_info.h" 28 #include "chrome/common/channel_info.h"
29 #include "chrome/common/pref_names.h"
26 #include "components/content_settings/core/browser/cookie_settings.h" 30 #include "components/content_settings/core/browser/cookie_settings.h"
27 #include "components/metrics/metrics_service.h" 31 #include "components/metrics/metrics_service.h"
28 #include "components/prefs/pref_service.h" 32 #include "components/prefs/pref_service.h"
29 #include "components/signin/core/browser/profile_oauth2_token_service.h" 33 #include "components/signin/core/browser/profile_oauth2_token_service.h"
30 #include "components/signin/core/browser/signin_cookie_changed_subscription.h" 34 #include "components/signin/core/browser/signin_cookie_changed_subscription.h"
31 #include "components/signin/core/browser/signin_header_helper.h" 35 #include "components/signin/core/browser/signin_header_helper.h"
32 #include "components/signin/core/common/profile_management_switches.h" 36 #include "components/signin/core/common/profile_management_switches.h"
33 #include "components/signin/core/common/signin_pref_names.h" 37 #include "components/signin/core/common/signin_pref_names.h"
34 #include "components/signin/core/common/signin_switches.h" 38 #include "components/signin/core/common/signin_switches.h"
35 #include "google_apis/gaia/gaia_constants.h" 39 #include "google_apis/gaia/gaia_constants.h"
36 #include "google_apis/gaia/gaia_urls.h" 40 #include "google_apis/gaia/gaia_urls.h"
37 #include "net/url_request/url_request_context_getter.h" 41 #include "net/url_request/url_request_context_getter.h"
38 #include "url/gurl.h" 42 #include "url/gurl.h"
39 43
40 #if defined(ENABLE_SUPERVISED_USERS) 44 #if defined(ENABLE_SUPERVISED_USERS)
41 #include "chrome/browser/supervised_user/supervised_user_constants.h" 45 #include "chrome/browser/supervised_user/supervised_user_constants.h"
42 #endif 46 #endif
43 47
44 #if defined(OS_CHROMEOS) 48 #if defined(OS_CHROMEOS)
45 #include "chrome/browser/chromeos/net/delay_network_call.h" 49 #include "chrome/browser/chromeos/net/delay_network_call.h"
46 #include "chrome/browser/chromeos/profiles/profile_helper.h" 50 #include "chrome/browser/chromeos/profiles/profile_helper.h"
47 #include "components/user_manager/known_user.h" 51 #include "components/user_manager/known_user.h"
48 #include "components/user_manager/user_manager.h" 52 #include "components/user_manager/user_manager.h"
49 #endif 53 #endif
50 54
51 #if !defined(OS_ANDROID) 55 #if !defined(OS_ANDROID)
52 #include "chrome/browser/first_run/first_run.h" 56 #include "chrome/browser/first_run/first_run.h"
53 #endif 57 #endif
54 58
59 namespace {
60
61 bool IsForceSigninEnabled() {
62 PrefService* prefs = g_browser_process->local_state();
63 return prefs && prefs->GetBoolean(prefs::kForceBrowserSignin);
64 }
65
66 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
67 void OnCloseBrowsersAborted(const base::FilePath& path) {}
68 #endif
69
70 } // namespace
71
55 ChromeSigninClient::ChromeSigninClient( 72 ChromeSigninClient::ChromeSigninClient(
56 Profile* profile, SigninErrorController* signin_error_controller) 73 Profile* profile,
74 SigninErrorController* signin_error_controller)
57 : OAuth2TokenService::Consumer("chrome_signin_client"), 75 : OAuth2TokenService::Consumer("chrome_signin_client"),
58 profile_(profile), 76 profile_(profile),
59 signin_error_controller_(signin_error_controller) { 77 signin_error_controller_(signin_error_controller),
78 is_force_signin_enabled_(IsForceSigninEnabled()) {
60 signin_error_controller_->AddObserver(this); 79 signin_error_controller_->AddObserver(this);
61 #if !defined(OS_CHROMEOS) 80 #if !defined(OS_CHROMEOS)
62 net::NetworkChangeNotifier::AddNetworkChangeObserver(this); 81 net::NetworkChangeNotifier::AddNetworkChangeObserver(this);
63 #else 82 #else
64 // UserManager may not exist in unit_tests. 83 // UserManager may not exist in unit_tests.
65 if (!user_manager::UserManager::IsInitialized()) 84 if (!user_manager::UserManager::IsInitialized())
66 return; 85 return;
67 86
68 const user_manager::User* user = 87 const user_manager::User* user =
69 chromeos::ProfileHelper::Get()->GetUserByProfile(profile_); 88 chromeos::ProfileHelper::Get()->GetUserByProfile(profile_);
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 void ChromeSigninClient::PostSignedIn(const std::string& account_id, 271 void ChromeSigninClient::PostSignedIn(const std::string& account_id,
253 const std::string& username, 272 const std::string& username,
254 const std::string& password) { 273 const std::string& password) {
255 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) 274 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
256 // Don't store password hash except when lock is available for the user. 275 // Don't store password hash except when lock is available for the user.
257 if (!password.empty() && profiles::IsLockAvailable(profile_)) 276 if (!password.empty() && profiles::IsLockAvailable(profile_))
258 LocalAuth::SetLocalAuthCredentials(profile_, password); 277 LocalAuth::SetLocalAuthCredentials(profile_, password);
259 #endif 278 #endif
260 } 279 }
261 280
281 void ChromeSigninClient::PreSignOut(const base::Callback<void()>& sign_out) {
282 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
283 if (is_force_signin_enabled_ && !profile_->IsSystemProfile() &&
284 !profile_->IsGuestSession()) {
285 BrowserList::CloseAllBrowsersWithProfile(
286 profile_, base::Bind(&ChromeSigninClient::OnCloseBrowsersSuccess,
287 base::Unretained(this), sign_out),
288 base::Bind(&OnCloseBrowsersAborted));
289 } else {
290 #else
291 {
292 #endif
293 SigninClient::PreSignOut(sign_out);
294 }
295 }
296
262 void ChromeSigninClient::OnErrorChanged() { 297 void ChromeSigninClient::OnErrorChanged() {
263 // Some tests don't have a ProfileManager. 298 // Some tests don't have a ProfileManager.
264 if (g_browser_process->profile_manager() == nullptr) 299 if (g_browser_process->profile_manager() == nullptr)
265 return; 300 return;
266 301
267 ProfileAttributesEntry* entry; 302 ProfileAttributesEntry* entry;
268 303
269 if (!g_browser_process->profile_manager()->GetProfileAttributesStorage(). 304 if (!g_browser_process->profile_manager()->GetProfileAttributesStorage().
270 GetProfileAttributesWithPath(profile_->GetPath(), &entry)) { 305 GetProfileAttributesWithPath(profile_->GetPath(), &entry)) {
271 return; 306 return;
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 ProfileOAuth2TokenService* token_service = 412 ProfileOAuth2TokenService* token_service =
378 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); 413 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_);
379 OAuth2TokenService::ScopeSet scopes; 414 OAuth2TokenService::ScopeSet scopes;
380 scopes.insert(GaiaConstants::kGoogleUserInfoEmail); 415 scopes.insert(GaiaConstants::kGoogleUserInfoEmail);
381 oauth_request_ = token_service->StartRequest(account_id, scopes, this); 416 oauth_request_ = token_service->StartRequest(account_id, scopes, this);
382 } 417 }
383 } 418 }
384 } 419 }
385 #endif 420 #endif
386 } 421 }
422
423 void ChromeSigninClient::OnCredentialsBeingCopied() {
424 if (is_force_signin_enabled_)
425 // The signout after credential copy won't open UserManager after all
426 // browser window are closed. Because the browser window will be opened for
427 // the new profile soon.
428 is_user_manager_displayed_ = false;
429 }
430
431 void ChromeSigninClient::OnCloseBrowsersSuccess(
432 const base::Callback<void()>& sign_out,
433 const base::FilePath& profile_path) {
434 SigninClient::PreSignOut(sign_out);
435
436 // After sign out, lock the profile and show UserManager if necessary.
437 LockProfile(profile_path);
438 if (is_user_manager_displayed_) {
439 ShowUserManager(profile_path);
440 } else {
441 is_user_manager_displayed_ = true;
442 }
443 }
444
445 void ChromeSigninClient::LockProfile(const base::FilePath& profile_path) {
446 ProfileAttributesEntry* entry;
447 bool has_entry = g_browser_process->profile_manager()
448 ->GetProfileAttributesStorage()
449 .GetProfileAttributesWithPath(profile_path, &entry);
450 DCHECK(has_entry);
451 entry->SetIsSigninRequired(true);
452 }
453
454 void ChromeSigninClient::ShowUserManager(const base::FilePath& profile_path) {
455 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
456 UserManager::Show(profile_path, profiles::USER_MANAGER_NO_TUTORIAL,
457 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION);
458 #endif
459 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698