Skip to content

Commit

Permalink
Convert shell & catalog to use new wrapper types.
Browse files Browse the repository at this point in the history
R=yzshen@chromium.org
TBR=tsepez@chromium.org

Review-Url: https://codereview.chromium.org/2235983002
Cr-Commit-Position: refs/heads/master@{#411525}
  • Loading branch information
ben authored and Commit bot committed Aug 12, 2016
1 parent 6d909b8 commit ee942d7
Show file tree
Hide file tree
Showing 35 changed files with 60 additions and 71 deletions.
2 changes: 1 addition & 1 deletion chrome/app/mash/mash_runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class DefaultService : public shell::Service,

// ServiceFactory:
void CreateService(shell::mojom::ServiceRequest request,
const mojo::String& mojo_name) override {
const std::string& mojo_name) override {
if (service_) {
LOG(ERROR) << "request to create additional service " << mojo_name;
return;
Expand Down
4 changes: 2 additions & 2 deletions content/browser/mojo/mojo_child_connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace {
void CallBinderOnTaskRunner(
const shell::InterfaceRegistry::Binder& binder,
scoped_refptr<base::SequencedTaskRunner> task_runner,
const mojo::String& interface_name,
const std::string& interface_name,
mojo::ScopedMessagePipeHandle request_handle) {
task_runner->PostTask(
FROM_HERE,
Expand Down Expand Up @@ -64,7 +64,7 @@ class MojoChildConnection::IOThreadContext
}

void GetRemoteInterfaceOnIOThread(
const mojo::String& interface_name,
const std::string& interface_name,
mojo::ScopedMessagePipeHandle request_handle) {
if (connection_) {
connection_->GetRemoteInterfaces()->GetInterface(
Expand Down
2 changes: 1 addition & 1 deletion content/child/service_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ ServiceFactory::ServiceFactory() {}
ServiceFactory::~ServiceFactory() {}

void ServiceFactory::CreateService(shell::mojom::ServiceRequest request,
const mojo::String& name) {
const std::string& name) {
// Only register services on first run.
if (!has_registered_services_) {
DCHECK(services_.empty());
Expand Down
2 changes: 1 addition & 1 deletion content/child/service_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ServiceFactory : public shell::mojom::ServiceFactory {

// shell::mojom::ServiceFactory:
void CreateService(shell::mojom::ServiceRequest request,
const mojo::String& name) override;
const std::string& name) override;

private:
// Called if CreateService fails to find a registered service.
Expand Down
10 changes: 5 additions & 5 deletions content/common/mojo/mojo_shell_connection_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class MojoShellConnectionImpl::IOThreadContext
public:
using InitializeCallback = base::Callback<void(const shell::Identity&)>;
using ServiceFactoryCallback =
base::Callback<void(shell::mojom::ServiceRequest, const mojo::String&)>;
base::Callback<void(shell::mojom::ServiceRequest, const std::string&)>;

IOThreadContext(shell::mojom::ServiceRequest service_request,
scoped_refptr<base::SequencedTaskRunner> io_task_runner,
Expand Down Expand Up @@ -198,7 +198,7 @@ class MojoShellConnectionImpl::IOThreadContext
// shell::mojom::ServiceFactory implementation

void CreateService(shell::mojom::ServiceRequest request,
const mojo::String& name) override {
const std::string& name) override {
DCHECK(io_thread_checker_.CalledOnValidThread());
callback_task_runner_->PostTask(
FROM_HERE,
Expand All @@ -208,7 +208,7 @@ class MojoShellConnectionImpl::IOThreadContext
static void CallBinderOnTaskRunner(
scoped_refptr<base::SequencedTaskRunner> task_runner,
const shell::InterfaceRegistry::Binder& binder,
const mojo::String& interface_name,
const std::string& interface_name,
mojo::ScopedMessagePipeHandle request_handle) {
task_runner->PostTask(FROM_HERE, base::Bind(binder, interface_name,
base::Passed(&request_handle)));
Expand Down Expand Up @@ -391,7 +391,7 @@ void MojoShellConnectionImpl::AddServiceRequestHandler(

void MojoShellConnectionImpl::CreateService(
shell::mojom::ServiceRequest request,
const mojo::String& name) {
const std::string& name) {
auto it = request_handlers_.find(name);
if (it != request_handlers_.end())
it->second.Run(std::move(request));
Expand All @@ -411,7 +411,7 @@ void MojoShellConnectionImpl::OnConnectionLost() {

void MojoShellConnectionImpl::GetInterface(
shell::mojom::InterfaceProvider* provider,
const mojo::String& interface_name,
const std::string& interface_name,
mojo::ScopedMessagePipeHandle request_handle) {
provider->GetInterface(interface_name, std::move(request_handle));
}
Expand Down
4 changes: 2 additions & 2 deletions content/common/mojo/mojo_shell_connection_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ class MojoShellConnectionImpl : public MojoShellConnection {
void OnContextInitialized(const shell::Identity& identity);
void OnConnectionLost();
void CreateService(shell::mojom::ServiceRequest request,
const mojo::String& name);
const std::string& name);
void GetInterface(shell::mojom::InterfaceProvider* provider,
const mojo::String& interface_name,
const std::string& interface_name,
mojo::ScopedMessagePipeHandle request_handle);

shell::Identity identity_;
Expand Down
2 changes: 1 addition & 1 deletion content/renderer/media/media_interface_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ MediaInterfaceProvider::~MediaInterfaceProvider() {
DCHECK(thread_checker_.CalledOnValidThread());
}

void MediaInterfaceProvider::GetInterface(const mojo::String& interface_name,
void MediaInterfaceProvider::GetInterface(const std::string& interface_name,
mojo::ScopedMessagePipeHandle pipe) {
DVLOG(1) << __FUNCTION__;
DCHECK(thread_checker_.CalledOnValidThread());
Expand Down
2 changes: 1 addition & 1 deletion content/renderer/media/media_interface_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class CONTENT_EXPORT MediaInterfaceProvider
~MediaInterfaceProvider() final;

// InterfaceProvider implementation.
void GetInterface(const mojo::String& interface_name,
void GetInterface(const std::string& interface_name,
mojo::ScopedMessagePipeHandle pipe) final;

private:
Expand Down
2 changes: 1 addition & 1 deletion mash/app_driver/app_driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ AppDriver::AppDriver() : binding_(this), weak_factory_(this) {}
AppDriver::~AppDriver() {}

void AppDriver::OnAvailableCatalogEntries(
mojo::Array<catalog::mojom::EntryPtr> entries) {
std::vector<catalog::mojom::EntryPtr> entries) {
if (entries.empty()) {
LOG(ERROR) << "Unable to install accelerators for launching chrome.";
return;
Expand Down
2 changes: 1 addition & 1 deletion mash/app_driver/app_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class AppDriver : public shell::Service,
~AppDriver() override;

private:
void OnAvailableCatalogEntries(mojo::Array<catalog::mojom::EntryPtr> entries);
void OnAvailableCatalogEntries(std::vector<catalog::mojom::EntryPtr> entries);

// shell::Service:
void OnStart(const shell::Identity& identity) override;
Expand Down
4 changes: 2 additions & 2 deletions mash/catalog_viewer/catalog_viewer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ class CatalogViewerContents : public views::WidgetDelegateView,

// We don't want to show an empty UI so we just block until we have all the
// data. GetEntries is a sync call.
mojo::Array<catalog::mojom::EntryPtr> entries;
bool got = catalog_->GetEntries(nullptr, &entries);
std::vector<catalog::mojom::EntryPtr> entries;
bool got = catalog_->GetEntries(base::nullopt, &entries);
if (got) {
for (auto& entry : entries)
entries_.push_back(Entry(entry->display_name, entry->name));
Expand Down
4 changes: 2 additions & 2 deletions mash/quick_launch/quick_launch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ class QuickLaunchUI : public views::WidgetDelegateView,
base::Unretained(this)));
}

void OnGotCatalogEntries(mojo::Array<catalog::mojom::EntryPtr> entries) {
void OnGotCatalogEntries(std::vector<catalog::mojom::EntryPtr> entries) {
for (const auto& entry : entries)
app_names_.insert(base::UTF8ToUTF16(entry->name.get()));
app_names_.insert(base::UTF8ToUTF16(entry->name));
}

void Launch(const std::string& name, bool new_window) {
Expand Down
9 changes: 5 additions & 4 deletions mash/task_viewer/task_viewer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,11 @@ class TaskViewerContents : public views::WidgetDelegateView,
}

// Overridden from shell::mojom::ServiceManagerListener:
void OnInit(mojo::Array<ServiceInfoPtr> instances) override {
void OnInit(std::vector<ServiceInfoPtr> instances) override {
// This callback should only be called with an empty model.
DCHECK(instances_.empty());
mojo::Array<mojo::String> names;
std::vector<std::string> names;
names.reserve(instances.size());
for (size_t i = 0; i < instances.size(); ++i) {
const shell::Identity& identity = instances[i]->identity;
InsertInstance(identity, instances[i]->pid);
Expand All @@ -167,7 +168,7 @@ class TaskViewerContents : public views::WidgetDelegateView,
DCHECK(!ContainsIdentity(identity));
InsertInstance(identity, instance->pid);
observer_->OnItemsAdded(static_cast<int>(instances_.size()), 1);
mojo::Array<mojo::String> names;
std::vector<std::string> names;
names.push_back(identity.name());
catalog_->GetEntries(std::move(names),
base::Bind(&TaskViewerContents::OnGotCatalogEntries,
Expand Down Expand Up @@ -209,7 +210,7 @@ class TaskViewerContents : public views::WidgetDelegateView,
base::WrapUnique(new InstanceInfo(identity, pid)));
}

void OnGotCatalogEntries(mojo::Array<catalog::mojom::EntryPtr> entries) {
void OnGotCatalogEntries(std::vector<catalog::mojom::EntryPtr> entries) {
for (auto it = instances_.begin(); it != instances_.end(); ++it) {
for (auto& entry : entries) {
if (entry->name == (*it)->identity.name()) {
Expand Down
21 changes: 10 additions & 11 deletions services/catalog/instance.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
namespace catalog {
namespace {

void AddEntry(const Entry& entry, mojo::Array<mojom::EntryPtr>* ary) {
void AddEntry(const Entry& entry, std::vector<mojom::EntryPtr>* ary) {
mojom::EntryPtr entry_ptr(mojom::Entry::New());
entry_ptr->name = entry.name();
entry_ptr->display_name = entry.display_name();
Expand Down Expand Up @@ -58,7 +58,7 @@ void Instance::CacheReady(EntryCache* cache) {
////////////////////////////////////////////////////////////////////////////////
// Instance, shell::mojom::Resolver:

void Instance::ResolveMojoName(const mojo::String& mojo_name,
void Instance::ResolveMojoName(const std::string& mojo_name,
const ResolveMojoNameCallback& callback) {
DCHECK(system_cache_);

Expand Down Expand Up @@ -90,18 +90,17 @@ void Instance::ResolveMojoName(const mojo::String& mojo_name,
////////////////////////////////////////////////////////////////////////////////
// Instance, mojom::Catalog:

void Instance::GetEntries(mojo::Array<mojo::String> names,
void Instance::GetEntries(const base::Optional<std::vector<std::string>>& names,
const GetEntriesCallback& callback) {
DCHECK(system_cache_);

mojo::Array<mojom::EntryPtr> entries;
if (names.is_null()) {
std::vector<mojom::EntryPtr> entries;
if (!names.has_value()) {
// TODO(beng): user catalog.
for (const auto& entry : *system_cache_)
AddEntry(*entry.second, &entries);
} else {
std::vector<mojo::String> names_vec = names.PassStorage();
for (const std::string& name : names_vec) {
for (const std::string& name : names.value()) {
Entry* entry = nullptr;
// TODO(beng): user catalog.
if (system_cache_->find(name) != system_cache_->end())
Expand All @@ -115,23 +114,23 @@ void Instance::GetEntries(mojo::Array<mojo::String> names,
}

void Instance::GetEntriesProvidingClass(
const mojo::String& clazz,
const std::string& clazz,
const GetEntriesProvidingClassCallback& callback) {
mojo::Array<mojom::EntryPtr> entries;
std::vector<mojom::EntryPtr> entries;
for (const auto& entry : *system_cache_)
if (entry.second->ProvidesClass(clazz))
entries.push_back(mojom::Entry::From(*entry.second));
callback.Run(std::move(entries));
}

void Instance::GetEntriesConsumingMIMEType(
const mojo::String& mime_type,
const std::string& mime_type,
const GetEntriesConsumingMIMETypeCallback& callback) {
// TODO(beng): implement.
}

void Instance::GetEntriesSupportingScheme(
const mojo::String& scheme,
const std::string& scheme,
const GetEntriesSupportingSchemeCallback& callback) {
// TODO(beng): implement.
}
Expand Down
10 changes: 5 additions & 5 deletions services/catalog/instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,20 @@ class Instance : public shell::mojom::Resolver,

private:
// shell::mojom::Resolver:
void ResolveMojoName(const mojo::String& mojo_name,
void ResolveMojoName(const std::string& mojo_name,
const ResolveMojoNameCallback& callback) override;

// mojom::Catalog:
void GetEntries(mojo::Array<mojo::String> names,
void GetEntries(const base::Optional<std::vector<std::string>>& names,
const GetEntriesCallback& callback) override;
void GetEntriesProvidingClass(
const mojo::String& clazz,
const std::string& clazz,
const GetEntriesProvidingClassCallback& callback) override;
void GetEntriesConsumingMIMEType(
const mojo::String& mime_type,
const std::string& mime_type,
const GetEntriesConsumingMIMETypeCallback& callback) override;
void GetEntriesSupportingScheme(
const mojo::String& scheme,
const std::string& scheme,
const GetEntriesSupportingSchemeCallback& callback) override;

// Populate/serialize the cache from/to the supplied store.
Expand Down
2 changes: 0 additions & 2 deletions services/catalog/public/interfaces/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,4 @@ mojom("interfaces") {
sources = [
"catalog.mojom",
]

use_new_wrapper_types = false
}
2 changes: 1 addition & 1 deletion services/shell/public/cpp/identity_struct_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct StructTraits<shell::mojom::Identity, shell::Identity> {
return identity.instance();
}
static bool Read(shell::mojom::IdentityDataView data, shell::Identity* out) {
mojo::String name, user_id, instance;
std::string name, user_id, instance;
if (!data.ReadName(&name))
return false;

Expand Down
2 changes: 1 addition & 1 deletion services/shell/public/cpp/interface_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace shell {
// Connection.
class InterfaceProvider {
public:
using ForwardCallback = base::Callback<void(const mojo::String&,
using ForwardCallback = base::Callback<void(const std::string&,
mojo::ScopedMessagePipeHandle)>;
class TestApi {
public:
Expand Down
6 changes: 3 additions & 3 deletions services/shell/public/cpp/interface_registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class InterfaceBinder;
//
class InterfaceRegistry : public mojom::InterfaceProvider {
public:
using Binder = base::Callback<void(const mojo::String&,
using Binder = base::Callback<void(const std::string&,
mojo::ScopedMessagePipeHandle)>;

class TestApi {
Expand Down Expand Up @@ -138,7 +138,7 @@ class InterfaceRegistry : public mojom::InterfaceProvider {
std::map<std::string, std::unique_ptr<InterfaceBinder>>;

// mojom::InterfaceProvider:
void GetInterface(const mojo::String& interface_name,
void GetInterface(const std::string& interface_name,
mojo::ScopedMessagePipeHandle handle) override;

// Returns true if the binder was set, false if it was not set (e.g. by
Expand All @@ -164,7 +164,7 @@ class InterfaceRegistry : public mojom::InterfaceProvider {

// Pending interface requests which can accumulate if GetInterface() is called
// while binding is paused.
std::queue<std::pair<mojo::String, mojo::ScopedMessagePipeHandle>>
std::queue<std::pair<std::string, mojo::ScopedMessagePipeHandle>>
pending_interface_requests_;

base::WeakPtrFactory<InterfaceRegistry> weak_factory_;
Expand Down
2 changes: 1 addition & 1 deletion services/shell/public/cpp/lib/connection_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ base::WeakPtr<Connection> ConnectionImpl::GetWeakPtr() {
// ConnectionImpl, private:

void ConnectionImpl::OnConnectionCompleted(shell::mojom::ConnectResult result,
mojo::String target_user_id) {
const std::string& target_user_id) {
DCHECK(State::PENDING == state_);

result_ = result;
Expand Down
2 changes: 1 addition & 1 deletion services/shell/public/cpp/lib/connection_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class ConnectionImpl : public Connection {
base::WeakPtr<Connection> GetWeakPtr() override;

void OnConnectionCompleted(shell::mojom::ConnectResult result,
mojo::String target_user_id);
const std::string& target_user_id);

Identity remote_;

Expand Down
2 changes: 1 addition & 1 deletion services/shell/public/cpp/lib/interface_registry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void InterfaceRegistry::SetConnectionLostClosure(
}

// mojom::InterfaceProvider:
void InterfaceRegistry::GetInterface(const mojo::String& interface_name,
void InterfaceRegistry::GetInterface(const std::string& interface_name,
mojo::ScopedMessagePipeHandle handle) {
if (is_paused_) {
pending_interface_requests_.emplace(interface_name, std::move(handle));
Expand Down
2 changes: 0 additions & 2 deletions services/shell/public/interfaces/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,4 @@ mojom("interfaces") {
public_deps = [
"//mojo/common:common_custom_types",
]

use_new_wrapper_types = false
}
3 changes: 2 additions & 1 deletion services/shell/service_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,8 @@ ServiceManager::Instance* ServiceManager::CreateInstance(

void ServiceManager::AddListener(mojom::ServiceManagerListenerPtr listener) {
// TODO(beng): filter instances provided by those visible to this service.
mojo::Array<mojom::ServiceInfoPtr> instances;
std::vector<mojom::ServiceInfoPtr> instances;
instances.reserve(identity_to_instance_.size());
for (auto& instance : identity_to_instance_)
instances.push_back(instance.second->CreateServiceInfo());
listener->OnInit(std::move(instances));
Expand Down
2 changes: 1 addition & 1 deletion services/shell/standalone/context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class TracingInterfaceProvider : public mojom::InterfaceProvider {
~TracingInterfaceProvider() override {}

// mojom::InterfaceProvider:
void GetInterface(const mojo::String& interface_name,
void GetInterface(const std::string& interface_name,
mojo::ScopedMessagePipeHandle client_handle) override {
if (tracer_ && interface_name == tracing::mojom::Provider::Name_) {
tracer_->ConnectToProvider(
Expand Down
Loading

0 comments on commit ee942d7

Please sign in to comment.