summaryrefslogtreecommitdiffstats
path: root/mojo
diff options
context:
space:
mode:
authorerg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-19 00:57:58 +0000
committererg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-19 00:57:58 +0000
commit3ecf8289a6e5d7e07b8e52cf1f3e40bf436e814c (patch)
tree72b3487aead1628b6375f783ff31646f67337ec6 /mojo
parent1f6c86af09fd5fa00f4717040e57f276fecd46f2 (diff)
downloadchromium_src-3ecf8289a6e5d7e07b8e52cf1f3e40bf436e814c.zip
chromium_src-3ecf8289a6e5d7e07b8e52cf1f3e40bf436e814c.tar.gz
chromium_src-3ecf8289a6e5d7e07b8e52cf1f3e40bf436e814c.tar.bz2
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
Diffstat (limited to 'mojo')
-rw-r--r--mojo/examples/nesting_app/nesting_app.cc2
-rw-r--r--mojo/examples/window_manager/window_manager.cc2
-rw-r--r--mojo/gles2/command_buffer_client_impl.cc2
-rw-r--r--mojo/public/cpp/bindings/interface_ptr.h10
-rw-r--r--mojo/public/cpp/bindings/lib/interface_ptr_internal.h4
-rw-r--r--mojo/public/cpp/bindings/tests/handle_passing_unittest.cc6
-rw-r--r--mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc14
-rw-r--r--mojo/services/gles2/command_buffer_impl.cc6
-rw-r--r--mojo/services/html_viewer/html_viewer.cc2
-rw-r--r--mojo/services/native_viewport/native_viewport_service.cc2
-rw-r--r--mojo/services/view_manager/view_manager_init_service_impl.cc4
-rw-r--r--mojo/shell/dynamic_service_loader.cc2
-rw-r--r--mojo/spy/spy.cc2
-rw-r--r--mojo/system/local_data_pipe.cc4
-rw-r--r--mojo/views/native_widget_view_manager.cc2
15 files changed, 39 insertions, 25 deletions
diff --git a/mojo/examples/nesting_app/nesting_app.cc b/mojo/examples/nesting_app/nesting_app.cc
index 9b488d2..e62f1b7 100644
--- a/mojo/examples/nesting_app/nesting_app.cc
+++ b/mojo/examples/nesting_app/nesting_app.cc
@@ -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_);
}
diff --git a/mojo/examples/window_manager/window_manager.cc b/mojo/examples/window_manager/window_manager.cc
index f672c5f..e1cb54d 100644
--- a/mojo/examples/window_manager/window_manager.cc
+++ b/mojo/examples/window_manager/window_manager.cc
@@ -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());
diff --git a/mojo/gles2/command_buffer_client_impl.cc b/mojo/gles2/command_buffer_client_impl.cc
index 1a03468..3a71697 100644
--- a/mojo/gles2/command_buffer_client_impl.cc
+++ b/mojo/gles2/command_buffer_client_impl.cc
@@ -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();
diff --git a/mojo/public/cpp/bindings/interface_ptr.h b/mojo/public/cpp/bindings/interface_ptr.h
index 0d8473d..eaa57f6 100644
--- a/mojo/public/cpp/bindings/interface_ptr.h
+++ b/mojo/public/cpp/bindings/interface_ptr.h
@@ -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_;
diff --git a/mojo/public/cpp/bindings/lib/interface_ptr_internal.h b/mojo/public/cpp/bindings/lib/interface_ptr_internal.h
index 437ce8e..7e9a262 100644
--- a/mojo/public/cpp/bindings/lib/interface_ptr_internal.h
+++ b/mojo/public/cpp/bindings/lib/interface_ptr_internal.h
@@ -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();
diff --git a/mojo/public/cpp/bindings/tests/handle_passing_unittest.cc b/mojo/public/cpp/bindings/tests/handle_passing_unittest.cc
index ab2e475..d2e287f 100644
--- a/mojo/public/cpp/bindings/tests/handle_passing_unittest.cc
+++ b/mojo/public/cpp/bindings/tests/handle_passing_unittest.cc
@@ -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;
diff --git a/mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc b/mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc
index 8f1de63..533d990 100644
--- a/mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc
+++ b/mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc
@@ -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.
diff --git a/mojo/services/gles2/command_buffer_impl.cc b/mojo/services/gles2/command_buffer_impl.cc
index 4b836d8..1f40444 100644
--- a/mojo/services/gles2/command_buffer_impl.cc
+++ b/mojo/services/gles2/command_buffer_impl.cc
@@ -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;
}
diff --git a/mojo/services/html_viewer/html_viewer.cc b/mojo/services/html_viewer/html_viewer.cc
index 431bbac..8490e69 100644
--- a/mojo/services/html_viewer/html_viewer.cc
+++ b/mojo/services/html_viewer/html_viewer.cc
@@ -83,7 +83,7 @@ class HTMLViewer : public ApplicationDelegate,
}
void MaybeLoad() {
- if (document_view_ && response_.get())
+ if (document_view_ && response_)
document_view_->Load(response_.Pass());
}
diff --git a/mojo/services/native_viewport/native_viewport_service.cc b/mojo/services/native_viewport/native_viewport_service.cc
index b7c8052..203ec10 100644
--- a/mojo/services/native_viewport/native_viewport_service.cc
+++ b/mojo/services/native_viewport/native_viewport_service.cc
@@ -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;
}
diff --git a/mojo/services/view_manager/view_manager_init_service_impl.cc b/mojo/services/view_manager/view_manager_init_service_impl.cc
index 9cb337b..f7822fc 100644
--- a/mojo/services/view_manager/view_manager_init_service_impl.cc
+++ b/mojo/services/view_manager/view_manager_init_service_impl.cc
@@ -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);
}
diff --git a/mojo/shell/dynamic_service_loader.cc b/mojo/shell/dynamic_service_loader.cc
index 6f1fc80..5939d4b 100644
--- a/mojo/shell/dynamic_service_loader.cc
+++ b/mojo/shell/dynamic_service_loader.cc
@@ -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_);
diff --git a/mojo/spy/spy.cc b/mojo/spy/spy.cc
index 58310d8..4c7ed0d 100644
--- a/mojo/spy/spy.cc
+++ b/mojo/spy/spy.cc
@@ -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;
diff --git a/mojo/system/local_data_pipe.cc b/mojo/system/local_data_pipe.cc
index 8f4bbd6a..eb799cc 100644
--- a/mojo/system/local_data_pipe.cc
+++ b/mojo/system/local_data_pipe.cc
@@ -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();
diff --git a/mojo/views/native_widget_view_manager.cc b/mojo/views/native_widget_view_manager.cc
index e4b0248..69fcf7f 100644
--- a/mojo/views/native_widget_view_manager.cc
+++ b/mojo/views/native_widget_view_manager.cc
@@ -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());
}