| 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 "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/guid.h" | 8 #include "base/guid.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/content_settings/cookie_settings.h" | 12 #include "chrome/browser/content_settings/cookie_settings.h" |
| 13 #include "chrome/browser/net/chrome_cookie_notification_details.h" | 13 #include "chrome/browser/net/chrome_cookie_notification_details.h" |
| 14 #include "chrome/browser/profiles/profile_info_cache.h" | 14 #include "chrome/browser/profiles/profile_info_cache.h" |
| 15 #include "chrome/browser/profiles/profile_manager.h" | 15 #include "chrome/browser/profiles/profile_manager.h" |
| 16 #include "chrome/browser/profiles/profile_metrics.h" | 16 #include "chrome/browser/profiles/profile_metrics.h" |
| 17 #include "chrome/browser/profiles/profile_window.h" | 17 #include "chrome/browser/profiles/profile_window.h" |
| 18 #include "chrome/browser/signin/local_auth.h" | 18 #include "chrome/browser/signin/local_auth.h" |
| 19 #include "chrome/browser/signin/signin_cookie_changed_subscription.h" | 19 #include "chrome/browser/signin/signin_cookie_changed_subscription.h" |
| 20 #include "chrome/browser/webdata/web_data_service_factory.h" | 20 #include "chrome/browser/webdata/web_data_service_factory.h" |
| 21 #include "chrome/common/chrome_version_info.h" | 21 #include "chrome/common/chrome_version_info.h" |
| 22 #include "components/metrics/metrics_service.h" | 22 #include "components/metrics/metrics_service.h" |
| 23 #include "components/signin/core/common/profile_management_switches.h" | 23 #include "components/signin/core/common/profile_management_switches.h" |
| 24 #include "components/signin/core/common/signin_pref_names.h" | 24 #include "components/signin/core/common/signin_pref_names.h" |
| 25 #include "components/signin/core/common/signin_switches.h" | 25 #include "components/signin/core/common/signin_switches.h" |
| 26 #include "content/public/browser/render_process_host.h" | |
| 27 #include "content/public/common/child_process_host.h" | |
| 28 #include "net/url_request/url_request_context_getter.h" | 26 #include "net/url_request/url_request_context_getter.h" |
| 29 #include "url/gurl.h" | 27 #include "url/gurl.h" |
| 30 | 28 |
| 31 #if defined(ENABLE_SUPERVISED_USERS) | 29 #if defined(ENABLE_SUPERVISED_USERS) |
| 32 #include "chrome/browser/supervised_user/supervised_user_constants.h" | 30 #include "chrome/browser/supervised_user/supervised_user_constants.h" |
| 33 #endif | 31 #endif |
| 34 | 32 |
| 35 #if defined(OS_CHROMEOS) | 33 #if defined(OS_CHROMEOS) |
| 36 #include "components/user_manager/user_manager.h" | 34 #include "components/user_manager/user_manager.h" |
| 37 #endif | 35 #endif |
| 38 | 36 |
| 39 #if !defined(OS_ANDROID) | 37 #if !defined(OS_ANDROID) |
| 40 #include "chrome/browser/first_run/first_run.h" | 38 #include "chrome/browser/first_run/first_run.h" |
| 41 #endif | 39 #endif |
| 42 | 40 |
| 43 using content::ChildProcessHost; | |
| 44 using content::RenderProcessHost; | |
| 45 | |
| 46 namespace { | 41 namespace { |
| 47 | 42 |
| 48 const char kGoogleAccountsUrl[] = "https://accounts.google.com"; | 43 const char kGoogleAccountsUrl[] = "https://accounts.google.com"; |
| 49 | 44 |
| 50 } // namespace | 45 } // namespace |
| 51 | 46 |
| 52 ChromeSigninClient::ChromeSigninClient( | 47 ChromeSigninClient::ChromeSigninClient( |
| 53 Profile* profile, SigninErrorController* signin_error_controller) | 48 Profile* profile, SigninErrorController* signin_error_controller) |
| 54 : profile_(profile), | 49 : profile_(profile), |
| 55 signin_error_controller_(signin_error_controller), | 50 signin_error_controller_(signin_error_controller) { |
| 56 signin_host_id_(ChildProcessHost::kInvalidUniqueID) { | |
| 57 signin_error_controller_->AddObserver(this); | 51 signin_error_controller_->AddObserver(this); |
| 58 } | 52 } |
| 59 | 53 |
| 60 ChromeSigninClient::~ChromeSigninClient() { | 54 ChromeSigninClient::~ChromeSigninClient() { |
| 61 signin_error_controller_->RemoveObserver(this); | 55 signin_error_controller_->RemoveObserver(this); |
| 62 std::set<RenderProcessHost*>::iterator i; | |
| 63 for (i = signin_hosts_observed_.begin(); i != signin_hosts_observed_.end(); | |
| 64 ++i) { | |
| 65 (*i)->RemoveObserver(this); | |
| 66 } | |
| 67 } | 56 } |
| 68 | 57 |
| 69 // static | 58 // static |
| 70 bool ChromeSigninClient::ProfileAllowsSigninCookies(Profile* profile) { | 59 bool ChromeSigninClient::ProfileAllowsSigninCookies(Profile* profile) { |
| 71 CookieSettings* cookie_settings = | 60 CookieSettings* cookie_settings = |
| 72 CookieSettings::Factory::GetForProfile(profile).get(); | 61 CookieSettings::Factory::GetForProfile(profile).get(); |
| 73 return SettingsAllowSigninCookies(cookie_settings); | 62 return SettingsAllowSigninCookies(cookie_settings); |
| 74 } | 63 } |
| 75 | 64 |
| 76 // static | 65 // static |
| 77 bool ChromeSigninClient::SettingsAllowSigninCookies( | 66 bool ChromeSigninClient::SettingsAllowSigninCookies( |
| 78 CookieSettings* cookie_settings) { | 67 CookieSettings* cookie_settings) { |
| 79 return cookie_settings && | 68 return cookie_settings && |
| 80 cookie_settings->IsSettingCookieAllowed(GURL(kGoogleAccountsUrl), | 69 cookie_settings->IsSettingCookieAllowed(GURL(kGoogleAccountsUrl), |
| 81 GURL(kGoogleAccountsUrl)); | 70 GURL(kGoogleAccountsUrl)); |
| 82 } | 71 } |
| 83 | 72 |
| 84 void ChromeSigninClient::SetSigninProcess(int process_id) { | |
| 85 if (process_id == signin_host_id_) | |
| 86 return; | |
| 87 DLOG_IF(WARNING, signin_host_id_ != ChildProcessHost::kInvalidUniqueID) | |
| 88 << "Replacing in-use signin process."; | |
| 89 signin_host_id_ = process_id; | |
| 90 RenderProcessHost* host = RenderProcessHost::FromID(process_id); | |
| 91 DCHECK(host); | |
| 92 host->AddObserver(this); | |
| 93 signin_hosts_observed_.insert(host); | |
| 94 } | |
| 95 | |
| 96 void ChromeSigninClient::ClearSigninProcess() { | |
| 97 signin_host_id_ = ChildProcessHost::kInvalidUniqueID; | |
| 98 } | |
| 99 | |
| 100 bool ChromeSigninClient::IsSigninProcess(int process_id) const { | |
| 101 return process_id != ChildProcessHost::kInvalidUniqueID && | |
| 102 process_id == signin_host_id_; | |
| 103 } | |
| 104 | |
| 105 bool ChromeSigninClient::HasSigninProcess() const { | |
| 106 return signin_host_id_ != ChildProcessHost::kInvalidUniqueID; | |
| 107 } | |
| 108 | |
| 109 void ChromeSigninClient::RenderProcessHostDestroyed(RenderProcessHost* host) { | |
| 110 // It's possible we're listening to a "stale" renderer because it was replaced | |
| 111 // with a new process by process-per-site. In either case, stop observing it, | |
| 112 // but only reset signin_host_id_ tracking if this was from the current signin | |
| 113 // process. | |
| 114 signin_hosts_observed_.erase(host); | |
| 115 if (signin_host_id_ == host->GetID()) | |
| 116 signin_host_id_ = ChildProcessHost::kInvalidUniqueID; | |
| 117 } | |
| 118 | |
| 119 PrefService* ChromeSigninClient::GetPrefs() { return profile_->GetPrefs(); } | 73 PrefService* ChromeSigninClient::GetPrefs() { return profile_->GetPrefs(); } |
| 120 | 74 |
| 121 scoped_refptr<TokenWebData> ChromeSigninClient::GetDatabase() { | 75 scoped_refptr<TokenWebData> ChromeSigninClient::GetDatabase() { |
| 122 return WebDataServiceFactory::GetTokenWebDataForProfile( | 76 return WebDataServiceFactory::GetTokenWebDataForProfile( |
| 123 profile_, ServiceAccessType::EXPLICIT_ACCESS); | 77 profile_, ServiceAccessType::EXPLICIT_ACCESS); |
| 124 } | 78 } |
| 125 | 79 |
| 126 bool ChromeSigninClient::CanRevokeCredentials() { | 80 bool ChromeSigninClient::CanRevokeCredentials() { |
| 127 #if defined(OS_CHROMEOS) | 81 #if defined(OS_CHROMEOS) |
| 128 // UserManager may not exist in unit_tests. | 82 // UserManager may not exist in unit_tests. |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 | 216 |
| 263 ProfileInfoCache& cache = g_browser_process->profile_manager()-> | 217 ProfileInfoCache& cache = g_browser_process->profile_manager()-> |
| 264 GetProfileInfoCache(); | 218 GetProfileInfoCache(); |
| 265 size_t index = cache.GetIndexOfProfileWithPath(profile_->GetPath()); | 219 size_t index = cache.GetIndexOfProfileWithPath(profile_->GetPath()); |
| 266 if (index == std::string::npos) | 220 if (index == std::string::npos) |
| 267 return; | 221 return; |
| 268 | 222 |
| 269 cache.SetProfileIsAuthErrorAtIndex(index, | 223 cache.SetProfileIsAuthErrorAtIndex(index, |
| 270 signin_error_controller_->HasError()); | 224 signin_error_controller_->HasError()); |
| 271 } | 225 } |
| OLD | NEW |