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

Unified Diff: chrome/browser/chromeos/settings/device_oauth2_token_service.cc

Issue 892633003: Do not announce robot account token before account ID is available (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/settings/device_oauth2_token_service.cc
diff --git a/chrome/browser/chromeos/settings/device_oauth2_token_service.cc b/chrome/browser/chromeos/settings/device_oauth2_token_service.cc
index 041ccb6a9b8eea2dce489baf3e4c81cf4c115b26..baf6b8052317a6ce264af7b471860968ea4130d9 100644
--- a/chrome/browser/chromeos/settings/device_oauth2_token_service.cc
+++ b/chrome/browser/chromeos/settings/device_oauth2_token_service.cc
@@ -8,16 +8,17 @@
#include <vector>
#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "base/memory/weak_ptr.h"
#include "base/message_loop/message_loop.h"
#include "base/prefs/pref_registry_simple.h"
#include "base/prefs/pref_service.h"
#include "base/values.h"
#include "chrome/browser/browser_process.h"
-#include "chrome/browser/chromeos/settings/cros_settings.h"
#include "chrome/browser/chromeos/settings/token_encryptor.h"
#include "chrome/common/pref_names.h"
#include "chromeos/cryptohome/system_salt_getter.h"
+#include "chromeos/settings/cros_settings_names.h"
#include "google_apis/gaia/gaia_constants.h"
#include "google_apis/gaia/gaia_urls.h"
#include "google_apis/gaia/google_service_auth_error.h"
@@ -42,6 +43,11 @@ struct DeviceOAuth2TokenService::PendingRequest {
const ScopeSet scopes;
};
+void DeviceOAuth2TokenService::OnServiceAccountIdentityChanged() {
+ if (!GetRobotAccountId().empty() && !refresh_token_.empty())
+ FireRefreshTokenAvailable(GetRobotAccountId());
+}
+
DeviceOAuth2TokenService::DeviceOAuth2TokenService(
net::URLRequestContextGetter* getter,
PrefService* local_state)
@@ -49,6 +55,12 @@ DeviceOAuth2TokenService::DeviceOAuth2TokenService(
local_state_(local_state),
state_(STATE_LOADING),
max_refresh_token_validation_retries_(3),
+ service_account_identity_subscription_(
+ CrosSettings::Get()->AddSettingsObserver(
+ kServiceAccountIdentity,
+ base::Bind(
+ &DeviceOAuth2TokenService::OnServiceAccountIdentityChanged,
+ base::Unretained(this))).Pass()),
weak_ptr_factory_(this) {
// Pull in the system salt.
SystemSaltGetter::Get()->GetSystemSalt(
@@ -75,7 +87,11 @@ void DeviceOAuth2TokenService::SetAndSaveRefreshToken(
bool waiting_for_salt = state_ == STATE_LOADING;
refresh_token_ = refresh_token;
state_ = STATE_VALIDATION_PENDING;
- FireRefreshTokenAvailable(GetRobotAccountId());
+
+ // We cannot announce the token yet because that requires us to also know the
+ // robot account ID, which is not available yet. It will be done from
+ // OnServiceAccountIdentityChanged() once the robot account ID becomes
+ // available.
xiyuan 2015/01/30 18:37:03 Should we call OnServiceAccountIdentityChanged her
bartfab (slow) 2015/02/02 21:01:07 Done.
token_save_callbacks_.push_back(result_callback);
if (!waiting_for_salt) {

Powered by Google App Engine
This is Rietveld 408576698