Commit 3ecf8289 authored by erg@chromium.org's avatar erg@chromium.org

mojo: Make InterfacePtr<> testable in if() statements without .get().

This also goes and changes a lot of "if (obj.get())" to "if (obj)".

BUG=394639

Review URL: https://codereview.chromium.org/405653003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@284269 0039d316-1c4b-4281-b951-d872f2087c98
parent 1f6c86af
......@@ -72,7 +72,7 @@ class NestingApp : public ApplicationDelegate,
connection->ConnectToService(&window_manager_);
connection->AddService<Navigator>(this);
// TODO(davemoore): Is this ok?
if (!navigator_.get()) {
if (!navigator_) {
connection->ConnectToApplication(
kEmbeddedAppURL)->ConnectToService(&navigator_);
}
......
......@@ -464,7 +464,7 @@ class WindowManager : public ApplicationDelegate,
navigation::NavigationDetailsPtr nav_details,
navigation::ResponseDetailsPtr response) {
node->Embed(app_url);
if (nav_details.get()) {
if (nav_details) {
navigation::NavigatorPtr navigator;
app_->ConnectToService(app_url, &navigator);
navigator->Navigate(node->id(), nav_details.Pass(), response.Pass());
......
......@@ -288,7 +288,7 @@ void CommandBufferClientImpl::MakeProgressAndUpdateState() {
command_buffer_->MakeProgress(last_state_.get_offset);
CommandBufferStatePtr state = sync_client_impl_->WaitForProgress();
if (!state.get()) {
if (!state) {
VLOG(1) << "Channel encountered error while waiting for command buffer";
// TODO(piman): is it ok for this to re-enter?
DidDestroy();
......
......@@ -102,6 +102,16 @@ class InterfacePtr {
return &internal_state_;
}
// Allow InterfacePtr<> to be used in boolean expressions, but not
// implicitly convertible to a real bool (which is dangerous).
private:
typedef internal::InterfacePtrState<Interface> InterfacePtr::*Testable;
public:
operator Testable() const {
return internal_state_.is_bound() ? &InterfacePtr::internal_state_ : NULL;
}
private:
typedef internal::InterfacePtrState<Interface> State;
mutable State internal_state_;
......
......@@ -69,6 +69,10 @@ class InterfacePtrState {
return handle_.Pass();
}
bool is_bound() const {
return handle_.is_valid() || router_;
}
void set_client(typename Interface::Client* client) {
ConfigureProxyIfNecessary();
......
......@@ -94,7 +94,7 @@ class SampleFactoryImpl : public InterfaceImpl<sample::Factory> {
response->pipe = pipe0.Pass();
client()->DidStuff(response.Pass(), text1);
if (request->obj.get())
if (request->obj)
request->obj->DoSomething();
}
......@@ -335,14 +335,14 @@ TEST_F(HandlePassingTest, CreateNamedObject) {
BindToProxy(new SampleFactoryImpl(), &factory);
sample::NamedObjectPtr object1;
EXPECT_FALSE(object1.get());
EXPECT_FALSE(object1);
InterfaceRequest<sample::NamedObject> object1_request = Get(&object1);
EXPECT_TRUE(object1_request.is_pending());
factory->CreateNamedObject(object1_request.Pass());
EXPECT_FALSE(object1_request.is_pending()); // We've passed the request.
ASSERT_TRUE(object1.get());
ASSERT_TRUE(object1);
object1->SetName("object1");
sample::NamedObjectPtr object2;
......
......@@ -252,19 +252,19 @@ TEST_F(InterfacePtrTest, Movable) {
math::CalculatorPtr b;
BindToProxy(new MathCalculatorImpl(), &b);
EXPECT_TRUE(!a.get());
EXPECT_FALSE(!b.get());
EXPECT_TRUE(!a);
EXPECT_FALSE(!b);
a = b.Pass();
EXPECT_FALSE(!a.get());
EXPECT_TRUE(!b.get());
EXPECT_FALSE(!a);
EXPECT_TRUE(!b);
}
TEST_F(InterfacePtrTest, Resettable) {
math::CalculatorPtr a;
EXPECT_TRUE(!a.get());
EXPECT_TRUE(!a);
MessagePipe pipe;
......@@ -273,11 +273,11 @@ TEST_F(InterfacePtrTest, Resettable) {
a = MakeProxy<math::Calculator>(pipe.handle0.Pass());
EXPECT_FALSE(!a.get());
EXPECT_FALSE(!a);
a.reset();
EXPECT_TRUE(!a.get());
EXPECT_TRUE(!a);
EXPECT_FALSE(a.internal_state()->router_for_testing());
// Test that handle was closed.
......
......@@ -52,7 +52,7 @@ CommandBufferImpl::CommandBufferImpl(gfx::AcceleratedWidget widget,
CommandBufferImpl::~CommandBufferImpl() {
client()->DidDestroy();
if (decoder_.get()) {
if (decoder_) {
bool have_context = decoder_->MakeCurrent();
decoder_->Destroy(have_context);
}
......@@ -130,7 +130,7 @@ bool CommandBufferImpl::DoInitialize(
const size_t kSize = sizeof(gpu::CommandBufferSharedState);
scoped_ptr<gpu::BufferBacking> backing(
gles2::MojoBufferBacking::Create(shared_state.Pass(), kSize));
if (!backing.get())
if (!backing)
return false;
command_buffer_->SetSharedStateBuffer(backing.Pass());
......@@ -159,7 +159,7 @@ void CommandBufferImpl::RegisterTransferBuffer(
// This validates the size.
scoped_ptr<gpu::BufferBacking> backing(
gles2::MojoBufferBacking::Create(transfer_buffer.Pass(), size));
if (!backing.get()) {
if (!backing) {
DVLOG(0) << "Failed to map shared memory.";
return;
}
......
......@@ -83,7 +83,7 @@ class HTMLViewer : public ApplicationDelegate,
}
void MaybeLoad() {
if (document_view_ && response_.get())
if (document_view_ && response_)
document_view_->Load(response_.Pass());
}
......
......@@ -73,7 +73,7 @@ class NativeViewportImpl
virtual void CreateGLES2Context(
InterfaceRequest<CommandBuffer> command_buffer_request) OVERRIDE {
if (command_buffer_.get() || command_buffer_request_.is_pending()) {
if (command_buffer_ || command_buffer_request_.is_pending()) {
LOG(ERROR) << "Can't create multiple contexts on a NativeViewport";
return;
}
......
......@@ -44,7 +44,7 @@ void ViewManagerInitServiceImpl::MaybeEmbedRoot(
void ViewManagerInitServiceImpl::EmbedRoot(
const String& url,
const Callback<void(bool)>& callback) {
if (connect_params_.get()) {
if (connect_params_) {
DVLOG(1) << "Ignoring second connect";
callback.Run(false);
return;
......@@ -58,7 +58,7 @@ void ViewManagerInitServiceImpl::EmbedRoot(
void ViewManagerInitServiceImpl::OnRootViewManagerWindowTreeHostCreated() {
DCHECK(!is_tree_host_ready_);
is_tree_host_ready_ = true;
if (connect_params_.get())
if (connect_params_)
MaybeEmbedRoot(connect_params_->url, connect_params_->callback);
}
......
......@@ -167,7 +167,7 @@ void DynamicServiceLoader::LoadService(ServiceManager* manager,
if (resolved_url.SchemeIsFile()) {
loader = new LocalLoader(runner.Pass());
} else {
if (!network_service_.get()) {
if (!network_service_) {
context_->service_manager()->ConnectToService(
GURL("mojo:mojo_network_service"),
&network_service_);
......
......@@ -239,7 +239,7 @@ class SpyInterceptor : public mojo::ServiceManager::Interceptor {
// You can get an invalid handle if the app (or service) is
// created by unconventional means, for example the command line.
if (!real_client.get())
if (!real_client)
return real_client.Pass();
mojo::ScopedMessagePipeHandle faux_client;
......
......@@ -287,7 +287,7 @@ HandleSignalsState LocalDataPipe::ConsumerGetHandleSignalsStateNoLock() const {
void LocalDataPipe::EnsureBufferNoLock() {
DCHECK(producer_open_no_lock());
if (buffer_.get())
if (buffer_)
return;
buffer_.reset(static_cast<char*>(
base::AlignedAlloc(capacity_num_bytes(), kDataPipeBufferAlignmentBytes)));
......@@ -297,7 +297,7 @@ void LocalDataPipe::DestroyBufferNoLock() {
#ifndef NDEBUG
// Scribble on the buffer to help detect use-after-frees. (This also helps the
// unit test detect certain bugs without needing ASAN or similar.)
if (buffer_.get())
if (buffer_)
memset(buffer_.get(), 0xcd, capacity_num_bytes());
#endif
buffer_.reset();
......
......@@ -162,7 +162,7 @@ void NativeWidgetViewManager::OnNodeActiveViewChanged(
void NativeWidgetViewManager::OnViewInputEvent(view_manager::View* view,
const EventPtr& event) {
scoped_ptr<ui::Event> ui_event(event.To<scoped_ptr<ui::Event> >());
if (ui_event.get())
if (ui_event)
window_tree_host_->SendEventToProcessor(ui_event.get());
}
......
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