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

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: Comments addressed. 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
43 ChromeSigninClient::ChromeSigninClient( 44 ChromeSigninClient::ChromeSigninClient(
44 Profile* profile, SigninErrorController* signin_error_controller) 45 Profile* profile, SigninErrorController* signin_error_controller)
45 : profile_(profile), 46 : profile_(profile),
46 signin_error_controller_(signin_error_controller) { 47 signin_error_controller_(signin_error_controller) {
47 signin_error_controller_->AddObserver(this); 48 signin_error_controller_->AddObserver(this);
48 #if !defined(OS_CHROMEOS) 49 #if !defined(OS_CHROMEOS)
49 net::NetworkChangeNotifier::AddNetworkChangeObserver(this); 50 net::NetworkChangeNotifier::AddNetworkChangeObserver(this);
51 #else
52 // UserManager may not exist in unit_tests.
53 if (!user_manager::UserManager::IsInitialized())
54 return;
55
56 const user_manager::User* user =
57 chromeos::ProfileHelper::Get()->GetUserByProfile(profile_);
58 if (!user)
59 return;
60
61 // Need to move device ID from the old location to the new one, if it has not
62 // been done yet.
63 const std::string legacy_device_id =
64 GetPrefs()->GetString(prefs::kGoogleServicesSigninScopedDeviceId);
65 auto* user_manager = user_manager::UserManager::Get();
66 if (!legacy_device_id.empty() &&
67 user_manager->GetKnownUserDeviceId(user->GetUserID()).empty()) {
68 user_manager->SetKnownUserDeviceId(user->GetUserID(), legacy_device_id);
69 }
70 GetPrefs()->SetString(prefs::kGoogleServicesSigninScopedDeviceId,
71 std::string());
50 #endif 72 #endif
51 } 73 }
52 74
53 ChromeSigninClient::~ChromeSigninClient() { 75 ChromeSigninClient::~ChromeSigninClient() {
54 signin_error_controller_->RemoveObserver(this); 76 signin_error_controller_->RemoveObserver(this);
55 } 77 }
56 78
57 void ChromeSigninClient::Shutdown() { 79 void ChromeSigninClient::Shutdown() {
58 #if !defined(OS_CHROMEOS) 80 #if !defined(OS_CHROMEOS)
59 net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this); 81 net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 #endif 128 #endif
107 return true; 129 return true;
108 } 130 }
109 131
110 std::string ChromeSigninClient::GetSigninScopedDeviceId() { 132 std::string ChromeSigninClient::GetSigninScopedDeviceId() {
111 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 133 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
112 switches::kDisableSigninScopedDeviceId)) { 134 switches::kDisableSigninScopedDeviceId)) {
113 return std::string(); 135 return std::string();
114 } 136 }
115 137
138 #if !defined(OS_CHROMEOS)
116 std::string signin_scoped_device_id = 139 std::string signin_scoped_device_id =
117 GetPrefs()->GetString(prefs::kGoogleServicesSigninScopedDeviceId); 140 GetPrefs()->GetString(prefs::kGoogleServicesSigninScopedDeviceId);
118 if (signin_scoped_device_id.empty()) { 141 if (signin_scoped_device_id.empty()) {
119 // If device_id doesn't exist then generate new and save in prefs. 142 // If device_id doesn't exist then generate new and save in prefs.
120 signin_scoped_device_id = base::GenerateGUID(); 143 signin_scoped_device_id = base::GenerateGUID();
121 DCHECK(!signin_scoped_device_id.empty()); 144 DCHECK(!signin_scoped_device_id.empty());
122 GetPrefs()->SetString(prefs::kGoogleServicesSigninScopedDeviceId, 145 GetPrefs()->SetString(prefs::kGoogleServicesSigninScopedDeviceId,
123 signin_scoped_device_id); 146 signin_scoped_device_id);
124 } 147 }
125 return signin_scoped_device_id; 148 return signin_scoped_device_id;
149 #else
150 // UserManager may not exist in unit_tests.
151 if (!user_manager::UserManager::IsInitialized())
152 return std::string();
153
154 const user_manager::User* user =
155 chromeos::ProfileHelper::Get()->GetUserByProfile(profile_);
156 if (!user)
157 return std::string();
158
159 const std::string signin_scoped_device_id =
160 user_manager::UserManager::Get()->GetKnownUserDeviceId(user->GetUserID());
161 if (signin_scoped_device_id.empty())
162 LOG(ERROR) << "Device ID is not set for user.";
xiyuan 2015/05/13 01:18:02 nit: LOG_IF(ERROR, signin_scoped_device_id.empty()
dzhioev (left Google) 2015/05/14 23:50:52 Done.
163 return signin_scoped_device_id;
164 #endif
126 } 165 }
127 166
128 void ChromeSigninClient::OnSignedOut() { 167 void ChromeSigninClient::OnSignedOut() {
129 GetPrefs()->ClearPref(prefs::kGoogleServicesSigninScopedDeviceId); 168 GetPrefs()->ClearPref(prefs::kGoogleServicesSigninScopedDeviceId);
130 ProfileInfoCache& cache = 169 ProfileInfoCache& cache =
131 g_browser_process->profile_manager()->GetProfileInfoCache(); 170 g_browser_process->profile_manager()->GetProfileInfoCache();
132 size_t index = cache.GetIndexOfProfileWithPath(profile_->GetPath()); 171 size_t index = cache.GetIndexOfProfileWithPath(profile_->GetPath());
133 172
134 // If sign out occurs because Sync setup was in progress and the Profile got 173 // 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. 174 // deleted, then the profile's no longer in the ProfileInfoCache.
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 return; 298 return;
260 #else 299 #else
261 // Don't bother if we don't have any kind of network connection. 300 // Don't bother if we don't have any kind of network connection.
262 if (net::NetworkChangeNotifier::IsOffline()) { 301 if (net::NetworkChangeNotifier::IsOffline()) {
263 delayed_callbacks_.push_back(callback); 302 delayed_callbacks_.push_back(callback);
264 } else { 303 } else {
265 callback.Run(); 304 callback.Run();
266 } 305 }
267 #endif 306 #endif
268 } 307 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698