summaryrefslogtreecommitdiffstats
path: root/remoting/client
diff options
context:
space:
mode:
authorsergeyu <sergeyu@chromium.org>2016-03-09 18:59:14 -0800
committerCommit bot <commit-bot@chromium.org>2016-03-10 03:01:00 +0000
commit1acf67baf01cd3f0cf072c3136a0929bb953073c (patch)
treeb8124e8c04983ec09c921f87ad8852c6b1b4155a /remoting/client
parent3a80f8993c32aefb757e8e2ff5e1fcff3a9dbc32 (diff)
downloadchromium_src-1acf67baf01cd3f0cf072c3136a0929bb953073c.zip
chromium_src-1acf67baf01cd3f0cf072c3136a0929bb953073c.tar.gz
chromium_src-1acf67baf01cd3f0cf072c3136a0929bb953073c.tar.bz2
Replace ThirdPartyClientAuthenticator::TokenFetcher with a callback.
Callbacks are already used to fetch PIN. It doesn't make sense to use a different style to fetch third-party tokens. Review URL: https://codereview.chromium.org/1774113005 Cr-Commit-Position: refs/heads/master@{#380316}
Diffstat (limited to 'remoting/client')
-rw-r--r--remoting/client/jni/chromoting_jni_instance.cc39
-rw-r--r--remoting/client/jni/chromoting_jni_instance.h9
-rw-r--r--remoting/client/jni/chromoting_jni_runtime.cc5
-rw-r--r--remoting/client/jni/chromoting_jni_runtime.h2
-rw-r--r--remoting/client/plugin/chromoting_instance.cc27
-rw-r--r--remoting/client/plugin/chromoting_instance.h7
-rw-r--r--remoting/client/token_fetcher_proxy.cc38
-rw-r--r--remoting/client/token_fetcher_proxy.h49
8 files changed, 38 insertions, 138 deletions
diff --git a/remoting/client/jni/chromoting_jni_instance.cc b/remoting/client/jni/chromoting_jni_instance.cc
index 540c955..d1602110 100644
--- a/remoting/client/jni/chromoting_jni_instance.cc
+++ b/remoting/client/jni/chromoting_jni_instance.cc
@@ -10,6 +10,7 @@
#include <utility>
#include "base/bind.h"
+#include "base/callback_helpers.h"
#include "base/logging.h"
#include "jingle/glue/thread_wrapper.h"
#include "net/socket/client_socket_factory.h"
@@ -21,7 +22,6 @@
#include "remoting/client/jni/chromoting_jni_runtime.h"
#include "remoting/client/jni/jni_frame_consumer.h"
#include "remoting/client/software_video_renderer.h"
-#include "remoting/client/token_fetcher_proxy.h"
#include "remoting/protocol/chromium_port_allocator_factory.h"
#include "remoting/protocol/chromium_socket_factory.h"
#include "remoting/protocol/host_stub.h"
@@ -74,16 +74,12 @@ ChromotingJniInstance::ChromotingJniInstance(ChromotingJniRuntime* jni_runtime,
xmpp_config_.auth_token = auth_token;
// Initialize |authenticator_|.
- scoped_ptr<protocol::ThirdPartyClientAuthenticator::TokenFetcher>
- token_fetcher(new TokenFetcherProxy(
- base::Bind(&ChromotingJniInstance::FetchThirdPartyToken,
- weak_factory_.GetWeakPtr()),
- host_pubkey));
-
authenticator_.reset(new protocol::NegotiatingClientAuthenticator(
pairing_id, pairing_secret, host_id_,
- base::Bind(&ChromotingJniInstance::FetchSecret, this),
- std::move(token_fetcher)));
+ base::Bind(&ChromotingJniInstance::FetchSecret,
+ weak_factory_.GetWeakPtr()),
+ base::Bind(&ChromotingJniInstance::FetchThirdPartyToken,
+ weak_factory_.GetWeakPtr(), host_pubkey)));
// Post a task to start connection
jni_runtime_->network_task_runner()->PostTask(
@@ -128,25 +124,22 @@ void ChromotingJniInstance::Disconnect() {
}
void ChromotingJniInstance::FetchThirdPartyToken(
- const GURL& token_url,
- const std::string& client_id,
+ const std::string& host_public_key,
+ const std::string& token_url,
const std::string& scope,
- base::WeakPtr<TokenFetcherProxy> token_fetcher_proxy) {
+ const protocol::ThirdPartyTokenFetchedCallback& token_fetched_callback) {
DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread());
- DCHECK(!token_fetcher_proxy_.get());
+ DCHECK(third_party_token_fetched_callback_.is_null());
__android_log_print(ANDROID_LOG_INFO,
"ThirdPartyAuth",
"Fetching Third Party Token from user.");
- token_fetcher_proxy_ = token_fetcher_proxy;
+ third_party_token_fetched_callback_ = token_fetched_callback;
jni_runtime_->ui_task_runner()->PostTask(
- FROM_HERE,
- base::Bind(&ChromotingJniRuntime::FetchThirdPartyToken,
- base::Unretained(jni_runtime_),
- token_url,
- client_id,
- scope));
+ FROM_HERE, base::Bind(&ChromotingJniRuntime::FetchThirdPartyToken,
+ base::Unretained(jni_runtime_), token_url,
+ host_public_key, scope));
}
void ChromotingJniInstance::HandleOnThirdPartyTokenFetched(
@@ -157,9 +150,9 @@ void ChromotingJniInstance::HandleOnThirdPartyTokenFetched(
__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();
+ if (!third_party_token_fetched_callback_.is_null()) {
+ base::ResetAndReturn(&third_party_token_fetched_callback_)
+ .Run(token, shared_secret);
} else {
__android_log_print(
ANDROID_LOG_WARN,
diff --git a/remoting/client/jni/chromoting_jni_instance.h b/remoting/client/jni/chromoting_jni_instance.h
index e31bb28..9eab8d9 100644
--- a/remoting/client/jni/chromoting_jni_instance.h
+++ b/remoting/client/jni/chromoting_jni_instance.h
@@ -33,7 +33,6 @@ class VideoRenderer;
class ChromotingJniRuntime;
class ClientStatusLogger;
class JniFrameConsumer;
-class TokenFetcherProxy;
// ClientUserInterface that indirectly makes and receives JNI calls.
class ChromotingJniInstance
@@ -62,10 +61,10 @@ class ChromotingJniInstance
// Requests the android app to fetch a third-party token.
void FetchThirdPartyToken(
- const GURL& token_url,
- const std::string& client_id,
+ const std::string& host_public_key,
+ const std::string& token_url,
const std::string& scope,
- const base::WeakPtr<TokenFetcherProxy> token_fetcher_proxy);
+ const protocol::ThirdPartyTokenFetchedCallback& token_fetched_callback);
// Called by the android app when the token is fetched.
void HandleOnThirdPartyTokenFetched(const std::string& token,
@@ -163,7 +162,7 @@ class ChromotingJniInstance
XmppSignalStrategy::XmppServerConfig xmpp_config_;
scoped_ptr<XmppSignalStrategy> signaling_; // Must outlive client_
scoped_ptr<ClientStatusLogger> client_status_logger_;
- base::WeakPtr<TokenFetcherProxy> token_fetcher_proxy_;
+ protocol::ThirdPartyTokenFetchedCallback third_party_token_fetched_callback_;
// Pass this the user's PIN once we have it. To be assigned and accessed on
// the UI thread, but must be posted to the network thread to call it.
diff --git a/remoting/client/jni/chromoting_jni_runtime.cc b/remoting/client/jni/chromoting_jni_runtime.cc
index b1b36b7..37303b3 100644
--- a/remoting/client/jni/chromoting_jni_runtime.cc
+++ b/remoting/client/jni/chromoting_jni_runtime.cc
@@ -308,14 +308,13 @@ void ChromotingJniRuntime::CommitPairingCredentials(const std::string& host,
env, j_host.obj(), j_id.obj(), j_secret.obj());
}
-void ChromotingJniRuntime::FetchThirdPartyToken(const GURL& token_url,
+void ChromotingJniRuntime::FetchThirdPartyToken(const std::string& token_url,
const std::string& client_id,
const std::string& scope) {
DCHECK(ui_task_runner_->BelongsToCurrentThread());
JNIEnv* env = base::android::AttachCurrentThread();
- ScopedJavaLocalRef<jstring> j_url =
- ConvertUTF8ToJavaString(env, token_url.spec());
+ ScopedJavaLocalRef<jstring> j_url = ConvertUTF8ToJavaString(env, token_url);
ScopedJavaLocalRef<jstring> j_client_id =
ConvertUTF8ToJavaString(env, client_id);
ScopedJavaLocalRef<jstring> j_scope = ConvertUTF8ToJavaString(env, scope);
diff --git a/remoting/client/jni/chromoting_jni_runtime.h b/remoting/client/jni/chromoting_jni_runtime.h
index af2c409..b6128c1 100644
--- a/remoting/client/jni/chromoting_jni_runtime.h
+++ b/remoting/client/jni/chromoting_jni_runtime.h
@@ -88,7 +88,7 @@ class ChromotingJniRuntime {
// Pops up a third party login page to fetch token required for
// authentication. Call on UI thread.
- void FetchThirdPartyToken(const GURL& token_url,
+ void FetchThirdPartyToken(const std::string& token_url,
const std::string& client_id,
const std::string& scope);
diff --git a/remoting/client/plugin/chromoting_instance.cc b/remoting/client/plugin/chromoting_instance.cc
index 2b1974b..1365821 100644
--- a/remoting/client/plugin/chromoting_instance.cc
+++ b/remoting/client/plugin/chromoting_instance.cc
@@ -51,7 +51,6 @@
#include "remoting/client/plugin/pepper_video_renderer_2d.h"
#include "remoting/client/plugin/pepper_video_renderer_3d.h"
#include "remoting/client/software_video_renderer.h"
-#include "remoting/client/token_fetcher_proxy.h"
#include "remoting/proto/control.pb.h"
#include "remoting/protocol/connection_to_host.h"
#include "remoting/protocol/host_stub.h"
@@ -461,17 +460,17 @@ void ChromotingInstance::OnConnectionState(
}
void ChromotingInstance::FetchThirdPartyToken(
- const GURL& token_url,
const std::string& host_public_key,
+ const std::string& token_url,
const std::string& scope,
- base::WeakPtr<TokenFetcherProxy> token_fetcher_proxy) {
+ const protocol::ThirdPartyTokenFetchedCallback& token_fetched_callback) {
// Once the Session object calls this function, it won't continue the
// authentication until the callback is called (or connection is canceled).
// So, it's impossible to reach this with a callback already registered.
- DCHECK(!token_fetcher_proxy_.get());
- token_fetcher_proxy_ = token_fetcher_proxy;
+ DCHECK(third_party_token_fetched_callback_.is_null());
+ third_party_token_fetched_callback_ = token_fetched_callback;
scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue());
- data->SetString("tokenUrl", token_url.spec());
+ data->SetString("tokenUrl", token_url);
data->SetString("hostPublicKey", host_public_key);
data->SetString("scope", scope);
PostLegacyJsonMessage("fetchThirdPartyToken", std::move(data));
@@ -697,16 +696,14 @@ void ChromotingInstance::HandleConnect(const base::DictionaryValue& data) {
protocol::TransportRole::CLIENT));
// Create Authenticator.
- scoped_ptr<protocol::ThirdPartyClientAuthenticator::TokenFetcher>
- token_fetcher(new TokenFetcherProxy(
- base::Bind(&ChromotingInstance::FetchThirdPartyToken,
- weak_factory_.GetWeakPtr()),
- host_public_key));
+ protocol::FetchThirdPartyTokenCallback fetch_third_party_token_callback =
+ base::Bind(&ChromotingInstance::FetchThirdPartyToken,
+ weak_factory_.GetWeakPtr(), host_public_key);
scoped_ptr<protocol::Authenticator> authenticator(
new protocol::NegotiatingClientAuthenticator(
client_pairing_id, client_paired_secret, authentication_tag,
- fetch_secret_callback, std::move(token_fetcher)));
+ fetch_secret_callback, fetch_third_party_token_callback));
scoped_ptr<protocol::CandidateSessionConfig> config =
protocol::CandidateSessionConfig::CreateDefault();
@@ -910,9 +907,9 @@ void ChromotingInstance::HandleOnThirdPartyTokenFetched(
LOG(ERROR) << "Invalid onThirdPartyTokenFetched data.";
return;
}
- if (token_fetcher_proxy_.get()) {
- token_fetcher_proxy_->OnTokenFetched(token, shared_secret);
- token_fetcher_proxy_.reset();
+ if (!third_party_token_fetched_callback_.is_null()) {
+ base::ResetAndReturn(&third_party_token_fetched_callback_)
+ .Run(token, shared_secret);
} else {
LOG(WARNING) << "Ignored OnThirdPartyTokenFetched without a pending fetch.";
}
diff --git a/remoting/client/plugin/chromoting_instance.h b/remoting/client/plugin/chromoting_instance.h
index 52b6efd..7b91854 100644
--- a/remoting/client/plugin/chromoting_instance.h
+++ b/remoting/client/plugin/chromoting_instance.h
@@ -66,7 +66,6 @@ class ClientContext;
class DelegatingSignalStrategy;
class PepperAudioPlayer;
class PepperMouseLocker;
-class TokenFetcherProxy;
class ChromotingInstance : public ClientUserInterface,
public PepperVideoRenderer::EventHandler,
@@ -162,10 +161,10 @@ class ChromotingInstance : public ClientUserInterface,
// Requests the webapp to fetch a third-party token.
void FetchThirdPartyToken(
- const GURL& token_url,
const std::string& host_public_key,
+ const std::string& token_url,
const std::string& scope,
- const base::WeakPtr<TokenFetcherProxy> pepper_token_fetcher);
+ const protocol::ThirdPartyTokenFetchedCallback& token_fetched_callback);
// Updates the specified UMA enumeration histogram with the input value.
void UpdateUmaEnumHistogram(const std::string& histogram_name,
@@ -283,7 +282,7 @@ class ChromotingInstance : public ClientUserInterface,
bool use_async_pin_dialog_;
protocol::SecretFetchedCallback secret_fetched_callback_;
- base::WeakPtr<TokenFetcherProxy> token_fetcher_proxy_;
+ protocol::ThirdPartyTokenFetchedCallback third_party_token_fetched_callback_;
base::RepeatingTimer stats_update_timer_;
diff --git a/remoting/client/token_fetcher_proxy.cc b/remoting/client/token_fetcher_proxy.cc
deleted file mode 100644
index 1079290..0000000
--- a/remoting/client/token_fetcher_proxy.cc
+++ /dev/null
@@ -1,38 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "remoting/client/token_fetcher_proxy.h"
-
-#include "base/callback_helpers.h"
-
-namespace remoting {
-
-TokenFetcherProxy::TokenFetcherProxy(
- const TokenFetcherCallback& token_fetcher_impl,
- const std::string& host_public_key)
- : host_public_key_(host_public_key),
- token_fetcher_impl_(token_fetcher_impl),
- weak_factory_(this) {
-}
-
-TokenFetcherProxy::~TokenFetcherProxy() {
-}
-
-void TokenFetcherProxy::FetchThirdPartyToken(
- const GURL& token_url,
- const std::string& scope,
- const TokenFetchedCallback& token_fetched_callback) {
- token_fetched_callback_ = token_fetched_callback;
- token_fetcher_impl_.Run(
- token_url, host_public_key_, scope, weak_factory_.GetWeakPtr());
-}
-
-void TokenFetcherProxy::OnTokenFetched(
- const std::string& token, const std::string& shared_secret) {
- if (!token_fetched_callback_.is_null()) {
- base::ResetAndReturn(&token_fetched_callback_).Run(token, shared_secret);
- }
-}
-
-} // namespace remoting
diff --git a/remoting/client/token_fetcher_proxy.h b/remoting/client/token_fetcher_proxy.h
deleted file mode 100644
index 17916ce..0000000
--- a/remoting/client/token_fetcher_proxy.h
+++ /dev/null
@@ -1,49 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef REMOTING_CLIENT_TOKEN_FETCHER_PROXY_H_
-#define REMOTING_CLIENT_TOKEN_FETCHER_PROXY_H_
-
-#include "base/callback.h"
-#include "base/macros.h"
-#include "base/memory/weak_ptr.h"
-#include "remoting/protocol/third_party_client_authenticator.h"
-
-namespace remoting {
-
-class TokenFetcherProxy
- : public protocol::ThirdPartyClientAuthenticator::TokenFetcher {
- public:
- typedef base::Callback<void(
- const GURL& token_url,
- const std::string& host_public_key,
- const std::string& scope,
- base::WeakPtr<TokenFetcherProxy>)> TokenFetcherCallback;
-
- TokenFetcherProxy(const TokenFetcherCallback& token_fetcher_impl,
- const std::string& host_public_key);
- ~TokenFetcherProxy() override;
-
- // protocol::TokenClientAuthenticator::TokenFetcher interface.
- void FetchThirdPartyToken(
- const GURL& token_url,
- const std::string& scope,
- const TokenFetchedCallback& token_fetched_callback) override;
-
- // Called by the token fetching implementation when the token is fetched.
- void OnTokenFetched(const std::string& token,
- const std::string& shared_secret);
-
- private:
- std::string host_public_key_;
- TokenFetcherCallback token_fetcher_impl_;
- TokenFetchedCallback token_fetched_callback_;
- base::WeakPtrFactory<TokenFetcherProxy> weak_factory_;
-
- DISALLOW_COPY_AND_ASSIGN(TokenFetcherProxy);
-};
-
-} // namespace remoting
-
-#endif // REMOTING_CLIENT_TOKEN_FETCHER_PROXY_H_