| Index: mojo/public/cpp/bindings/lib/interface_ptr_state.cc
|
| diff --git a/mojo/public/cpp/bindings/lib/interface_ptr_state.cc b/mojo/public/cpp/bindings/lib/interface_ptr_state.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..8287736881360fb09fc5d3d060b9c92ca80d8a96
|
| --- /dev/null
|
| +++ b/mojo/public/cpp/bindings/lib/interface_ptr_state.cc
|
| @@ -0,0 +1,82 @@
|
| +// Copyright 2016 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/bindings/lib/interface_ptr_state.h"
|
| +
|
| +namespace mojo {
|
| +namespace internal {
|
| +
|
| +SimpleInterfacePtrState::SimpleInterfacePtrState()
|
| + : router_(nullptr), version_(0u) {}
|
| +
|
| +SimpleInterfacePtrState::~SimpleInterfacePtrState() {
|
| + delete router_;
|
| +}
|
| +
|
| +void SimpleInterfacePtrState::QueryVersion(
|
| + const base::Callback<void(uint32_t)>& callback) {
|
| + ConfigureProxyIfNecessary();
|
| +
|
| + // It is safe to capture |this| because the callback won't be run after this
|
| + // object goes away.
|
| + proxy()->QueryVersion(base::Bind(&SimpleInterfacePtrState::OnQueryVersion,
|
| + base::Unretained(this), callback));
|
| +}
|
| +
|
| +void SimpleInterfacePtrState::RequireVersion(uint32_t version) {
|
| + ConfigureProxyIfNecessary();
|
| +
|
| + if (version <= version_)
|
| + return;
|
| +
|
| + version_ = version;
|
| + proxy()->RequireVersion(version);
|
| +}
|
| +
|
| +bool SimpleInterfacePtrState::HasAssociatedInterfaces() const {
|
| + return false;
|
| +}
|
| +
|
| +void SimpleInterfacePtrState::EnableTestingMode() {
|
| + ConfigureProxyIfNecessary();
|
| + router_->EnableTestingMode();
|
| +}
|
| +
|
| +void SimpleInterfacePtrState::BindInternal(
|
| + InterfacePtrInfoBase* info,
|
| + scoped_refptr<base::SingleThreadTaskRunner> runner) {
|
| + DCHECK(!router_);
|
| + DCHECK(!handle_.is_valid());
|
| + DCHECK_EQ(0u, version_);
|
| + DCHECK(info->is_valid());
|
| +
|
| + handle_ = info->PassHandle();
|
| + version_ = info->version();
|
| + runner_ = std::move(runner);
|
| +}
|
| +
|
| +bool SimpleInterfacePtrState::ConfigureProxyIfNecessaryInternal(
|
| + const char* interface_name) {
|
| + // The object hasn't been bound.
|
| + if (!handle_.is_valid())
|
| + return false;
|
| +
|
| + FilterChain filters;
|
| + filters.Append<MessageHeaderValidator>(interface_name);
|
| + filters.Append(CreateRequestValidator());
|
| +
|
| + router_ = new Router(std::move(handle_), std::move(filters), false,
|
| + std::move(runner_));
|
| + return true;
|
| +}
|
| +
|
| +void SimpleInterfacePtrState::OnQueryVersion(
|
| + const base::Callback<void(uint32_t)>& callback,
|
| + uint32_t version) {
|
| + version_ = version;
|
| + callback.Run(version);
|
| +}
|
| +
|
| +} // namespace internal
|
| +} // namespace mojo
|
|
|