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

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

Issue 1138143002: Pass Device ID in the oauth2/token request. Keep Device ID in local state on Chrome OS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added comment. Created 5 years, 7 months 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 "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"
(...skipping 15 matching lines...) Expand all
26 #include "google_apis/gaia/gaia_urls.h" 26 #include "google_apis/gaia/gaia_urls.h"
27 #include "net/url_request/url_request_context_getter.h" 27 #include "net/url_request/url_request_context_getter.h"
28 #include "url/gurl.h" 28 #include "url/gurl.h"
29 29
30 #if defined(ENABLE_SUPERVISED_USERS) 30 #if defined(ENABLE_SUPERVISED_USERS)
31 #include "chrome/browser/supervised_user/supervised_user_constants.h" 31 #include "chrome/browser/supervised_user/supervised_user_constants.h"
32 #endif 32 #endif
33 33
34 #if defined(OS_CHROMEOS) 34 #if defined(OS_CHROMEOS)
35 #include "chrome/browser/chromeos/net/delay_network_call.h" 35 #include "chrome/browser/chromeos/net/delay_network_call.h"
36 #include "chrome/browser/chromeos/profiles/profile_helper.h"
36 #include "components/user_manager/user_manager.h" 37 #include "components/user_manager/user_manager.h"
37 #endif 38 #endif
38 39
39 #if !defined(OS_ANDROID) 40 #if !defined(OS_ANDROID)
40 #include "chrome/browser/first_run/first_run.h" 41 #include "chrome/browser/first_run/first_run.h"
41 #endif 42 #endif
42 43
44 namespace {
45 const char kEphemeralUserDeviceIDPrefix[] = "t_";
46 }
47
43 ChromeSigninClient::ChromeSigninClient( 48 ChromeSigninClient::ChromeSigninClient(
44 Profile* profile, SigninErrorController* signin_error_controller) 49 Profile* profile, SigninErrorController* signin_error_controller)
45 : profile_(profile), 50 : profile_(profile),
46 signin_error_controller_(signin_error_controller) { 51 signin_error_controller_(signin_error_controller) {
47 signin_error_controller_->AddObserver(this); 52 signin_error_controller_->AddObserver(this);
48 #if !defined(OS_CHROMEOS) 53 #if !defined(OS_CHROMEOS)
49 net::NetworkChangeNotifier::AddNetworkChangeObserver(this); 54 net::NetworkChangeNotifier::AddNetworkChangeObserver(this);
55 #else
56 // UserManager may not exist in unit_tests.
57 if (!user_manager::UserManager::IsInitialized())
58 return;
59
60 const user_manager::User* user =
61 chromeos::ProfileHelper::Get()->GetUserByProfile(profile_);
62 if (!user)
63 return;
64 auto* user_manager = user_manager::UserManager::Get();
65 const std::string& user_id = user->GetUserID();
66 if (user_manager->GetKnownUserDeviceId(user_id).empty()) {
67 const std::string legacy_device_id =
68 GetPrefs()->GetString(prefs::kGoogleServicesSigninScopedDeviceId);
69 if (!legacy_device_id.empty()) {
70 // Need to move device ID from the old location to the new one, if it has
71 // not been done yet.
72 user_manager->SetKnownUserDeviceId(user_id, legacy_device_id);
73 } else {
74 user_manager->SetKnownUserDeviceId(
75 user_id,
76 GenerateSigninScopedDeviceID(
77 user_manager->IsUserNonCryptohomeDataEphemeral(user_id)));
78 }
79 }
80 GetPrefs()->SetString(prefs::kGoogleServicesSigninScopedDeviceId,
81 std::string());
50 #endif 82 #endif
51 } 83 }
52 84
53 ChromeSigninClient::~ChromeSigninClient() { 85 ChromeSigninClient::~ChromeSigninClient() {
54 signin_error_controller_->RemoveObserver(this); 86 signin_error_controller_->RemoveObserver(this);
55 } 87 }
56 88
57 void ChromeSigninClient::Shutdown() { 89 void ChromeSigninClient::Shutdown() {
58 #if !defined(OS_CHROMEOS) 90 #if !defined(OS_CHROMEOS)
59 net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this); 91 net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this);
(...skipping 10 matching lines...) Expand all
70 // static 102 // static
71 bool ChromeSigninClient::SettingsAllowSigninCookies( 103 bool ChromeSigninClient::SettingsAllowSigninCookies(
72 CookieSettings* cookie_settings) { 104 CookieSettings* cookie_settings) {
73 GURL gaia_url = GaiaUrls::GetInstance()->gaia_url(); 105 GURL gaia_url = GaiaUrls::GetInstance()->gaia_url();
74 GURL google_url = GaiaUrls::GetInstance()->google_url(); 106 GURL google_url = GaiaUrls::GetInstance()->google_url();
75 return cookie_settings && 107 return cookie_settings &&
76 cookie_settings->IsSettingCookieAllowed(gaia_url, gaia_url) && 108 cookie_settings->IsSettingCookieAllowed(gaia_url, gaia_url) &&
77 cookie_settings->IsSettingCookieAllowed(google_url, google_url); 109 cookie_settings->IsSettingCookieAllowed(google_url, google_url);
78 } 110 }
79 111
112 // static
113 std::string ChromeSigninClient::GenerateSigninScopedDeviceID(
114 bool for_ephemeral) {
115 std::string guid = base::GenerateGUID();
116 return for_ephemeral ? kEphemeralUserDeviceIDPrefix + guid : guid;
117 }
118
80 PrefService* ChromeSigninClient::GetPrefs() { return profile_->GetPrefs(); } 119 PrefService* ChromeSigninClient::GetPrefs() { return profile_->GetPrefs(); }
81 120
82 scoped_refptr<TokenWebData> ChromeSigninClient::GetDatabase() { 121 scoped_refptr<TokenWebData> ChromeSigninClient::GetDatabase() {
83 return WebDataServiceFactory::GetTokenWebDataForProfile( 122 return WebDataServiceFactory::GetTokenWebDataForProfile(
84 profile_, ServiceAccessType::EXPLICIT_ACCESS); 123 profile_, ServiceAccessType::EXPLICIT_ACCESS);
85 } 124 }
86 125
87 bool ChromeSigninClient::CanRevokeCredentials() { 126 bool ChromeSigninClient::CanRevokeCredentials() {
88 #if defined(OS_CHROMEOS) 127 #if defined(OS_CHROMEOS)
89 // UserManager may not exist in unit_tests. 128 // UserManager may not exist in unit_tests.
(...skipping 16 matching lines...) Expand all
106 #endif 145 #endif
107 return true; 146 return true;
108 } 147 }
109 148
110 std::string ChromeSigninClient::GetSigninScopedDeviceId() { 149 std::string ChromeSigninClient::GetSigninScopedDeviceId() {
111 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 150 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
112 switches::kDisableSigninScopedDeviceId)) { 151 switches::kDisableSigninScopedDeviceId)) {
113 return std::string(); 152 return std::string();
114 } 153 }
115 154
155 #if !defined(OS_CHROMEOS)
116 std::string signin_scoped_device_id = 156 std::string signin_scoped_device_id =
117 GetPrefs()->GetString(prefs::kGoogleServicesSigninScopedDeviceId); 157 GetPrefs()->GetString(prefs::kGoogleServicesSigninScopedDeviceId);
118 if (signin_scoped_device_id.empty()) { 158 if (signin_scoped_device_id.empty()) {
119 // If device_id doesn't exist then generate new and save in prefs. 159 // If device_id doesn't exist then generate new and save in prefs.
120 signin_scoped_device_id = base::GenerateGUID(); 160 signin_scoped_device_id = GenerateSigninScopedDeviceID(false);
121 DCHECK(!signin_scoped_device_id.empty()); 161 DCHECK(!signin_scoped_device_id.empty());
122 GetPrefs()->SetString(prefs::kGoogleServicesSigninScopedDeviceId, 162 GetPrefs()->SetString(prefs::kGoogleServicesSigninScopedDeviceId,
123 signin_scoped_device_id); 163 signin_scoped_device_id);
124 } 164 }
125 return signin_scoped_device_id; 165 return signin_scoped_device_id;
166 #else
167 // UserManager may not exist in unit_tests.
168 if (!user_manager::UserManager::IsInitialized())
169 return std::string();
170
171 const user_manager::User* user =
172 chromeos::ProfileHelper::Get()->GetUserByProfile(profile_);
173 if (!user)
174 return std::string();
175
176 const std::string signin_scoped_device_id =
177 user_manager::UserManager::Get()->GetKnownUserDeviceId(user->GetUserID());
178 LOG_IF(ERROR, signin_scoped_device_id.empty())
179 << "Device ID is not set for user.";
180 return signin_scoped_device_id;
181 #endif
126 } 182 }
127 183
128 void ChromeSigninClient::OnSignedOut() { 184 void ChromeSigninClient::OnSignedOut() {
129 GetPrefs()->ClearPref(prefs::kGoogleServicesSigninScopedDeviceId); 185 GetPrefs()->ClearPref(prefs::kGoogleServicesSigninScopedDeviceId);
130 ProfileInfoCache& cache = 186 ProfileInfoCache& cache =
131 g_browser_process->profile_manager()->GetProfileInfoCache(); 187 g_browser_process->profile_manager()->GetProfileInfoCache();
132 size_t index = cache.GetIndexOfProfileWithPath(profile_->GetPath()); 188 size_t index = cache.GetIndexOfProfileWithPath(profile_->GetPath());
133 189
134 // If sign out occurs because Sync setup was in progress and the Profile got 190 // If sign out occurs because Sync setup was in progress and the Profile got
135 // deleted, then the profile's no longer in the ProfileInfoCache. 191 // deleted, then the profile's no longer in the ProfileInfoCache.
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 return; 315 return;
260 #else 316 #else
261 // Don't bother if we don't have any kind of network connection. 317 // Don't bother if we don't have any kind of network connection.
262 if (net::NetworkChangeNotifier::IsOffline()) { 318 if (net::NetworkChangeNotifier::IsOffline()) {
263 delayed_callbacks_.push_back(callback); 319 delayed_callbacks_.push_back(callback);
264 } else { 320 } else {
265 callback.Run(); 321 callback.Run();
266 } 322 }
267 #endif 323 #endif
268 } 324 }
OLDNEW
« no previous file with comments | « chrome/browser/signin/chrome_signin_client.h ('k') | chrome/browser/ui/webui/chromeos/login/gaia_screen_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698