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

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

Issue 2442843002: Override SigninManager::SignOut if force-signin is enabled. (Closed)
Patch Set: 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"
26 #include "chrome/common/features.h" 29 #include "chrome/common/features.h"
30 #include "chrome/common/pref_names.h"
27 #include "components/content_settings/core/browser/cookie_settings.h" 31 #include "components/content_settings/core/browser/cookie_settings.h"
28 #include "components/metrics/metrics_service.h" 32 #include "components/metrics/metrics_service.h"
29 #include "components/prefs/pref_service.h" 33 #include "components/prefs/pref_service.h"
30 #include "components/signin/core/browser/profile_oauth2_token_service.h" 34 #include "components/signin/core/browser/profile_oauth2_token_service.h"
31 #include "components/signin/core/browser/signin_cookie_changed_subscription.h" 35 #include "components/signin/core/browser/signin_cookie_changed_subscription.h"
32 #include "components/signin/core/browser/signin_header_helper.h" 36 #include "components/signin/core/browser/signin_header_helper.h"
33 #include "components/signin/core/common/profile_management_switches.h" 37 #include "components/signin/core/common/profile_management_switches.h"
34 #include "components/signin/core/common/signin_pref_names.h" 38 #include "components/signin/core/common/signin_pref_names.h"
35 #include "components/signin/core/common/signin_switches.h" 39 #include "components/signin/core/common/signin_switches.h"
36 #include "google_apis/gaia/gaia_constants.h" 40 #include "google_apis/gaia/gaia_constants.h"
37 #include "google_apis/gaia/gaia_urls.h" 41 #include "google_apis/gaia/gaia_urls.h"
38 #include "net/url_request/url_request_context_getter.h" 42 #include "net/url_request/url_request_context_getter.h"
39 #include "url/gurl.h" 43 #include "url/gurl.h"
40 44
41 #if BUILDFLAG(ENABLE_SUPERVISED_USERS) 45 #if BUILDFLAG(ENABLE_SUPERVISED_USERS)
42 #include "chrome/browser/supervised_user/supervised_user_constants.h" 46 #include "chrome/browser/supervised_user/supervised_user_constants.h"
43 #endif 47 #endif
44 48
45 #if defined(OS_CHROMEOS) 49 #if defined(OS_CHROMEOS)
46 #include "chrome/browser/chromeos/net/delay_network_call.h" 50 #include "chrome/browser/chromeos/net/delay_network_call.h"
47 #include "chrome/browser/chromeos/profiles/profile_helper.h" 51 #include "chrome/browser/chromeos/profiles/profile_helper.h"
48 #include "components/user_manager/known_user.h" 52 #include "components/user_manager/known_user.h"
49 #include "components/user_manager/user_manager.h" 53 #include "components/user_manager/user_manager.h"
50 #endif 54 #endif
51 55
52 #if !defined(OS_ANDROID) 56 #if !defined(OS_ANDROID)
53 #include "chrome/browser/first_run/first_run.h" 57 #include "chrome/browser/first_run/first_run.h"
54 #endif 58 #endif
55 59
60 namespace {
61
62 bool IsForceSigninEnabled() {
63 PrefService* prefs = g_browser_process->local_state();
64 return prefs && prefs->GetBoolean(prefs::kForceBrowserSignin);
65 }
66
67 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
68 void OnCloseBrowsersAborted(const base::FilePath& path) {}
69 #endif
70
71 } // namespace
72
56 ChromeSigninClient::ChromeSigninClient( 73 ChromeSigninClient::ChromeSigninClient(
57 Profile* profile, SigninErrorController* signin_error_controller) 74 Profile* profile,
75 SigninErrorController* signin_error_controller)
58 : OAuth2TokenService::Consumer("chrome_signin_client"), 76 : OAuth2TokenService::Consumer("chrome_signin_client"),
59 profile_(profile), 77 profile_(profile),
60 signin_error_controller_(signin_error_controller) { 78 signin_error_controller_(signin_error_controller),
79 is_force_signin_enabled_(IsForceSigninEnabled()) {
61 signin_error_controller_->AddObserver(this); 80 signin_error_controller_->AddObserver(this);
62 #if !defined(OS_CHROMEOS) 81 #if !defined(OS_CHROMEOS)
63 net::NetworkChangeNotifier::AddNetworkChangeObserver(this); 82 net::NetworkChangeNotifier::AddNetworkChangeObserver(this);
64 #else 83 #else
65 // UserManager may not exist in unit_tests. 84 // UserManager may not exist in unit_tests.
66 if (!user_manager::UserManager::IsInitialized()) 85 if (!user_manager::UserManager::IsInitialized())
67 return; 86 return;
68 87
69 const user_manager::User* user = 88 const user_manager::User* user =
70 chromeos::ProfileHelper::Get()->GetUserByProfile(profile_); 89 chromeos::ProfileHelper::Get()->GetUserByProfile(profile_);
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 GetProfileAttributesStorage(). 192 GetProfileAttributesStorage().
174 GetProfileAttributesWithPath(profile_->GetPath(), &entry); 193 GetProfileAttributesWithPath(profile_->GetPath(), &entry);
175 194
176 // If sign out occurs because Sync setup was in progress and the Profile got 195 // If sign out occurs because Sync setup was in progress and the Profile got
177 // deleted, then the profile's no longer in the ProfileAttributesStorage. 196 // deleted, then the profile's no longer in the ProfileAttributesStorage.
178 if (!has_entry) 197 if (!has_entry)
179 return; 198 return;
180 199
181 entry->SetLocalAuthCredentials(std::string()); 200 entry->SetLocalAuthCredentials(std::string());
182 entry->SetAuthInfo(std::string(), base::string16()); 201 entry->SetAuthInfo(std::string(), base::string16());
183 entry->SetIsSigninRequired(false); 202 entry->SetIsSigninRequired(false);
Roger Tawa OOO till Jul 10th 2016/11/02 13:20:39 Can we call LockProfile() from here to reduce code
zmin 2016/11/02 20:30:22 OnSignedOut is not always called during signout. F
184 } 203 }
185 204
186 net::URLRequestContextGetter* ChromeSigninClient::GetURLRequestContext() { 205 net::URLRequestContextGetter* ChromeSigninClient::GetURLRequestContext() {
187 return profile_->GetRequestContext(); 206 return profile_->GetRequestContext();
188 } 207 }
189 208
190 bool ChromeSigninClient::ShouldMergeSigninCredentialsIntoCookieJar() { 209 bool ChromeSigninClient::ShouldMergeSigninCredentialsIntoCookieJar() {
191 return !switches::IsEnableAccountConsistency(); 210 return !switches::IsEnableAccountConsistency();
192 } 211 }
193 212
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 void ChromeSigninClient::PostSignedIn(const std::string& account_id, 272 void ChromeSigninClient::PostSignedIn(const std::string& account_id,
254 const std::string& username, 273 const std::string& username,
255 const std::string& password) { 274 const std::string& password) {
256 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) 275 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
257 // Don't store password hash except when lock is available for the user. 276 // Don't store password hash except when lock is available for the user.
258 if (!password.empty() && profiles::IsLockAvailable(profile_)) 277 if (!password.empty() && profiles::IsLockAvailable(profile_))
259 LocalAuth::SetLocalAuthCredentials(profile_, password); 278 LocalAuth::SetLocalAuthCredentials(profile_, password);
260 #endif 279 #endif
261 } 280 }
262 281
282 void ChromeSigninClient::PreSignOut(const base::Callback<void()>& sign_out) {
283 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
284 if (is_force_signin_enabled_ && !profile_->IsSystemProfile() &&
285 !profile_->IsGuestSession()) {
286 BrowserList::CloseAllBrowsersWithProfile(
287 profile_, base::Bind(&ChromeSigninClient::OnCloseBrowsersSuccess,
288 base::Unretained(this), sign_out),
289 base::Bind(&OnCloseBrowsersAborted));
290 } else {
291 #else
292 {
293 #endif
294 SigninClient::PreSignOut(sign_out);
295 }
296 }
297
263 void ChromeSigninClient::OnErrorChanged() { 298 void ChromeSigninClient::OnErrorChanged() {
264 // Some tests don't have a ProfileManager. 299 // Some tests don't have a ProfileManager.
265 if (g_browser_process->profile_manager() == nullptr) 300 if (g_browser_process->profile_manager() == nullptr)
266 return; 301 return;
267 302
268 ProfileAttributesEntry* entry; 303 ProfileAttributesEntry* entry;
269 304
270 if (!g_browser_process->profile_manager()->GetProfileAttributesStorage(). 305 if (!g_browser_process->profile_manager()->GetProfileAttributesStorage().
271 GetProfileAttributesWithPath(profile_->GetPath(), &entry)) { 306 GetProfileAttributesWithPath(profile_->GetPath(), &entry)) {
272 return; 307 return;
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 ProfileOAuth2TokenService* token_service = 413 ProfileOAuth2TokenService* token_service =
379 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); 414 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_);
380 OAuth2TokenService::ScopeSet scopes; 415 OAuth2TokenService::ScopeSet scopes;
381 scopes.insert(GaiaConstants::kGoogleUserInfoEmail); 416 scopes.insert(GaiaConstants::kGoogleUserInfoEmail);
382 oauth_request_ = token_service->StartRequest(account_id, scopes, this); 417 oauth_request_ = token_service->StartRequest(account_id, scopes, this);
383 } 418 }
384 } 419 }
385 } 420 }
386 #endif 421 #endif
387 } 422 }
423
424 void ChromeSigninClient::OnCredentialsBeingCopied() {
425 if (is_force_signin_enabled_)
426 // The signout after credential copy won't open UserManager after all
427 // browser window are closed. Because the browser window will be opened for
428 // the new profile soon.
429 is_user_manager_displayed_ = false;
Roger Tawa OOO till Jul 10th 2016/11/02 13:20:39 Nit: since comment is below the if() statement, I'
zmin 2016/11/02 20:30:22 Done.
430 }
431
432 void ChromeSigninClient::OnCloseBrowsersSuccess(
433 const base::Callback<void()>& sign_out,
434 const base::FilePath& profile_path) {
435 SigninClient::PreSignOut(sign_out);
436
437 // After sign out, lock the profile and show UserManager if necessary.
438 LockProfile(profile_path);
439 if (is_user_manager_displayed_) {
440 ShowUserManager(profile_path);
441 } else {
442 is_user_manager_displayed_ = true;
Roger Tawa OOO till Jul 10th 2016/11/02 13:20:39 Maybe this member could be renamed should_display_
zmin 2016/11/02 20:30:22 Done. Good point. Because displaying UserManager
443 }
444 }
445
446 void ChromeSigninClient::LockProfile(const base::FilePath& profile_path) {
447 ProfileAttributesEntry* entry;
448 bool has_entry = g_browser_process->profile_manager()
449 ->GetProfileAttributesStorage()
450 .GetProfileAttributesWithPath(profile_path, &entry);
451 DCHECK(has_entry);
452 entry->SetIsSigninRequired(true);
453 }
454
455 void ChromeSigninClient::ShowUserManager(const base::FilePath& profile_path) {
456 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
457 UserManager::Show(profile_path, profiles::USER_MANAGER_NO_TUTORIAL,
458 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION);
459 #endif
460 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698