From 48f0c963ba40f0b3b7768c9d7f36bd51346ebeb5 Mon Sep 17 00:00:00 2001 From: yzshen Date: Fri, 12 Feb 2016 17:10:46 -0800 Subject: Mojo C++ bindings: make Array/Map/String non-null by default. Array a; // Default construct an empty array. Array b(nullptr); // Construct a null array. a.clear(); // Set to an empty array. a = nullptr; // Set to a null array. BUG=579634 TEST=None Review URL: https://codereview.chromium.org/1693943002 Cr-Commit-Position: refs/heads/master@{#375304} --- components/filesystem/directory_impl.cc | 8 ++++---- components/mus/public/cpp/lib/window.cc | 2 +- components/mus/public/cpp/lib/window_tree_client_impl.cc | 4 +--- .../mus/public/cpp/tests/window_tree_client_impl_unittest.cc | 2 +- components/mus/ws/window_tree_apptest.cc | 2 +- components/mus/ws/window_tree_impl.cc | 2 +- components/mus/ws/window_tree_unittest.cc | 1 - 7 files changed, 9 insertions(+), 12 deletions(-) (limited to 'components') diff --git a/components/filesystem/directory_impl.cc b/components/filesystem/directory_impl.cc index 7fd7a4c..3b4e74d 100644 --- a/components/filesystem/directory_impl.cc +++ b/components/filesystem/directory_impl.cc @@ -30,7 +30,7 @@ DirectoryImpl::~DirectoryImpl() { } void DirectoryImpl::Read(const ReadCallback& callback) { - mojo::Array entries(0); + mojo::Array entries; base::FileEnumerator directory_enumerator( directory_path_, false, base::FileEnumerator::DIRECTORIES | base::FileEnumerator::FILES); @@ -221,18 +221,18 @@ void DirectoryImpl::ReadEntireFile(const mojo::String& raw_path, base::FilePath path; FileError error = ValidatePath(raw_path, directory_path_, &path); if (error != FileError::OK) { - callback.Run(error, mojo::Array(0)); + callback.Run(error, mojo::Array()); return; } if (base::DirectoryExists(path)) { - callback.Run(FileError::NOT_A_FILE, mojo::Array(0)); + callback.Run(FileError::NOT_A_FILE, mojo::Array()); return; } base::File base_file(path, base::File::FLAG_OPEN | base::File::FLAG_READ); if (!base_file.IsValid()) { - callback.Run(GetError(base_file), mojo::Array(0)); + callback.Run(GetError(base_file), mojo::Array()); return; } diff --git a/components/mus/public/cpp/lib/window.cc b/components/mus/public/cpp/lib/window.cc index 8c2ec50..1f8f3ea 100644 --- a/components/mus/public/cpp/lib/window.cc +++ b/components/mus/public/cpp/lib/window.cc @@ -495,7 +495,7 @@ void Window::SetSharedPropertyInternal(const std::string& name, return; if (connection_) { - mojo::Array transport_value; + mojo::Array transport_value(nullptr); if (value) { transport_value.resize(value->size()); if (value->size()) diff --git a/components/mus/public/cpp/lib/window_tree_client_impl.cc b/components/mus/public/cpp/lib/window_tree_client_impl.cc index 0a7426f..2d609fe 100644 --- a/components/mus/public/cpp/lib/window_tree_client_impl.cc +++ b/components/mus/public/cpp/lib/window_tree_client_impl.cc @@ -299,7 +299,7 @@ void WindowTreeClientImpl::SetProperty(Window* window, mojo::Array data) { DCHECK(tree_); - mojo::Array old_value; + mojo::Array old_value(nullptr); if (window->HasSharedProperty(name)) old_value = mojo::Array::From(window->properties_[name]); @@ -435,8 +435,6 @@ Window* WindowTreeClientImpl::NewWindowImpl( if (properties) { transport_properties = mojo::Map>::From(*properties); - } else { - transport_properties.mark_non_null(); } if (type == NewWindowType::CHILD) { tree_->NewWindow(change_id, window->id(), std::move(transport_properties)); diff --git a/components/mus/public/cpp/tests/window_tree_client_impl_unittest.cc b/components/mus/public/cpp/tests/window_tree_client_impl_unittest.cc index c1159d5..dc19a84 100644 --- a/components/mus/public/cpp/tests/window_tree_client_impl_unittest.cc +++ b/components/mus/public/cpp/tests/window_tree_client_impl_unittest.cc @@ -62,7 +62,7 @@ class WindowTreeClientImplPrivate { root_data->parent_id = 0; root_data->window_id = 1; root_data->bounds = mojo::Rect::From(gfx::Rect()); - root_data->properties.mark_non_null(); + root_data->properties.SetToEmpty(); root_data->visible = true; root_data->drawn = true; root_data->viewport_metrics = mojom::ViewportMetrics::New(); diff --git a/components/mus/ws/window_tree_apptest.cc b/components/mus/ws/window_tree_apptest.cc index bc55a76..ee2a186 100644 --- a/components/mus/ws/window_tree_apptest.cc +++ b/components/mus/ws/window_tree_apptest.cc @@ -234,7 +234,7 @@ class TestWindowTreeClientImpl : public mojom::WindowTreeClient, bool SetWindowProperty(Id window_id, const std::string& name, const std::vector* data) { - Array mojo_data; + Array mojo_data(nullptr); if (data) mojo_data = Array::From(*data); const uint32_t change_id = GetAndAdvanceChangeId(); diff --git a/components/mus/ws/window_tree_impl.cc b/components/mus/ws/window_tree_impl.cc index df73c46..f144d3a 100644 --- a/components/mus/ws/window_tree_impl.cc +++ b/components/mus/ws/window_tree_impl.cc @@ -397,7 +397,7 @@ void WindowTreeImpl::ProcessWindowPropertyChanged( if (!IsWindowKnown(window, &client_window_id)) return; - Array data; + Array data(nullptr); if (new_data) data = Array::From(*new_data); diff --git a/components/mus/ws/window_tree_unittest.cc b/components/mus/ws/window_tree_unittest.cc index 8eea452..99e53a5 100644 --- a/components/mus/ws/window_tree_unittest.cc +++ b/components/mus/ws/window_tree_unittest.cc @@ -849,7 +849,6 @@ TEST_F(WindowTreeTest, NewTopLevelWindow) { // Create a new top level window. mojo::Map> properties; - properties.mark_non_null(); const uint32_t initial_change_id = 17; // Explicitly use an id that does not contain the connection id. const ClientWindowId embed_window_id2_in_child(45 << 16 | 27); -- cgit v1.1