| Index: mojo/shell/public/cpp/lib/shell_connection.cc
|
| diff --git a/mojo/shell/public/cpp/lib/shell_connection.cc b/mojo/shell/public/cpp/lib/shell_connection.cc
|
| index e14cc77e59308d71fbfcbfc924c43b3d24160722..5977cc64a9f1be90a37145f983a3a009b49c1db6 100644
|
| --- a/mojo/shell/public/cpp/lib/shell_connection.cc
|
| +++ b/mojo/shell/public/cpp/lib/shell_connection.cc
|
| @@ -2,9 +2,6 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include <algorithm>
|
| -#include <utility>
|
| -
|
| #include "base/bind.h"
|
| #include "base/logging.h"
|
| #include "base/message_loop/message_loop.h"
|
| @@ -17,65 +14,6 @@
|
|
|
| namespace mojo {
|
|
|
| -class AppRefCountImpl : public AppRefCount {
|
| - public:
|
| - AppRefCountImpl(ShellConnection* connection,
|
| - scoped_refptr<base::SingleThreadTaskRunner> app_task_runner)
|
| - : connection_(connection),
|
| - app_task_runner_(app_task_runner) {}
|
| - ~AppRefCountImpl() override {
|
| -#ifndef NDEBUG
|
| - // Ensure that this object is used on only one thread at a time, or else
|
| - // there could be races where the object is being reset on one thread and
|
| - // cloned on another.
|
| - if (clone_task_runner_)
|
| - DCHECK(clone_task_runner_->BelongsToCurrentThread());
|
| -#endif
|
| -
|
| - if (app_task_runner_->BelongsToCurrentThread()) {
|
| - connection_->Release();
|
| - } else {
|
| - app_task_runner_->PostTask(
|
| - FROM_HERE,
|
| - base::Bind(&ShellConnection::Release, base::Unretained(connection_)));
|
| - }
|
| - }
|
| -
|
| - private:
|
| - // AppRefCount:
|
| - scoped_ptr<AppRefCount> Clone() override {
|
| - if (app_task_runner_->BelongsToCurrentThread()) {
|
| - connection_->AddRef();
|
| - } else {
|
| - app_task_runner_->PostTask(
|
| - FROM_HERE,
|
| - base::Bind(&ShellConnection::AddRef, base::Unretained(connection_)));
|
| - }
|
| -
|
| -#ifndef NDEBUG
|
| - // Ensure that this object is used on only one thread at a time, or else
|
| - // there could be races where the object is being reset on one thread and
|
| - // cloned on another.
|
| - if (clone_task_runner_) {
|
| - DCHECK(clone_task_runner_->BelongsToCurrentThread());
|
| - } else {
|
| - clone_task_runner_ = base::MessageLoop::current()->task_runner();
|
| - }
|
| -#endif
|
| -
|
| - return make_scoped_ptr(new AppRefCountImpl(connection_, app_task_runner_));
|
| - }
|
| -
|
| - ShellConnection* connection_;
|
| - scoped_refptr<base::SingleThreadTaskRunner> app_task_runner_;
|
| -
|
| -#ifndef NDEBUG
|
| - scoped_refptr<base::SingleThreadTaskRunner> clone_task_runner_;
|
| -#endif
|
| -
|
| - DISALLOW_COPY_AND_ASSIGN(AppRefCountImpl);
|
| -};
|
| -
|
| ////////////////////////////////////////////////////////////////////////////////
|
| // ShellConnection, public:
|
|
|
| @@ -84,7 +22,6 @@ ShellConnection::ShellConnection(
|
| InterfaceRequest<shell::mojom::ShellClient> request)
|
| : client_(client),
|
| binding_(this, std::move(request)),
|
| - ref_count_(0),
|
| weak_factory_(this) {}
|
|
|
| ShellConnection::~ShellConnection() {}
|
| @@ -95,36 +32,6 @@ void ShellConnection::WaitForInitialize() {
|
| }
|
|
|
| ////////////////////////////////////////////////////////////////////////////////
|
| -// ShellConnection, Shell implementation:
|
| -
|
| -scoped_ptr<Connection> ShellConnection::Connect(const std::string& url) {
|
| - return connector_->Connect(url);
|
| -}
|
| -
|
| -scoped_ptr<Connection> ShellConnection::Connect(
|
| - Connector::ConnectParams* params) {
|
| - return connector_->Connect(params);
|
| -}
|
| -
|
| -scoped_ptr<Connector> ShellConnection::CloneConnector() const {
|
| - return connector_->Clone();
|
| -}
|
| -
|
| -scoped_ptr<AppRefCount> ShellConnection::CreateAppRefCount() {
|
| - AddRef();
|
| - return make_scoped_ptr(
|
| - new AppRefCountImpl(this, base::MessageLoop::current()->task_runner()));
|
| -}
|
| -
|
| -void ShellConnection::Quit() {
|
| - client_->Quit();
|
| - if (base::MessageLoop::current() &&
|
| - base::MessageLoop::current()->is_running()) {
|
| - base::MessageLoop::current()->QuitWhenIdle();
|
| - }
|
| -}
|
| -
|
| -////////////////////////////////////////////////////////////////////////////////
|
| // ShellConnection, shell::mojom::ShellClient implementation:
|
|
|
| void ShellConnection::Initialize(shell::mojom::ConnectorPtr connector,
|
| @@ -135,7 +42,7 @@ void ShellConnection::Initialize(shell::mojom::ConnectorPtr connector,
|
| std::move(connector),
|
| base::Bind(&ShellConnection::OnConnectionError,
|
| weak_factory_.GetWeakPtr())));
|
| - client_->Initialize(this, url, id, user_id);
|
| + client_->Initialize(connector_.get(), url, id, user_id);
|
| }
|
|
|
| void ShellConnection::AcceptConnection(
|
| @@ -162,27 +69,12 @@ void ShellConnection::AcceptConnection(
|
| // ShellConnection, private:
|
|
|
| void ShellConnection::OnConnectionError() {
|
| - base::WeakPtr<ShellConnection> ptr(weak_factory_.GetWeakPtr());
|
| -
|
| // We give the client notice first, since it might want to do something on
|
| // shell connection errors other than immediate termination of the run
|
| // loop. The application might want to continue servicing connections other
|
| // than the one to the shell.
|
| - bool quit_now = client_->ShellConnectionLost();
|
| - if (quit_now)
|
| - Quit();
|
| - if (!ptr)
|
| - return;
|
| - connector_.reset();
|
| -}
|
| -
|
| -void ShellConnection::AddRef() {
|
| - ++ref_count_;
|
| -}
|
| -
|
| -void ShellConnection::Release() {
|
| - if (!--ref_count_)
|
| - Quit();
|
| + if (client_->ShellConnectionLost())
|
| + connector_.reset();
|
| }
|
|
|
| } // namespace mojo
|
|
|