| OLD | NEW |
| 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 "chrome/browser/content_settings/cookie_settings.h" | 7 #include "chrome/browser/content_settings/cookie_settings.h" |
| 8 #include "chrome/browser/signin/local_auth.h" | 8 #include "chrome/browser/signin/local_auth.h" |
| 9 #include "chrome/browser/webdata/web_data_service_factory.h" | 9 #include "chrome/browser/webdata/web_data_service_factory.h" |
| 10 #include "chrome/common/profile_management_switches.h" | 10 #include "chrome/common/profile_management_switches.h" |
| 11 #include "content/public/browser/render_process_host.h" |
| 12 #include "content/public/common/child_process_host.h" |
| 11 #include "url/gurl.h" | 13 #include "url/gurl.h" |
| 12 | 14 |
| 13 #if defined(ENABLE_MANAGED_USERS) | 15 #if defined(ENABLE_MANAGED_USERS) |
| 14 #include "chrome/browser/managed_mode/managed_user_constants.h" | 16 #include "chrome/browser/managed_mode/managed_user_constants.h" |
| 15 #endif | 17 #endif |
| 16 | 18 |
| 17 #if defined(OS_CHROMEOS) | 19 #if defined(OS_CHROMEOS) |
| 18 #include "chrome/browser/chromeos/login/user_manager.h" | 20 #include "chrome/browser/chromeos/login/user_manager.h" |
| 19 #endif | 21 #endif |
| 20 | 22 |
| 23 using content::ChildProcessHost; |
| 24 using content::RenderProcessHost; |
| 25 |
| 21 namespace { | 26 namespace { |
| 22 | 27 |
| 23 const char kGoogleAccountsUrl[] = "https://accounts.google.com"; | 28 const char kGoogleAccountsUrl[] = "https://accounts.google.com"; |
| 24 | 29 |
| 25 } // namespace | 30 } // namespace |
| 26 | 31 |
| 27 ChromeSigninClient::ChromeSigninClient(Profile* profile) : profile_(profile) {} | 32 ChromeSigninClient::ChromeSigninClient(Profile* profile) |
| 33 : profile_(profile), signin_host_id_(ChildProcessHost::kInvalidUniqueID) {} |
| 28 | 34 |
| 29 ChromeSigninClient::~ChromeSigninClient() {} | 35 ChromeSigninClient::~ChromeSigninClient() { |
| 36 std::set<RenderProcessHost*>::iterator i; |
| 37 for (i = signin_hosts_observed_.begin(); i != signin_hosts_observed_.end(); |
| 38 ++i) { |
| 39 (*i)->RemoveObserver(this); |
| 40 } |
| 41 } |
| 30 | 42 |
| 31 // static | 43 // static |
| 32 bool ChromeSigninClient::ProfileAllowsSigninCookies(Profile* profile) { | 44 bool ChromeSigninClient::ProfileAllowsSigninCookies(Profile* profile) { |
| 33 CookieSettings* cookie_settings = | 45 CookieSettings* cookie_settings = |
| 34 CookieSettings::Factory::GetForProfile(profile).get(); | 46 CookieSettings::Factory::GetForProfile(profile).get(); |
| 35 return SettingsAllowSigninCookies(cookie_settings); | 47 return SettingsAllowSigninCookies(cookie_settings); |
| 36 } | 48 } |
| 37 | 49 |
| 38 // static | 50 // static |
| 39 bool ChromeSigninClient::SettingsAllowSigninCookies( | 51 bool ChromeSigninClient::SettingsAllowSigninCookies( |
| 40 CookieSettings* cookie_settings) { | 52 CookieSettings* cookie_settings) { |
| 41 return cookie_settings && | 53 return cookie_settings && |
| 42 cookie_settings->IsSettingCookieAllowed(GURL(kGoogleAccountsUrl), | 54 cookie_settings->IsSettingCookieAllowed(GURL(kGoogleAccountsUrl), |
| 43 GURL(kGoogleAccountsUrl)); | 55 GURL(kGoogleAccountsUrl)); |
| 44 } | 56 } |
| 45 | 57 |
| 58 void ChromeSigninClient::SetSigninProcess(int process_id) { |
| 59 if (process_id == signin_host_id_) |
| 60 return; |
| 61 DLOG_IF(WARNING, signin_host_id_ != ChildProcessHost::kInvalidUniqueID) |
| 62 << "Replacing in-use signin process."; |
| 63 signin_host_id_ = process_id; |
| 64 RenderProcessHost* host = RenderProcessHost::FromID(process_id); |
| 65 DCHECK(host); |
| 66 host->AddObserver(this); |
| 67 signin_hosts_observed_.insert(host); |
| 68 } |
| 69 |
| 70 void ChromeSigninClient::ClearSigninProcess() { |
| 71 signin_host_id_ = ChildProcessHost::kInvalidUniqueID; |
| 72 } |
| 73 |
| 74 bool ChromeSigninClient::IsSigninProcess(int process_id) const { |
| 75 return process_id == signin_host_id_; |
| 76 } |
| 77 |
| 78 bool ChromeSigninClient::HasSigninProcess() const { |
| 79 return signin_host_id_ != ChildProcessHost::kInvalidUniqueID; |
| 80 } |
| 81 |
| 82 void ChromeSigninClient::RenderProcessHostDestroyed(RenderProcessHost* host) { |
| 83 // It's possible we're listening to a "stale" renderer because it was replaced |
| 84 // with a new process by process-per-site. In either case, stop observing it, |
| 85 // but only reset signin_host_id_ tracking if this was from the current signin |
| 86 // process. |
| 87 signin_hosts_observed_.erase(host); |
| 88 if (signin_host_id_ == host->GetID()) |
| 89 signin_host_id_ = ChildProcessHost::kInvalidUniqueID; |
| 90 } |
| 91 |
| 46 PrefService* ChromeSigninClient::GetPrefs() { return profile_->GetPrefs(); } | 92 PrefService* ChromeSigninClient::GetPrefs() { return profile_->GetPrefs(); } |
| 47 | 93 |
| 48 scoped_refptr<TokenWebData> ChromeSigninClient::GetDatabase() { | 94 scoped_refptr<TokenWebData> ChromeSigninClient::GetDatabase() { |
| 49 return WebDataServiceFactory::GetTokenWebDataForProfile( | 95 return WebDataServiceFactory::GetTokenWebDataForProfile( |
| 50 profile_, Profile::EXPLICIT_ACCESS); | 96 profile_, Profile::EXPLICIT_ACCESS); |
| 51 } | 97 } |
| 52 | 98 |
| 53 bool ChromeSigninClient::CanRevokeCredentials() { | 99 bool ChromeSigninClient::CanRevokeCredentials() { |
| 54 #if defined(OS_CHROMEOS) | 100 #if defined(OS_CHROMEOS) |
| 55 // UserManager may not exist in unit_tests. | 101 // UserManager may not exist in unit_tests. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 78 } | 124 } |
| 79 | 125 |
| 80 void ChromeSigninClient::GoogleSigninSucceeded(const std::string& username, | 126 void ChromeSigninClient::GoogleSigninSucceeded(const std::string& username, |
| 81 const std::string& password) { | 127 const std::string& password) { |
| 82 #if !defined(OS_ANDROID) | 128 #if !defined(OS_ANDROID) |
| 83 // Don't store password hash except for users of new profile features. | 129 // Don't store password hash except for users of new profile features. |
| 84 if (switches::IsNewProfileManagement()) | 130 if (switches::IsNewProfileManagement()) |
| 85 chrome::SetLocalAuthCredentials(profile_, password); | 131 chrome::SetLocalAuthCredentials(profile_, password); |
| 86 #endif | 132 #endif |
| 87 } | 133 } |
| OLD | NEW |