Commit 39fafebd authored by dcheng's avatar dcheng Committed by Commit bot

Convert //services from scoped_ptr to std::unique_ptr

BUG=554298
R=ben@chromium.org,jam@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#388610}
parent 0c40087a
......@@ -5,6 +5,7 @@
#include "services/catalog/catalog.h"
#include "base/bind.h"
#include "base/memory/ptr_util.h"
#include "services/catalog/constants.h"
#include "services/catalog/instance.h"
#include "services/catalog/reader.h"
......@@ -14,7 +15,7 @@
namespace catalog {
Catalog::Catalog(base::TaskRunner* file_task_runner,
scoped_ptr<Store> store,
std::unique_ptr<Store> store,
ManifestProvider* manifest_provider)
: file_task_runner_(file_task_runner),
store_(std::move(store)),
......@@ -64,7 +65,7 @@ Instance* Catalog::GetInstanceForUserId(const std::string& user_id) {
// TODO(beng): There needs to be a way to load the store from different users.
Instance* instance = new Instance(std::move(store_), system_reader_.get());
instances_[user_id] = make_scoped_ptr(instance);
instances_[user_id] = base::WrapUnique(instance);
if (loaded_)
instance->CacheReady(&system_cache_);
......
......@@ -6,10 +6,10 @@
#define SERVICES_CATALOG_CATALOG_H_
#include <map>
#include <memory>
#include <string>
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "services/catalog/public/interfaces/catalog.mojom.h"
......@@ -41,7 +41,7 @@ class Catalog : public shell::ShellClient,
public:
// |manifest_provider| may be null.
Catalog(base::TaskRunner* file_task_runner,
scoped_ptr<Store> store,
std::unique_ptr<Store> store,
ManifestProvider* manifest_provider);
~Catalog() override;
......@@ -64,14 +64,14 @@ class Catalog : public shell::ShellClient,
void SystemPackageDirScanned();
base::TaskRunner* const file_task_runner_;
scoped_ptr<Store> store_;
std::unique_ptr<Store> store_;
shell::mojom::ShellClientPtr shell_client_;
scoped_ptr<shell::ShellConnection> shell_connection_;
std::unique_ptr<shell::ShellConnection> shell_connection_;
std::map<std::string, scoped_ptr<Instance>> instances_;
std::map<std::string, std::unique_ptr<Instance>> instances_;
scoped_ptr<Reader> system_reader_;
std::unique_ptr<Reader> system_reader_;
EntryCache system_cache_;
bool loaded_ = false;
......
......@@ -106,31 +106,31 @@ Entry::Entry(const std::string& name)
Entry::Entry(const Entry& other) = default;
Entry::~Entry() {}
scoped_ptr<base::DictionaryValue> Entry::Serialize() const {
scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue);
std::unique_ptr<base::DictionaryValue> Entry::Serialize() const {
std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue);
value->SetInteger(Store::kManifestVersionKey, 1);
value->SetString(Store::kNameKey, name_);
value->SetString(Store::kDisplayNameKey, display_name_);
value->SetString(Store::kQualifierKey, qualifier_);
scoped_ptr<base::DictionaryValue> spec(new base::DictionaryValue);
std::unique_ptr<base::DictionaryValue> spec(new base::DictionaryValue);
scoped_ptr<base::DictionaryValue> provided(new base::DictionaryValue);
std::unique_ptr<base::DictionaryValue> provided(new base::DictionaryValue);
for (const auto& i : capabilities_.provided) {
scoped_ptr<base::ListValue> interfaces(new base::ListValue);
std::unique_ptr<base::ListValue> interfaces(new base::ListValue);
for (const auto& interface_name : i.second)
interfaces->AppendString(interface_name);
provided->Set(i.first, std::move(interfaces));
}
spec->Set(Store::kCapabilities_ProvidedKey, std::move(provided));
scoped_ptr<base::DictionaryValue> required(new base::DictionaryValue);
std::unique_ptr<base::DictionaryValue> required(new base::DictionaryValue);
for (const auto& i : capabilities_.required) {
scoped_ptr<base::DictionaryValue> request(new base::DictionaryValue);
scoped_ptr<base::ListValue> classes(new base::ListValue);
std::unique_ptr<base::DictionaryValue> request(new base::DictionaryValue);
std::unique_ptr<base::ListValue> classes(new base::ListValue);
for (const auto& class_name : i.second.classes)
classes->AppendString(class_name);
request->Set(Store::kCapabilities_ClassesKey, std::move(classes));
scoped_ptr<base::ListValue> interfaces(new base::ListValue);
std::unique_ptr<base::ListValue> interfaces(new base::ListValue);
for (const auto& interface_name : i.second.interfaces)
interfaces->AppendString(interface_name);
request->Set(Store::kCapabilities_InterfacesKey, std::move(interfaces));
......@@ -143,8 +143,8 @@ scoped_ptr<base::DictionaryValue> Entry::Serialize() const {
}
// static
scoped_ptr<Entry> Entry::Deserialize(const base::DictionaryValue& value) {
scoped_ptr<Entry> entry(new Entry);
std::unique_ptr<Entry> Entry::Deserialize(const base::DictionaryValue& value) {
std::unique_ptr<Entry> entry(new Entry);
int manifest_version = 0;
if (value.HasKey(Store::kManifestVersionKey))
CHECK(value.GetInteger(Store::kManifestVersionKey, &manifest_version));
......@@ -188,7 +188,7 @@ scoped_ptr<Entry> Entry::Deserialize(const base::DictionaryValue& value) {
for (size_t i = 0; i < applications->GetSize(); ++i) {
const base::DictionaryValue* application = nullptr;
applications->GetDictionary(i, &application);
scoped_ptr<Entry> child = Entry::Deserialize(*application);
std::unique_ptr<Entry> child = Entry::Deserialize(*application);
if (child) {
child->set_package(entry.get());
// Caller must assume ownership of these items.
......
......@@ -5,11 +5,11 @@
#ifndef SERVICES_CATALOG_ENTRY_H_
#define SERVICES_CATALOG_ENTRY_H_
#include <memory>
#include <set>
#include <string>
#include "base/files/file_path.h"
#include "base/memory/scoped_ptr.h"
#include "services/catalog/public/interfaces/catalog.mojom.h"
#include "services/shell/public/cpp/capabilities.h"
......@@ -27,12 +27,12 @@ class Entry {
explicit Entry(const Entry& other);
~Entry();
scoped_ptr<base::DictionaryValue> Serialize() const;
std::unique_ptr<base::DictionaryValue> Serialize() const;
// If the constructed Entry is a package that provides other Entrys, the
// caller must assume ownership of the tree of Entrys by enumerating
// applications().
static scoped_ptr<Entry> Deserialize(const base::DictionaryValue& value);
static std::unique_ptr<Entry> Deserialize(const base::DictionaryValue& value);
bool ProvidesClass(const std::string& clazz) const;
......
......@@ -21,9 +21,9 @@ class EntryTest : public testing::Test {
~EntryTest() override {}
protected:
scoped_ptr<Entry> ReadEntry(const std::string& manifest,
scoped_ptr<base::Value>* out_value) {
scoped_ptr<base::Value> value = ReadManifest(manifest);
std::unique_ptr<Entry> ReadEntry(const std::string& manifest,
std::unique_ptr<base::Value>* out_value) {
std::unique_ptr<base::Value> value = ReadManifest(manifest);
base::DictionaryValue* dictionary = nullptr;
CHECK(value->GetAsDictionary(&dictionary));
if (out_value)
......@@ -31,7 +31,7 @@ class EntryTest : public testing::Test {
return Entry::Deserialize(*dictionary);
}
scoped_ptr<base::Value> ReadManifest(const std::string& manifest) {
std::unique_ptr<base::Value> ReadManifest(const std::string& manifest) {
base::FilePath manifest_path;
PathService::Get(base::DIR_SOURCE_ROOT, &manifest_path);
manifest_path = manifest_path.AppendASCII(
......@@ -54,21 +54,21 @@ class EntryTest : public testing::Test {
};
TEST_F(EntryTest, Simple) {
scoped_ptr<Entry> entry = ReadEntry("simple", nullptr);
std::unique_ptr<Entry> entry = ReadEntry("simple", nullptr);
EXPECT_EQ("mojo:foo", entry->name());
EXPECT_EQ(shell::GetNamePath(entry->name()), entry->qualifier());
EXPECT_EQ("Foo", entry->display_name());
}
TEST_F(EntryTest, Instance) {
scoped_ptr<Entry> entry = ReadEntry("instance", nullptr);
std::unique_ptr<Entry> entry = ReadEntry("instance", nullptr);
EXPECT_EQ("mojo:foo", entry->name());
EXPECT_EQ("bar", entry->qualifier());
EXPECT_EQ("Foo", entry->display_name());
}
TEST_F(EntryTest, Capabilities) {
scoped_ptr<Entry> entry = ReadEntry("capabilities", nullptr);
std::unique_ptr<Entry> entry = ReadEntry("capabilities", nullptr);
EXPECT_EQ("mojo:foo", entry->name());
EXPECT_EQ("bar", entry->qualifier());
......@@ -81,20 +81,20 @@ TEST_F(EntryTest, Capabilities) {
}
TEST_F(EntryTest, Serialization) {
scoped_ptr<base::Value> value;
scoped_ptr<Entry> entry = ReadEntry("serialization", &value);
std::unique_ptr<base::Value> value;
std::unique_ptr<Entry> entry = ReadEntry("serialization", &value);
scoped_ptr<base::DictionaryValue> serialized(entry->Serialize());
std::unique_ptr<base::DictionaryValue> serialized(entry->Serialize());
// We can't just compare values, since during deserialization some of the
// lists get converted to std::sets, which are sorted, so Value::Equals will
// fail.
scoped_ptr<Entry> reconstituted = Entry::Deserialize(*serialized.get());
std::unique_ptr<Entry> reconstituted = Entry::Deserialize(*serialized.get());
EXPECT_EQ(*entry, *reconstituted);
}
TEST_F(EntryTest, Malformed) {
scoped_ptr<base::Value> value = ReadManifest("malformed");
std::unique_ptr<base::Value> value = ReadManifest("malformed");
EXPECT_FALSE(value.get());
}
......
......@@ -26,7 +26,7 @@ void AddEntry(const Entry& entry, mojo::Array<mojom::EntryPtr>* ary) {
////////////////////////////////////////////////////////////////////////////////
// Instance, public:
Instance::Instance(scoped_ptr<Store> store, Reader* system_reader)
Instance::Instance(std::unique_ptr<Store> store, Reader* system_reader)
: store_(std::move(store)),
system_reader_(system_reader),
weak_factory_(this) {}
......@@ -65,7 +65,7 @@ void Instance::ResolveMojoName(const mojo::String& mojo_name,
std::string type = shell::GetNameType(mojo_name);
if (type != shell::kNameType_Mojo && type != shell::kNameType_Exe) {
scoped_ptr<Entry> entry(new Entry(mojo_name));
std::unique_ptr<Entry> entry(new Entry(mojo_name));
callback.Run(shell::mojom::ResolveResult::From(*entry));
return;
}
......@@ -149,7 +149,7 @@ void Instance::DeserializeCatalog() {
const base::DictionaryValue* dictionary = nullptr;
const base::Value* v = *it;
CHECK(v->GetAsDictionary(&dictionary));
scoped_ptr<Entry> entry = Entry::Deserialize(*dictionary);
std::unique_ptr<Entry> entry = Entry::Deserialize(*dictionary);
// TODO(beng): user catalog.
if (entry)
(*system_cache_)[entry->name()] = std::move(entry);
......@@ -158,7 +158,7 @@ void Instance::DeserializeCatalog() {
void Instance::SerializeCatalog() {
DCHECK(system_cache_);
scoped_ptr<base::ListValue> catalog(new base::ListValue);
std::unique_ptr<base::ListValue> catalog(new base::ListValue);
// TODO(beng): user catalog.
for (const auto& entry : *system_cache_)
catalog->Append(entry.second->Serialize());
......
......@@ -26,7 +26,7 @@ class Instance : public shell::mojom::ShellResolver,
public mojom::Catalog {
public:
// |manifest_provider| may be null.
Instance(scoped_ptr<Store> store, Reader* system_reader);
Instance(std::unique_ptr<Store> store, Reader* system_reader);
~Instance() override;
void BindShellResolver(shell::mojom::ShellResolverRequest request);
......@@ -68,7 +68,7 @@ class Instance : public shell::mojom::ShellResolver,
shell::mojom::ResolveResultPtr result);
// User-specific persistent storage of package manifests and other settings.
scoped_ptr<Store> store_;
std::unique_ptr<Store> store_;
mojo::BindingSet<shell::mojom::ShellResolver> shell_resolver_bindings_;
mojo::BindingSet<mojom::Catalog> catalog_bindings_;
......
......@@ -9,6 +9,7 @@
#include "base/files/file_util.h"
#include "base/json/json_file_value_serializer.h"
#include "base/json/json_reader.h"
#include "base/memory/ptr_util.h"
#include "base/path_service.h"
#include "base/task_runner_util.h"
#include "base/thread_task_runner_handle.h"
......@@ -54,8 +55,9 @@ base::FilePath GetPackagePath(const base::FilePath& package_dir,
return base::FilePath();
}
scoped_ptr<Entry> ProcessManifest(scoped_ptr<base::Value> manifest_root,
const base::FilePath& package_dir) {
std::unique_ptr<Entry> ProcessManifest(
std::unique_ptr<base::Value> manifest_root,
const base::FilePath& package_dir) {
// Manifest was malformed or did not exist.
if (!manifest_root)
return nullptr;
......@@ -64,14 +66,14 @@ scoped_ptr<Entry> ProcessManifest(scoped_ptr<base::Value> manifest_root,
if (!manifest_root->GetAsDictionary(&dictionary))
return nullptr;
scoped_ptr<Entry> entry = Entry::Deserialize(*dictionary);
std::unique_ptr<Entry> entry = Entry::Deserialize(*dictionary);
if (!entry)
return nullptr;
entry->set_path(GetPackagePath(package_dir, entry->name()));
return entry;
}
scoped_ptr<Entry> CreateEntryForManifestAt(
std::unique_ptr<Entry> CreateEntryForManifestAt(
const base::FilePath& manifest_path,
const base::FilePath& package_dir) {
JSONFileValueDeserializer deserializer(manifest_path);
......@@ -96,7 +98,7 @@ void ScanDir(
if (path.empty())
break;
base::FilePath manifest_path = path.AppendASCII("manifest.json");
scoped_ptr<Entry> entry =
std::unique_ptr<Entry> entry =
CreateEntryForManifestAt(manifest_path, package_dir);
if (!entry)
continue;
......@@ -116,9 +118,9 @@ void ScanDir(
original_thread_task_runner->PostTask(FROM_HERE, read_complete_closure);
}
scoped_ptr<Entry> ReadManifest(const base::FilePath& package_dir,
const std::string& mojo_name) {
scoped_ptr<Entry> entry = CreateEntryForManifestAt(
std::unique_ptr<Entry> ReadManifest(const base::FilePath& package_dir,
const std::string& mojo_name) {
std::unique_ptr<Entry> entry = CreateEntryForManifestAt(
GetManifestPath(package_dir, mojo_name), package_dir);
if (!entry) {
entry.reset(new Entry(mojo_name));
......@@ -128,9 +130,9 @@ scoped_ptr<Entry> ReadManifest(const base::FilePath& package_dir,
return entry;
}
void AddEntryToCache(EntryCache* cache, scoped_ptr<Entry> entry) {
void AddEntryToCache(EntryCache* cache, std::unique_ptr<Entry> entry) {
for (auto child : entry->applications())
AddEntryToCache(cache, make_scoped_ptr(child));
AddEntryToCache(cache, base::WrapUnique(child));
(*cache)[entry->name()] = std::move(entry);
}
......@@ -167,7 +169,7 @@ void Reader::CreateEntryForName(
if (manifest_provider_ &&
manifest_provider_->GetApplicationManifest(mojo_name,
&manifest_contents)) {
scoped_ptr<base::Value> manifest_root =
std::unique_ptr<base::Value> manifest_root =
base::JSONReader::Read(manifest_contents);
base::PostTaskAndReplyWithResult(
file_task_runner_, FROM_HERE,
......@@ -188,7 +190,7 @@ void Reader::CreateEntryForName(
void Reader::OnReadManifest(
EntryCache* cache,
const CreateEntryForNameCallback& entry_created_callback,
scoped_ptr<Entry> entry) {
std::unique_ptr<Entry> entry) {
shell::mojom::ResolveResultPtr result =
shell::mojom::ResolveResult::From(*entry);
AddEntryToCache(cache, std::move(entry));
......
......@@ -5,10 +5,11 @@
#ifndef SERVICES_CATALOG_READER_H_
#define SERVICES_CATALOG_READER_H_
#include <memory>
#include "base/callback.h"
#include "base/files/file_path.h"
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "services/catalog/types.h"
#include "services/shell/public/interfaces/shell_resolver.mojom.h"
......@@ -25,9 +26,8 @@ class ManifestProvider;
// Responsible for loading manifests & building the Entry data structures.
class Reader {
public:
using ReadManifestCallback =
base::Callback<void(scoped_ptr<Entry>)>;
using CreateEntryForNameCallback =
using ReadManifestCallback = base::Callback<void(std::unique_ptr<Entry>)>;
using CreateEntryForNameCallback =
base::Callback<void(shell::mojom::ResolveResultPtr)>;
Reader(base::TaskRunner* file_task_runner,
......@@ -50,7 +50,7 @@ class Reader {
private:
void OnReadManifest(EntryCache* cache,
const CreateEntryForNameCallback& entry_created_callback,
scoped_ptr<Entry> entry);
std::unique_ptr<Entry> entry);
base::FilePath system_package_dir_;
base::TaskRunner* file_task_runner_;
......
......@@ -5,7 +5,8 @@
#ifndef SERVICES_CATALOG_STORE_H_
#define SERVICES_CATALOG_STORE_H_
#include "base/memory/scoped_ptr.h"
#include <memory>
#include "base/values.h"
namespace catalog {
......@@ -46,7 +47,7 @@ class Store {
// Write the catalog to the store. Called when the Catalog learns of a newly
// encountered application.
virtual void UpdateStore(scoped_ptr<base::ListValue> store) = 0;
virtual void UpdateStore(std::unique_ptr<base::ListValue> store) = 0;
};
} // namespace catalog
......
......@@ -6,16 +6,16 @@
#define SERVICES_CATALOG_TYPES_H_
#include <map>
#include <memory>
#include <string>
#include "base/memory/scoped_ptr.h"
namespace catalog {
class Entry;
// A map of mojo names -> catalog |Entry|s.
using EntryCache = std::map<std::string, scoped_ptr<Entry>>;
using EntryCache = std::map<std::string, std::unique_ptr<Entry>>;
} // namespace catalog
......
......@@ -41,7 +41,7 @@ class TracingImpl : public shell::InterfaceFactory<tracing::TraceProvider> {
void Create(shell::Connection* connection,
InterfaceRequest<tracing::TraceProvider> request) override;
scoped_ptr<shell::Connection> connection_;
std::unique_ptr<shell::Connection> connection_;
TraceProviderImpl provider_impl_;
DISALLOW_COPY_AND_ASSIGN(TracingImpl);
......
......@@ -7,8 +7,9 @@
#include <stdint.h>
#include <memory>
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/scoped_vector.h"
#include "mojo/public/cpp/bindings/binding_set.h"
#include "mojo/public/cpp/bindings/interface_ptr_set.h"
......@@ -63,7 +64,7 @@ class TracingApp
void AllDataCollected();
scoped_ptr<TraceDataSink> sink_;
std::unique_ptr<TraceDataSink> sink_;
ScopedVector<TraceRecorderImpl> recorder_impls_;
mojo::InterfacePtrSet<TraceProvider> provider_ptrs_;
mojo::Binding<TraceCollector> collector_binding_;
......
......@@ -27,9 +27,8 @@ UserService::~UserService() {}
void UserService::GetDirectory(filesystem::DirectoryRequest request,
const GetDirectoryCallback& callback) {
new filesystem::DirectoryImpl(std::move(request),
path_,
scoped_ptr<base::ScopedTempDir>(),
new filesystem::DirectoryImpl(std::move(request), path_,
std::unique_ptr<base::ScopedTempDir>(),
lock_table_);
callback.Run();
}
......@@ -51,7 +50,8 @@ void UserService::GetSubDirectory(const mojo::String& sub_directory_path,
}
new filesystem::DirectoryImpl(std::move(request), subdir,
scoped_ptr<base::ScopedTempDir>(), lock_table_);
std::unique_ptr<base::ScopedTempDir>(),
lock_table_);
callback.Run(filesystem::FileError::OK);
}
......
......@@ -5,6 +5,7 @@
#include "services/user/user_shell_client.h"
#include "base/bind.h"
#include "base/memory/ptr_util.h"
#include "base/memory/weak_ptr.h"
#include "components/filesystem/lock_table.h"
#include "components/leveldb/leveldb_service_impl.h"
......@@ -63,17 +64,17 @@ class UserShellClient::LevelDBServiceObjects
scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
// Variables that are only accessible on the |leveldb_service_runner_| thread.
scoped_ptr<leveldb::LevelDBService> leveldb_service_;
std::unique_ptr<leveldb::LevelDBService> leveldb_service_;
mojo::BindingSet<leveldb::LevelDBService> leveldb_bindings_;
DISALLOW_COPY_AND_ASSIGN(LevelDBServiceObjects);
};
scoped_ptr<shell::ShellClient> CreateUserShellClient(
std::unique_ptr<shell::ShellClient> CreateUserShellClient(
scoped_refptr<base::SingleThreadTaskRunner> user_service_runner,
scoped_refptr<base::SingleThreadTaskRunner> leveldb_service_runner) {
return make_scoped_ptr(new UserShellClient(std::move(user_service_runner),
std::move(leveldb_service_runner)));
return base::WrapUnique(new UserShellClient(
std::move(user_service_runner), std::move(leveldb_service_runner)));
}
UserShellClient::UserShellClient(
......
......@@ -16,7 +16,7 @@
namespace user_service {
scoped_ptr<shell::ShellClient> CreateUserShellClient(
std::unique_ptr<shell::ShellClient> CreateUserShellClient(
scoped_refptr<base::SingleThreadTaskRunner> user_service_runner,
scoped_refptr<base::SingleThreadTaskRunner> leveldb_service_runner);
......@@ -57,10 +57,10 @@ class UserShellClient
// We create these two objects so we can delete them on the correct task
// runners.
class UserServiceObjects;
scoped_ptr<UserServiceObjects> user_objects_;
std::unique_ptr<UserServiceObjects> user_objects_;
class LevelDBServiceObjects;
scoped_ptr<LevelDBServiceObjects> leveldb_objects_;
std::unique_ptr<LevelDBServiceObjects> leveldb_objects_;
DISALLOW_COPY_AND_ASSIGN(UserShellClient);
};
......
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