Skip to content

Commit

Permalink
Rename lacros -> crosapi.
Browse files Browse the repository at this point in the history
This CL is a refactor with no intended behavior change.

The API surface between lacros-chrome and ash-chrome is named crosapi.
This allows a cleaner separation of code, since the word "lacros" will
only be used by lacros-chrome, not ash-chrome.

Bug: 1104273
Change-Id: I543ac6a44ab0d85c7f3cb672defcd73bcbba3066
TBR: kerrnel@chromium.org
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2292995
Commit-Queue: Erik Chen <erikchen@chromium.org>
Reviewed-by: Avi Drissman <avi@chromium.org>
Reviewed-by: Nico Weber <thakis@chromium.org>
Reviewed-by: James Cook <jamescook@chromium.org>
Auto-Submit: Erik Chen <erikchen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#787405}
  • Loading branch information
erikchen authored and Commit Bot committed Jul 10, 2020
1 parent daf09d5 commit 8e73ffd
Show file tree
Hide file tree
Showing 34 changed files with 210 additions and 182 deletions.
4 changes: 2 additions & 2 deletions chrome/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -3946,7 +3946,7 @@ static_library("browser") {
"//chromeos/components/cdm_factory_daemon:cdm_factory_daemon_browser",
"//chromeos/components/quick_answers",
"//chromeos/components/sync_wifi",
"//chromeos/lacros/mojom",
"//chromeos/crosapi/mojom",
"//chromeos/services/assistant/public/cpp",
"//chromeos/services/cellular_setup",
"//chromeos/services/device_sync/public/mojom",
Expand Down Expand Up @@ -4004,8 +4004,8 @@ static_library("browser") {
"metrics/lacros_metrics_provider.h",
]
deps += [
"//chromeos/crosapi/mojom",
"//chromeos/lacros/browser",
"//chromeos/lacros/mojom",
]
}

Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/chrome_content_browser_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5805,7 +5805,7 @@ bool ChromeContentBrowserClient::IsOriginTrialRequiredForAppCache(
void ChromeContentBrowserClient::BindBrowserControlInterface(
mojo::GenericPendingReceiver receiver) {
#if BUILDFLAG(IS_LACROS)
if (auto r = receiver.As<lacros::mojom::LacrosChromeService>()) {
if (auto r = receiver.As<crosapi::mojom::LacrosChromeService>()) {
chromeos::LacrosChromeServiceImpl::Get()->BindReceiver(std::move(r));
}
#endif
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/chromeos/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ source_set("chromeos") {
"//chromeos/components/telemetry_extension_ui/mojom",
"//chromeos/components/tether",
"//chromeos/constants",
"//chromeos/crosapi/cpp",
"//chromeos/crosapi/mojom",
"//chromeos/cryptohome",
"//chromeos/dbus",
"//chromeos/dbus:metrics_event_proto",
Expand Down Expand Up @@ -161,8 +163,6 @@ source_set("chromeos") {
"//chromeos/dbus/upstart",
"//chromeos/disks",
"//chromeos/geolocation",
"//chromeos/lacros/cpp",
"//chromeos/lacros/mojom",
"//chromeos/login/auth",
"//chromeos/login/login_state",
"//chromeos/login/session",
Expand Down
43 changes: 22 additions & 21 deletions chrome/browser/chromeos/crosapi/select_file_crosapi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,40 @@
#include "base/files/file_path.h"
#include "base/memory/ref_counted.h"
#include "base/numerics/ranges.h"
#include "chromeos/lacros/mojom/select_file.mojom.h"
#include "chromeos/crosapi/mojom/select_file.mojom.h"
#include "ui/shell_dialogs/select_file_dialog.h"
#include "ui/shell_dialogs/select_file_policy.h"
#include "ui/shell_dialogs/selected_file_info.h"
#include "url/gurl.h"

namespace {

ui::SelectFileDialog::Type GetUiType(lacros::mojom::SelectFileDialogType type) {
ui::SelectFileDialog::Type GetUiType(
crosapi::mojom::SelectFileDialogType type) {
switch (type) {
case lacros::mojom::SelectFileDialogType::kFolder:
case crosapi::mojom::SelectFileDialogType::kFolder:
return ui::SelectFileDialog::Type::SELECT_FOLDER;
case lacros::mojom::SelectFileDialogType::kUploadFolder:
case crosapi::mojom::SelectFileDialogType::kUploadFolder:
return ui::SelectFileDialog::Type::SELECT_UPLOAD_FOLDER;
case lacros::mojom::SelectFileDialogType::kExistingFolder:
case crosapi::mojom::SelectFileDialogType::kExistingFolder:
return ui::SelectFileDialog::Type::SELECT_EXISTING_FOLDER;
case lacros::mojom::SelectFileDialogType::kOpenFile:
case crosapi::mojom::SelectFileDialogType::kOpenFile:
return ui::SelectFileDialog::Type::SELECT_OPEN_FILE;
case lacros::mojom::SelectFileDialogType::kOpenMultiFile:
case crosapi::mojom::SelectFileDialogType::kOpenMultiFile:
return ui::SelectFileDialog::Type::SELECT_OPEN_MULTI_FILE;
case lacros::mojom::SelectFileDialogType::kSaveAsFile:
case crosapi::mojom::SelectFileDialogType::kSaveAsFile:
return ui::SelectFileDialog::Type::SELECT_SAVEAS_FILE;
}
}

ui::SelectFileDialog::FileTypeInfo::AllowedPaths GetUiAllowedPaths(
lacros::mojom::AllowedPaths allowed_paths) {
crosapi::mojom::AllowedPaths allowed_paths) {
switch (allowed_paths) {
case lacros::mojom::AllowedPaths::kAnyPath:
case crosapi::mojom::AllowedPaths::kAnyPath:
return ui::SelectFileDialog::FileTypeInfo::ANY_PATH;
case lacros::mojom::AllowedPaths::kNativePath:
case crosapi::mojom::AllowedPaths::kNativePath:
return ui::SelectFileDialog::FileTypeInfo::NATIVE_PATH;
case lacros::mojom::AllowedPaths::kAnyPathOrUrl:
case crosapi::mojom::AllowedPaths::kAnyPathOrUrl:
return ui::SelectFileDialog::FileTypeInfo::ANY_PATH_OR_URL;
}
}
Expand All @@ -53,8 +54,8 @@ ui::SelectFileDialog::FileTypeInfo::AllowedPaths GetUiAllowedPaths(
// the same time. Deletes itself when the dialog is closed.
class SelectFileDialogHolder : public ui::SelectFileDialog::Listener {
public:
SelectFileDialogHolder(lacros::mojom::SelectFileOptionsPtr options,
lacros::mojom::SelectFile::SelectCallback callback)
SelectFileDialogHolder(crosapi::mojom::SelectFileOptionsPtr options,
crosapi::mojom::SelectFile::SelectCallback callback)
: select_callback_(std::move(callback)) {
// Policy is null because showing the file-dialog-blocked infobar is handled
// client-side in lacros-chrome.
Expand Down Expand Up @@ -133,24 +134,24 @@ class SelectFileDialogHolder : public ui::SelectFileDialog::Listener {
// Invokes |select_callback_| with the list of files and deletes this object.
void OnSelected(const std::vector<ui::SelectedFileInfo>& files,
int file_type_index) {
std::vector<lacros::mojom::SelectedFileInfoPtr> mojo_files;
std::vector<crosapi::mojom::SelectedFileInfoPtr> mojo_files;
for (const ui::SelectedFileInfo& file : files) {
lacros::mojom::SelectedFileInfoPtr mojo_file =
lacros::mojom::SelectedFileInfo::New();
crosapi::mojom::SelectedFileInfoPtr mojo_file =
crosapi::mojom::SelectedFileInfo::New();
mojo_file->file_path = file.file_path;
mojo_file->local_path = file.local_path;
mojo_file->display_name = file.display_name;
mojo_file->url = file.url;
mojo_files.push_back(std::move(mojo_file));
}
std::move(select_callback_)
.Run(lacros::mojom::SelectFileResult::kSuccess, std::move(mojo_files),
.Run(crosapi::mojom::SelectFileResult::kSuccess, std::move(mojo_files),
file_type_index);
delete this;
}

// Callback run after files are selected or the dialog is canceled.
lacros::mojom::SelectFile::SelectCallback select_callback_;
crosapi::mojom::SelectFile::SelectCallback select_callback_;

// The file select dialog.
scoped_refptr<ui::SelectFileDialog> select_file_dialog_;
Expand All @@ -163,12 +164,12 @@ class SelectFileDialogHolder : public ui::SelectFileDialog::Listener {

// TODO(https://crbug.com/1090587): Connection error handling.
SelectFileCrosapi::SelectFileCrosapi(
mojo::PendingReceiver<lacros::mojom::SelectFile> receiver)
mojo::PendingReceiver<crosapi::mojom::SelectFile> receiver)
: receiver_(this, std::move(receiver)) {}

SelectFileCrosapi::~SelectFileCrosapi() = default;

void SelectFileCrosapi::Select(lacros::mojom::SelectFileOptionsPtr options,
void SelectFileCrosapi::Select(crosapi::mojom::SelectFileOptionsPtr options,
SelectCallback callback) {
// Deletes itself when the dialog closes.
new SelectFileDialogHolder(std::move(options), std::move(callback));
Expand Down
12 changes: 6 additions & 6 deletions chrome/browser/chromeos/crosapi/select_file_crosapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,27 @@
#ifndef CHROME_BROWSER_CHROMEOS_CROSAPI_SELECT_FILE_CROSAPI_H_
#define CHROME_BROWSER_CHROMEOS_CROSAPI_SELECT_FILE_CROSAPI_H_

#include "chromeos/lacros/mojom/select_file.mojom.h"
#include "chromeos/crosapi/mojom/select_file.mojom.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver.h"

// Implements the SelectFile mojo interface for open/save dialogs. Wraps the
// underlying Chrome OS SelectFileExtension implementation, which uses the WebUI
// file manager to provide the dialogs. Lives on the UI thread.
class SelectFileCrosapi : public lacros::mojom::SelectFile {
class SelectFileCrosapi : public crosapi::mojom::SelectFile {
public:
explicit SelectFileCrosapi(
mojo::PendingReceiver<lacros::mojom::SelectFile> receiver);
mojo::PendingReceiver<crosapi::mojom::SelectFile> receiver);
SelectFileCrosapi(const SelectFileCrosapi&) = delete;
SelectFileCrosapi& operator=(const SelectFileCrosapi&) = delete;
~SelectFileCrosapi() override;

// lacros::mojom::SelectFile:
void Select(lacros::mojom::SelectFileOptionsPtr options,
// crosapi::mojom::SelectFile:
void Select(crosapi::mojom::SelectFileOptionsPtr options,
SelectCallback callback) override;

private:
mojo::Receiver<lacros::mojom::SelectFile> receiver_;
mojo::Receiver<crosapi::mojom::SelectFile> receiver_;
};

#endif // CHROME_BROWSER_CHROMEOS_CROSAPI_SELECT_FILE_CROSAPI_H_
10 changes: 5 additions & 5 deletions chrome/browser/chromeos/lacros/ash_chrome_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
#include "base/logging.h"
#include "chrome/browser/chromeos/crosapi/select_file_crosapi.h"
#include "chrome/browser/chromeos/lacros/screen_manager_crosapi.h"
#include "chromeos/lacros/mojom/screen_manager.mojom.h"
#include "chromeos/lacros/mojom/select_file.mojom.h"
#include "chromeos/crosapi/mojom/screen_manager.mojom.h"
#include "chromeos/crosapi/mojom/select_file.mojom.h"

AshChromeServiceImpl::AshChromeServiceImpl(
mojo::PendingReceiver<lacros::mojom::AshChromeService> pending_receiver)
mojo::PendingReceiver<crosapi::mojom::AshChromeService> pending_receiver)
: receiver_(this, std::move(pending_receiver)),
screen_manager_crosapi_(std::make_unique<ScreenManagerCrosapi>()) {
// TODO(hidehiko): Remove non-critical log from here.
Expand All @@ -24,12 +24,12 @@ AshChromeServiceImpl::AshChromeServiceImpl(
AshChromeServiceImpl::~AshChromeServiceImpl() = default;

void AshChromeServiceImpl::BindSelectFile(
mojo::PendingReceiver<lacros::mojom::SelectFile> receiver) {
mojo::PendingReceiver<crosapi::mojom::SelectFile> receiver) {
select_file_crosapi_ =
std::make_unique<SelectFileCrosapi>(std::move(receiver));
}

void AshChromeServiceImpl::BindScreenManager(
mojo::PendingReceiver<lacros::mojom::ScreenManager> receiver) {
mojo::PendingReceiver<crosapi::mojom::ScreenManager> receiver) {
screen_manager_crosapi_->BindReceiver(std::move(receiver));
}
14 changes: 7 additions & 7 deletions chrome/browser/chromeos/lacros/ash_chrome_service_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include <memory>

#include "chromeos/lacros/mojom/lacros.mojom.h"
#include "chromeos/crosapi/mojom/crosapi.mojom.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver.h"

Expand All @@ -16,20 +16,20 @@ class SelectFileCrosapi;

// Implementation of AshChromeService. It provides a set of APIs that
// lacros-chrome can call into.
class AshChromeServiceImpl : public lacros::mojom::AshChromeService {
class AshChromeServiceImpl : public crosapi::mojom::AshChromeService {
public:
explicit AshChromeServiceImpl(
mojo::PendingReceiver<lacros::mojom::AshChromeService> pending_receiver);
mojo::PendingReceiver<crosapi::mojom::AshChromeService> pending_receiver);
~AshChromeServiceImpl() override;

// lacros::mojom::AshChromeService:
// crosapi::mojom::AshChromeService:
void BindScreenManager(
mojo::PendingReceiver<lacros::mojom::ScreenManager> receiver) override;
mojo::PendingReceiver<crosapi::mojom::ScreenManager> receiver) override;
void BindSelectFile(
mojo::PendingReceiver<lacros::mojom::SelectFile> receiver) override;
mojo::PendingReceiver<crosapi::mojom::SelectFile> receiver) override;

private:
mojo::Receiver<lacros::mojom::AshChromeService> receiver_;
mojo::Receiver<crosapi::mojom::AshChromeService> receiver_;

std::unique_ptr<ScreenManagerCrosapi> screen_manager_crosapi_;
std::unique_ptr<SelectFileCrosapi> select_file_crosapi_;
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/chromeos/lacros/lacros_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ void LacrosManager::StartForeground(bool already_running) {
}

void LacrosManager::OnAshChromeServiceReceiverReceived(
mojo::PendingReceiver<lacros::mojom::AshChromeService> pending_receiver) {
mojo::PendingReceiver<crosapi::mojom::AshChromeService> pending_receiver) {
DCHECK_EQ(state_, State::STARTING);
ash_chrome_service_ =
std::make_unique<AshChromeServiceImpl>(std::move(pending_receiver));
Expand Down
6 changes: 3 additions & 3 deletions chrome/browser/chromeos/lacros/lacros_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "base/memory/scoped_refptr.h"
#include "base/memory/weak_ptr.h"
#include "base/process/process.h"
#include "chromeos/lacros/mojom/lacros.mojom.h"
#include "chromeos/crosapi/mojom/crosapi.mojom.h"
#include "components/session_manager/core/session_manager_observer.h"
#include "mojo/public/cpp/bindings/remote.h"

Expand Down Expand Up @@ -101,7 +101,7 @@ class LacrosManager : public session_manager::SessionManagerObserver {
// Called when PendingReceiver of AshChromeService is passed from
// lacros-chrome.
void OnAshChromeServiceReceiverReceived(
mojo::PendingReceiver<lacros::mojom::AshChromeService> pending_receiver);
mojo::PendingReceiver<crosapi::mojom::AshChromeService> pending_receiver);

// Called when the Mojo connection to lacros-chrome is disconnected.
// It may be "just a Mojo error" or "lacros-chrome crash".
Expand Down Expand Up @@ -139,7 +139,7 @@ class LacrosManager : public session_manager::SessionManagerObserver {

// Proxy to LacrosChromeService mojo service in lacros-chrome.
// Available during lacros-chrome is running.
mojo::Remote<lacros::mojom::LacrosChromeService> lacros_chrome_service_;
mojo::Remote<crosapi::mojom::LacrosChromeService> lacros_chrome_service_;

// Implementation of AshChromeService Mojo APIs.
// Instantiated on receiving the PendingReceiver from lacros-chrome.
Expand Down
14 changes: 7 additions & 7 deletions chrome/browser/chromeos/lacros/screen_manager_crosapi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "base/numerics/checked_math.h"
#include "base/numerics/safe_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "chromeos/lacros/cpp/window_snapshot.h"
#include "chromeos/crosapi/cpp/window_snapshot.h"
#include "ui/snapshot/snapshot.h"

ScreenManagerCrosapi::ScreenManagerCrosapi() = default;
Expand All @@ -25,7 +25,7 @@ ScreenManagerCrosapi::~ScreenManagerCrosapi() {
}

void ScreenManagerCrosapi::BindReceiver(
mojo::PendingReceiver<lacros::mojom::ScreenManager> receiver) {
mojo::PendingReceiver<crosapi::mojom::ScreenManager> receiver) {
receivers_.Add(this, std::move(receiver));
}

Expand All @@ -49,7 +49,7 @@ void ScreenManagerCrosapi::ListWindows(ListWindowsCallback callback) {
ash::kShellWindowId_DefaultContainerDeprecated);

// We need to create a vector that contains window_id and title.
std::vector<lacros::mojom::WindowDetailsPtr> windows;
std::vector<crosapi::mojom::WindowDetailsPtr> windows;

// The |container| has all the top-level windows in reverse order, e.g. the
// most top-level window is at the end. So iterate children reversely to make
Expand All @@ -64,8 +64,8 @@ void ScreenManagerCrosapi::ListWindows(ListWindowsCallback callback) {
if (!window->IsVisible() || !window->CanFocus())
continue;

lacros::mojom::WindowDetailsPtr details =
lacros::mojom::WindowDetails::New();
crosapi::mojom::WindowDetailsPtr details =
crosapi::mojom::WindowDetails::New();

// We are already tracking the window.
auto existing_window_it = window_to_id_.find(window);
Expand Down Expand Up @@ -93,7 +93,7 @@ void ScreenManagerCrosapi::TakeWindowSnapshot(
TakeWindowSnapshotCallback callback) {
auto it = id_to_window_.find(id);
if (it == id_to_window_.end()) {
std::move(callback).Run(/*success=*/false, lacros::WindowSnapshot());
std::move(callback).Run(/*success=*/false, crosapi::WindowSnapshot());
return;
}

Expand Down Expand Up @@ -132,7 +132,7 @@ void ScreenManagerCrosapi::DidTakeSnapshot(SnapshotCallback callback,
uint8_t* base = static_cast<uint8_t*>(bitmap.getPixels());
std::vector<uint8_t> bytes(base, base + bitmap.computeByteSize());

lacros::WindowSnapshot snapshot;
crosapi::WindowSnapshot snapshot;
snapshot.width = bitmap.width();
snapshot.height = bitmap.height();
snapshot.bitmap.swap(bytes);
Expand Down
12 changes: 6 additions & 6 deletions chrome/browser/chromeos/lacros/screen_manager_crosapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
#include <map>

#include "base/memory/weak_ptr.h"
#include "chromeos/lacros/mojom/screen_manager.mojom.h"
#include "chromeos/crosapi/mojom/screen_manager.mojom.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
#include "ui/aura/window_observer.h"
#include "ui/gfx/image/image.h"

// This class is the ash-chrome implementation of the ScreenManager interface.
// This class must only be used from the main thread.
class ScreenManagerCrosapi : public lacros::mojom::ScreenManager,
class ScreenManagerCrosapi : public crosapi::mojom::ScreenManager,
aura::WindowObserver {
public:
ScreenManagerCrosapi();
Expand All @@ -27,9 +27,9 @@ class ScreenManagerCrosapi : public lacros::mojom::ScreenManager,
~ScreenManagerCrosapi() override;

void BindReceiver(
mojo::PendingReceiver<lacros::mojom::ScreenManager> receiver);
mojo::PendingReceiver<crosapi::mojom::ScreenManager> receiver);

// lacros::mojom::ScreenManager:
// crosapi::mojom::ScreenManager:
void TakeScreenSnapshot(TakeScreenSnapshotCallback callback) override;
void ListWindows(ListWindowsCallback callback) override;
void TakeWindowSnapshot(uint64_t id,
Expand All @@ -43,7 +43,7 @@ class ScreenManagerCrosapi : public lacros::mojom::ScreenManager,

private:
using SnapshotCallback =
base::OnceCallback<void(const lacros::WindowSnapshot&)>;
base::OnceCallback<void(const crosapi::WindowSnapshot&)>;
void DidTakeSnapshot(SnapshotCallback callback, gfx::Image image);

// This class generates unique, non-reused IDs for windows on demand. The IDs
Expand All @@ -60,7 +60,7 @@ class ScreenManagerCrosapi : public lacros::mojom::ScreenManager,
// This class supports any number of connections. This allows the client to
// have multiple, potentially thread-affine, remotes. This is needed by
// WebRTC.
mojo::ReceiverSet<lacros::mojom::ScreenManager> receivers_;
mojo::ReceiverSet<crosapi::mojom::ScreenManager> receivers_;

base::WeakPtrFactory<ScreenManagerCrosapi> weak_factory_{this};
};
Expand Down
Loading

0 comments on commit 8e73ffd

Please sign in to comment.