Commit 6ecbaf9d authored by kmarshall's avatar kmarshall Committed by Commit bot

Blimp: relocate thread-unsafe member getter in DropConnection code.

There is logic in the ClientSession/ClientContext which attempts
to drop a connection on the IO thread. Unfortunately, in doing so,
it called a thread-unsafe member getter within the call to PostTask.

This CL moves the getter into a helper method which runs entirely
on the IO thread.

R=nyquist@chromium.org,wez@chromium.org
CC=steimel@chromium.org
BUG=647814

Review-Url: https://codereview.chromium.org/2344893009
Cr-Commit-Position: refs/heads/master@{#419491}
parent 8d286e55
......@@ -38,8 +38,14 @@ namespace blimp {
namespace client {
namespace {
const char kDefaultAssignerUrl[] =
"https://blimp-pa.googleapis.com/v1/assignment";
void DropConnectionOnIOThread(ClientNetworkComponents* net_components) {
net_components->GetBrowserConnectionHandler()->DropCurrentConnection();
}
} // namespace
// This function is declared in //blimp/client/public/blimp_client_context.h,
......@@ -226,6 +232,11 @@ void BlimpClientContextImpl::InitializeSettings() {
settings_feature_->SetRecordWholeDocument(true);
}
void BlimpClientContextImpl::DropConnection() {
io_thread_task_runner_->PostTask(
FROM_HERE, base::Bind(&DropConnectionOnIOThread, net_components_.get()));
}
void BlimpClientContextImpl::CreateIdentitySource() {
identity_source_ = base::MakeUnique<IdentitySource>(
delegate_, base::Bind(&BlimpClientContextImpl::OnAuthTokenReceived,
......@@ -234,11 +245,7 @@ void BlimpClientContextImpl::CreateIdentitySource() {
void BlimpClientContextImpl::OnImageDecodeError() {
// Currently we just drop the connection on image decoding error.
io_thread_task_runner_->PostTask(
FROM_HERE,
base::Bind(
&BrowserConnectionHandler::DropCurrentConnection,
base::Unretained(net_components_->GetBrowserConnectionHandler())));
DropConnection();
}
} // namespace client
......
......@@ -84,6 +84,10 @@ class BlimpClientContextImpl
void RegisterFeatures();
void InitializeSettings();
// Terminates the active connection held by |net_connections_|.
// May be called on any thread.
void DropConnection();
// Create IdentitySource which provides user sign in states and OAuth2 token
// service.
void CreateIdentitySource();
......
......@@ -13,6 +13,7 @@
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/sequenced_task_runner.h"
#include "base/task_runner_util.h"
#include "base/threading/sequenced_task_runner_handle.h"
#include "base/threading/thread.h"
#include "base/threading/thread_task_runner_handle.h"
......@@ -37,6 +38,13 @@
namespace blimp {
namespace client {
namespace {
void DropConnectionOnIOThread(ClientNetworkComponents* net_components) {
net_components->GetBrowserConnectionHandler()->DropCurrentConnection();
}
} // namespace
BlimpClientSession::BlimpClientSession(const GURL& assigner_endpoint)
: io_thread_("BlimpIOThread"),
......@@ -149,16 +157,17 @@ void BlimpClientSession::RegisterFeatures() {
settings_feature_->SetRecordWholeDocument(true);
}
void BlimpClientSession::DropConnection() {
io_thread_.task_runner()->PostTask(
FROM_HERE, base::Bind(&DropConnectionOnIOThread, net_components_.get()));
}
void BlimpClientSession::OnConnected() {}
void BlimpClientSession::OnDisconnected(int result) {}
void BlimpClientSession::OnImageDecodeError() {
io_thread_.task_runner()->PostTask(
FROM_HERE,
base::Bind(
&BrowserConnectionHandler::DropCurrentConnection,
base::Unretained(net_components_->GetBrowserConnectionHandler())));
DropConnection();
}
TabControlFeature* BlimpClientSession::GetTabControlFeature() const {
......
......@@ -86,6 +86,10 @@ class BlimpClientSession
private:
void RegisterFeatures();
// Terminates the active connection held by |net_connections_| on the IO
// thread. Should be called on the main thread.
void DropConnection();
// NetworkEventObserver implementation.
void OnConnected() override;
void OnDisconnected(int result) override;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment