Index: remoting/client/jni/chromoting_jni_instance.cc |
diff --git a/remoting/client/jni/chromoting_jni_instance.cc b/remoting/client/jni/chromoting_jni_instance.cc |
index efe2ea5a5887c41813c19af1698129b2cff7543b..9a929dd037318dba87a1ce9c0bdee721afb416b9 100644 |
--- a/remoting/client/jni/chromoting_jni_instance.cc |
+++ b/remoting/client/jni/chromoting_jni_instance.cc |
@@ -48,7 +48,8 @@ ChromotingJniInstance::ChromotingJniInstance(ChromotingJniRuntime* jni_runtime, |
: jni_runtime_(jni_runtime), |
host_id_(host_id), |
create_pairing_(false), |
- stats_logging_enabled_(false) { |
+ stats_logging_enabled_(false), |
+ weak_factory_(this) { |
DCHECK(jni_runtime_->ui_task_runner()->BelongsToCurrentThread()); |
// Intialize XMPP config. |
@@ -110,9 +111,41 @@ void ChromotingJniInstance::FetchThirdPartyToken( |
const GURL& token_url, |
const std::string& client_id, |
const std::string& scope, |
- base::WeakPtr<TokenFetcherProxy> jni_token_fetcher) { |
- // TODO(kelvinp) Calls into the jni_runtime_ to obtain a token from the |
- // android app (Android Third Party Auth - Part II). |
+ base::WeakPtr<TokenFetcherProxy> token_fetcher_proxy) { |
+ DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread()); |
+ DCHECK(!token_fetcher_proxy_.get()); |
+ |
+ __android_log_print(ANDROID_LOG_INFO, |
+ "ThirdPartyAuth", |
+ "Fetching Third Party Token from user."); |
+ |
+ token_fetcher_proxy_ = token_fetcher_proxy; |
+ jni_runtime_->ui_task_runner()->PostTask( |
+ FROM_HERE, |
+ base::Bind(&ChromotingJniRuntime::FetchThirdPartyToken, |
+ base::Unretained(jni_runtime_), |
+ token_url, |
+ client_id, |
+ scope)); |
+} |
+ |
+void ChromotingJniInstance::HandleOnThirdPartyTokenFetched( |
+ const std::string& token, |
+ const std::string& shared_secret) { |
+ DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread()); |
+ |
+ __android_log_print( |
+ ANDROID_LOG_INFO, "ThirdPartyAuth", "Third Party Token Fetched."); |
+ |
+ if (token_fetcher_proxy_.get()) { |
+ token_fetcher_proxy_->OnTokenFetched(token, shared_secret); |
+ token_fetcher_proxy_.reset(); |
+ } else { |
+ __android_log_print( |
+ ANDROID_LOG_WARN, |
+ "ThirdPartyAuth", |
+ "Ignored OnThirdPartyTokenFetched() without a pending fetch."); |
+ } |
} |
void ChromotingJniInstance::ProvideSecret(const std::string& pin, |
@@ -286,8 +319,11 @@ protocol::CursorShapeStub* ChromotingJniInstance::GetCursorShapeStub() { |
scoped_ptr<protocol::ThirdPartyClientAuthenticator::TokenFetcher> |
ChromotingJniInstance::GetTokenFetcher(const std::string& host_public_key) { |
- // Return null to indicate that third-party authentication is unsupported. |
- return scoped_ptr<protocol::ThirdPartyClientAuthenticator::TokenFetcher>(); |
+ return scoped_ptr<protocol::ThirdPartyClientAuthenticator::TokenFetcher>( |
+ new TokenFetcherProxy( |
+ base::Bind(&ChromotingJniInstance::FetchThirdPartyToken, |
+ weak_factory_.GetWeakPtr()), |
+ host_public_key)); |
} |
void ChromotingJniInstance::InjectClipboardEvent( |