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

Side by Side Diff: blimp/client/core/session/identity_source.cc

Issue 2391263005: Propagate error messages to UI for blimp. (Closed)
Patch Set: Minor fixes. Created 4 years, 2 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "blimp/client/core/session/identity_source.h" 5 #include "blimp/client/core/session/identity_source.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "blimp/client/core/switches/blimp_client_switches.h" 9 #include "blimp/client/core/switches/blimp_client_switches.h"
10 10
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kEngineIP)) { 49 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kEngineIP)) {
50 if (token_callback_) { 50 if (token_callback_) {
51 token_callback_.Run(std::string()); 51 token_callback_.Run(std::string());
52 } 52 }
53 return; 53 return;
54 } 54 }
55 55
56 // User must sign in first to get an OAuth2 token. 56 // User must sign in first to get an OAuth2 token.
57 const std::string& account_id = identity_provider_->GetActiveAccountId(); 57 const std::string& account_id = identity_provider_->GetActiveAccountId();
58 if (account_id.empty()) { 58 if (account_id.empty()) {
59 delegate_->OnAuthenticationError( 59 VLOG(1) << "User is not signed in before connection to Blimp engine.";
60 BlimpClientContextDelegate::AuthError::NOT_SIGNED_IN);
61 return; 60 return;
62 } 61 }
63 62
64 account_id_ = account_id; 63 account_id_ = account_id;
65 is_fetching_token_ = true; 64 is_fetching_token_ = true;
66 FetchAuthToken(); 65 FetchAuthToken();
67 } 66 }
68 67
69 // Add sign in state observer. 68 // Add sign in state observer.
70 void IdentitySource::AddObserver(IdentityProvider::Observer* observer) { 69 void IdentitySource::AddObserver(IdentityProvider::Observer* observer) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 << retry_times_; 108 << retry_times_;
110 FetchAuthToken(); 109 FetchAuthToken();
111 return; 110 return;
112 } 111 }
113 112
114 // If request failure was not caused by cancellation, or reached max retry 113 // If request failure was not caused by cancellation, or reached max retry
115 // times on request cancellation, propagate the error to embedder. 114 // times on request cancellation, propagate the error to embedder.
116 is_fetching_token_ = false; 115 is_fetching_token_ = false;
117 retry_times_ = 0; 116 retry_times_ = 0;
118 VLOG(1) << "OAuth2 token error: " << error.state(); 117 VLOG(1) << "OAuth2 token error: " << error.state();
118
119 // Propagate the error.
119 DCHECK(delegate_); 120 DCHECK(delegate_);
120 delegate_->OnAuthenticationError( 121 delegate_->OnAuthenticationError(error);
121 BlimpClientContextDelegate::AuthError::OAUTH_TOKEN_FAIL);
122 } 122 }
123 123
124 void IdentitySource::OnRefreshTokenAvailable(const std::string& account_id) { 124 void IdentitySource::OnRefreshTokenAvailable(const std::string& account_id) {
125 if (account_id != account_id_) { 125 if (account_id != account_id_) {
126 return; 126 return;
127 } 127 }
128 128
129 identity_provider_->RemoveActiveAccountRefreshTokenObserver(this); 129 identity_provider_->RemoveActiveAccountRefreshTokenObserver(this);
130 FetchAuthToken(); 130 FetchAuthToken();
131 } 131 }
132 132
133 void IdentitySource::FetchAuthToken() { 133 void IdentitySource::FetchAuthToken() {
134 OAuth2TokenService* token_service = identity_provider_->GetTokenService(); 134 OAuth2TokenService* token_service = identity_provider_->GetTokenService();
135 DCHECK(token_service); 135 DCHECK(token_service);
136 136
137 if (token_service->RefreshTokenIsAvailable(account_id_)) { 137 if (token_service->RefreshTokenIsAvailable(account_id_)) {
138 OAuth2TokenService::ScopeSet scopes; 138 OAuth2TokenService::ScopeSet scopes;
139 scopes.insert(kOAuth2TokenScope); 139 scopes.insert(kOAuth2TokenScope);
140 token_request_ = token_service->StartRequest(account_id_, scopes, this); 140 token_request_ = token_service->StartRequest(account_id_, scopes, this);
141 } else { 141 } else {
142 identity_provider_->AddActiveAccountRefreshTokenObserver(this); 142 identity_provider_->AddActiveAccountRefreshTokenObserver(this);
143 } 143 }
144 } 144 }
145 145
146 } // namespace client 146 } // namespace client
147 } // namespace blimp 147 } // namespace blimp
OLDNEW
« no previous file with comments | « blimp/client/core/context/blimp_client_context_impl.cc ('k') | blimp/client/core/session/identity_source_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698