You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.6 KiB
42 lines
1.6 KiB
// Copyright 2018 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 "mojo/public/cpp/system/isolated_connection.h"
|
|
|
|
#include "mojo/public/cpp/platform/platform_channel.h"
|
|
#include "mojo/public/cpp/system/invitation.h"
|
|
|
|
namespace mojo {
|
|
|
|
IsolatedConnection::IsolatedConnection()
|
|
: token_(base::UnguessableToken::Create()) {}
|
|
|
|
IsolatedConnection::~IsolatedConnection() {
|
|
// We send a dummy invitation over a temporary channel, re-using |token_| as
|
|
// the name. This ensures that the connection set up by Connect(), if any,
|
|
// will be replaced with a short-lived, self-terminating connection.
|
|
//
|
|
// This is a bit of a hack since Mojo does not provide any API for explicitly
|
|
// terminating isolated connections, but this is a decision made to minimize
|
|
// the API surface dedicated to isolated connections in anticipation of the
|
|
// concept being deprecated eventually.
|
|
PlatformChannel channel;
|
|
OutgoingInvitation::SendIsolated(channel.TakeLocalEndpoint(),
|
|
token_.ToString());
|
|
}
|
|
|
|
ScopedMessagePipeHandle IsolatedConnection::Connect(
|
|
PlatformChannelEndpoint endpoint) {
|
|
return OutgoingInvitation::SendIsolated(std::move(endpoint),
|
|
token_.ToString());
|
|
}
|
|
|
|
ScopedMessagePipeHandle IsolatedConnection::Connect(
|
|
PlatformChannelServerEndpoint endpoint) {
|
|
return OutgoingInvitation::SendIsolated(std::move(endpoint),
|
|
token_.ToString());
|
|
}
|
|
|
|
} // namespace mojo
|