0

App Service: Run clang-format on //c/b/apps/app_service

Change-Id: Ia6027138cfff60e30e4ae5acea8fc2240f9fbc38
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5131594
Reviewed-by: Glen Robertson <glenrob@chromium.org>
Commit-Queue: Glen Robertson <glenrob@chromium.org>
Auto-Submit: Tim Sergeant <tsergeant@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1238919}
This commit is contained in:
Tim Sergeant
2023-12-19 02:45:22 +00:00
committed by Chromium LUCI CQ
parent 055be24f63
commit a3d592c5ff
24 changed files with 103 additions and 74 deletions

@ -320,8 +320,9 @@ gfx::ImageSkia LoadMaskImage(const ScaleToSize& scale_to_size) {
gfx::ImageSkia ApplyBackgroundAndMask(const gfx::ImageSkia& image) {
TRACE_EVENT0("ui", "apps::ApplyBackgroundAndMask");
if (image.isNull())
if (image.isNull()) {
return gfx::ImageSkia();
}
return gfx::ImageSkiaOperations::CreateButtonBackground(
SK_ColorWHITE, image, LoadMaskImage(GetScaleToSize(image)));
}

@ -392,8 +392,9 @@ void AppIconLoader::ApplyIconEffects(IconEffects icon_effects,
const std::optional<std::string>& app_id,
IconValuePtr iv) {
TRACE_EVENT0("ui", "AppIconLoader::ApplyIconEffects");
if (!iv || iv->uncompressed.isNull())
if (!iv || iv->uncompressed.isNull()) {
return;
}
if (!standard_icon_task_runner_) {
standard_icon_task_runner_ = base::ThreadPool::CreateSequencedTaskRunner(

@ -85,8 +85,9 @@ void AppIconSource::StartDataRequest(
// Check whether data is of correct type, load default image if not.
std::string size_param = base::ToLowerASCII(path_parts[1]);
size_t query_position = size_param.find("?");
if (query_position != std::string::npos)
if (query_position != std::string::npos) {
size_param = size_param.substr(0, query_position);
}
int size_in_dip = 0;
if (!base::StringToInt(size_param, &size_in_dip) || size_in_dip < 1) {
LoadDefaultImage(std::move(callback));

@ -500,8 +500,9 @@ void AppServiceProxyAsh::LaunchAppWithIntent(const std::string& app_id,
files_controller->CheckIfLaunchAllowed(update, std::move(intent_copy),
std::move(launch_callback));
});
if (!app_found)
if (!app_found) {
std::move(launch_callback).Run(/*is_allowed=*/true);
}
} else {
std::move(launch_callback).Run(/*is_allowed=*/true);
}
@ -1203,8 +1204,9 @@ bool AppServiceProxyAsh::CanRunLaunchCallback(
InstanceRegistry().ForOneInstance(
instance_id,
[&exists](const apps::InstanceUpdate& update) { exists = true; });
if (!exists)
if (!exists) {
return false;
}
}
return true;

@ -345,44 +345,43 @@ void AppServiceProxyBase::LaunchAppWithIntent(const std::string& app_id,
WindowInfoPtr window_info,
LaunchCallback callback) {
CHECK(intent);
app_registry_cache_.ForOneApp(
app_id,
[this, event_flags, &intent, launch_source, &window_info,
callback = std::move(callback)](const AppUpdate& update) mutable {
auto* publisher = GetPublisher(update.AppType());
if (!publisher) {
std::unique_ptr<LaunchParams> params =
std::make_unique<LaunchParams>();
params->event_flags_ = event_flags;
params->intent_ = std::move(intent);
params->launch_source_ = launch_source;
params->window_info_ = std::move(window_info);
params->call_back_ = std::move(callback);
OnPublisherNotReadyForLaunch(update.AppId(), std::move(params));
return;
}
app_registry_cache_.ForOneApp(app_id, [this, event_flags, &intent,
launch_source, &window_info,
callback = std::move(callback)](
const AppUpdate& update) mutable {
auto* publisher = GetPublisher(update.AppType());
if (!publisher) {
std::unique_ptr<LaunchParams> params = std::make_unique<LaunchParams>();
params->event_flags_ = event_flags;
params->intent_ = std::move(intent);
params->launch_source_ = launch_source;
params->window_info_ = std::move(window_info);
params->call_back_ = std::move(callback);
OnPublisherNotReadyForLaunch(update.AppId(), std::move(params));
return;
}
if (MaybeShowLaunchPreventionDialog(update)) {
std::move(callback).Run(LaunchResult(State::FAILED));
return;
}
if (MaybeShowLaunchPreventionDialog(update)) {
std::move(callback).Run(LaunchResult(State::FAILED));
return;
}
// TODO(crbug/1117655): File manager records metrics for apps it
// launched. So we only record launches from other places. We should
// eventually move those metrics here, after AppService supports all
// app types launched by file manager.
if (launch_source != LaunchSource::kFromFileManager) {
RecordAppLaunch(update.AppId(), launch_source);
}
RecordAppPlatformMetrics(profile_, update, launch_source,
LaunchContainer::kLaunchContainerNone);
// TODO(crbug/1117655): File manager records metrics for apps it
// launched. So we only record launches from other places. We should
// eventually move those metrics here, after AppService supports all
// app types launched by file manager.
if (launch_source != LaunchSource::kFromFileManager) {
RecordAppLaunch(update.AppId(), launch_source);
}
RecordAppPlatformMetrics(profile_, update, launch_source,
LaunchContainer::kLaunchContainerNone);
publisher->LaunchAppWithIntent(
update.AppId(), event_flags, std::move(intent), launch_source,
std::move(window_info), std::move(callback));
publisher->LaunchAppWithIntent(update.AppId(), event_flags,
std::move(intent), launch_source,
std::move(window_info), std::move(callback));
PerformPostLaunchTasks(launch_source);
});
PerformPostLaunchTasks(launch_source);
});
}
void AppServiceProxyBase::LaunchAppWithUrl(const std::string& app_id,

@ -45,8 +45,9 @@ void AppServiceTest::UninstallAllApps(Profile* profile) {
std::string AppServiceTest::GetAppName(const std::string& app_id) const {
std::string name;
if (!app_service_proxy_)
if (!app_service_proxy_) {
return name;
}
app_service_proxy_->AppRegistryCache().ForOneApp(
app_id, [&name](const AppUpdate& update) { name = update.Name(); });
return name;

@ -61,8 +61,9 @@ bool HaveSameWindowTreeHostLacros(aura::Window* window1,
Browser* GetBrowserWithTabStripModel(TabStripModel* tab_strip_model) {
for (auto* browser : *BrowserList::GetInstance()) {
if (browser->tab_strip_model() == tab_strip_model)
if (browser->tab_strip_model() == tab_strip_model) {
return browser;
}
}
return nullptr;
}
@ -122,8 +123,9 @@ std::string GetAppIdForBrowser(Browser* browser) {
auto* registry = extensions::ExtensionRegistry::Get(browser->profile());
auto* extension = registry->GetInstalledExtension(app_id);
// This is a web-app.
if (!extension)
if (!extension) {
return app_id;
}
if (extension->is_hosted_app() || extension->is_legacy_packaged_app()) {
return app_id;

@ -117,8 +117,7 @@ struct TestInstance {
bool operator==(const TestInstance& e1, const TestInstance& e2) {
return e1.name == e2.name && e1.id == e2.id && e1.type == e2.type &&
e1.app_id == e2.app_id && e1.window == e2.window &&
e1.title == e2.title &&
e1.is_browser_active == e2.is_browser_active &&
e1.title == e2.title && e1.is_browser_active == e2.is_browser_active &&
e1.is_web_contents_active == e2.is_web_contents_active;
}

@ -29,8 +29,9 @@ namespace apps {
#if BUILDFLAG(IS_CHROMEOS_LACROS)
bool ShouldHostedAppsRunInLacros() {
if (g_enable_hosted_apps_in_lacros_for_testing)
if (g_enable_hosted_apps_in_lacros_for_testing) {
return true;
}
return chromeos::BrowserParamsProxy::Get()->PublishHostedApps();
}

@ -25,7 +25,7 @@
namespace arc {
class ArcIntentHelperBridge;
class IntentFilter;
}
} // namespace arc
#endif
class Profile;

@ -50,8 +50,9 @@ LaunchResult ConvertMojomLaunchResultToLaunchResult(
crosapi::mojom::LaunchResultPtr mojom_launch_result) {
auto launch_result = LaunchResult();
if (mojom_launch_result->instance_ids) {
for (auto token : *mojom_launch_result->instance_ids)
for (auto token : *mojom_launch_result->instance_ids) {
launch_result.instance_ids.push_back(std::move(token));
}
} else {
launch_result.instance_ids.push_back(
std::move(mojom_launch_result->instance_id));

@ -170,12 +170,14 @@ std::vector<base::FilePath> GetLaunchFilesFromCommandLine(
#else
GURL url(arg);
#endif
if (url.is_valid() && !url.SchemeIsFile())
if (url.is_valid() && !url.SchemeIsFile()) {
continue;
}
base::FilePath path(arg);
if (path.empty())
if (path.empty()) {
continue;
}
launch_files.push_back(path);
}

@ -151,8 +151,9 @@ void PopulateLaunchNewItemFromMenuItem(const MenuItemPtr& menu_item,
int* launch_new_string_id) {
DCHECK_EQ(menu_item->command_id, ash::LAUNCH_NEW);
if (launch_new_string_id)
if (launch_new_string_id) {
*launch_new_string_id = menu_item->string_id;
}
switch (menu_item->type) {
case apps::MenuItemType::kCommand: {
@ -210,10 +211,12 @@ base::StringPiece MenuTypeToString(MenuType menu_type) {
}
MenuType MenuTypeFromString(base::StringPiece menu_type) {
if (base::EqualsCaseInsensitiveASCII(menu_type, "shelf"))
if (base::EqualsCaseInsensitiveASCII(menu_type, "shelf")) {
return MenuType::kShelf;
if (base::EqualsCaseInsensitiveASCII(menu_type, "applist"))
}
if (base::EqualsCaseInsensitiveASCII(menu_type, "applist")) {
return MenuType::kAppList;
}
return MenuType::kShelf;
}

@ -174,8 +174,9 @@ class AppNotificationsExtensionApiTest : public extensions::ExtensionApiTest {
std::set<std::string> notifications =
GetDisplayHelper()->GetNotificationIdsForExtension(extension->url());
if (notifications.size() != 1)
if (notifications.size() != 1) {
return nullptr;
}
return GetDisplayHelper()->GetByNotificationId(*notifications.begin());
}
@ -856,8 +857,9 @@ class AppNotificationsArcNotificationTest
}
void StopInstance() {
if (app_instance_)
if (app_instance_) {
arc_bridge_service()->app()->CloseInstance(app_instance_.get());
}
arc_session_manager()->Shutdown();
}

@ -783,8 +783,9 @@ bool ExtensionAppsChromeOs::IsBlocklisted(const std::string& app_id) {
// In the App Service world, there should be a unique app publisher for any
// given app. In this case, the ArcApps publisher publishes the Play Store
// app, and the ExtensionApps publisher does not.
if (app_id == arc::kPlayStoreAppId)
if (app_id == arc::kPlayStoreAppId) {
return true;
}
// If lacros chrome apps is enabled, a small list of extension apps or
// extensions on ash extension keeplist is allowed to run in both ash and

@ -233,7 +233,7 @@ apps::IntentFilters CreateIntentFilterForAppService(
// them with a single "text/*" mime type.
if (base::Contains(mime_types, "text/plain")) {
base::EraseIf(mime_types, [](const std::string& s) {
return base::StartsWith(s, "text/");
return base::StartsWith(s, "text/");
});
mime_types.push_back("text/*");
}

@ -92,8 +92,9 @@ AppPtr StandaloneBrowserApps::CreateStandaloneBrowserApp() {
InstallSource::kSystem);
app->short_name = short_name;
if (crosapi::browser_util::IsAshWebBrowserEnabled())
if (crosapi::browser_util::IsAshWebBrowserEnabled()) {
app->additional_search_terms.push_back("chrome");
}
app->icon_key = std::move(*CreateIconKey(/*is_browser_load_success=*/true));
app->searchable = true;
@ -110,8 +111,9 @@ AppPtr StandaloneBrowserApps::CreateStandaloneBrowserApp() {
void StandaloneBrowserApps::Initialize() {
auto* browser_manager = crosapi::BrowserManager::Get();
// |browser_manager| may be null in tests. For tests, assume Lacros is ready.
if (browser_manager && !observation_.IsObserving())
if (browser_manager && !observation_.IsObserving()) {
observation_.Observe(browser_manager);
}
RegisterPublisher(AppType::kStandaloneBrowser);
@ -148,8 +150,9 @@ void StandaloneBrowserApps::GetMenuModel(
void StandaloneBrowserApps::OpenNativeSettings(const std::string& app_id) {
auto* browser_manager = crosapi::BrowserManager::Get();
// `browser_manager` may be null in tests.
if (!browser_manager)
if (!browser_manager) {
return;
}
browser_manager->SwitchToTab(
chrome::GetSettingsUrl(chrome::kContentSettingsSubPage),
/*path_behavior=*/NavigateParams::RESPECT);

@ -36,8 +36,9 @@ namespace {
// Returns true if app's launch info should be saved to full restore.
bool ShouldSaveToFullRestore(AppServiceProxy* proxy,
const std::string& app_id) {
if (!::full_restore::features::IsFullRestoreForLacrosEnabled())
if (!::full_restore::features::IsFullRestoreForLacrosEnabled()) {
return false;
}
bool is_platform_app = true;
proxy->AppRegistryCache().ForOneApp(
@ -99,8 +100,9 @@ void StandaloneBrowserExtensionApps::Launch(const std::string& app_id,
WindowInfoPtr window_info) {
// It is possible that Lacros is briefly unavailable, for example if it shuts
// down for an update.
if (!controller_.is_bound())
if (!controller_.is_bound()) {
return;
}
// The following code assumes |app_type_| must be
// AppType::kStandaloneBrowserChromeApp. Therefore, the app must be either
@ -130,8 +132,9 @@ void StandaloneBrowserExtensionApps::LaunchAppWithFiles(
std::vector<base::FilePath> file_paths) {
// It is possible that Lacros is briefly unavailable, for example if it shuts
// down for an update.
if (!controller_.is_bound())
if (!controller_.is_bound()) {
return;
}
std::vector<base::FilePath> file_paths_for_restore = file_paths;
auto launch_params = crosapi::mojom::LaunchParams::New();
@ -213,8 +216,9 @@ void StandaloneBrowserExtensionApps::Uninstall(const std::string& app_id,
bool report_abuse) {
// It is possible that Lacros is briefly unavailable, for example if it shuts
// down for an update.
if (!controller_.is_bound())
if (!controller_.is_bound()) {
return;
}
controller_->Uninstall(app_id, uninstall_source, clear_site_data,
report_abuse);
@ -271,8 +275,9 @@ void StandaloneBrowserExtensionApps::SetWindowMode(const std::string& app_id,
WindowMode window_mode) {
// It is possible that Lacros is briefly unavailable, for example if it shuts
// down for an update.
if (!controller_.is_bound())
if (!controller_.is_bound()) {
return;
}
controller_->SetWindowMode(app_id, window_mode);
}
@ -280,8 +285,9 @@ void StandaloneBrowserExtensionApps::SetWindowMode(const std::string& app_id,
void StandaloneBrowserExtensionApps::StopApp(const std::string& app_id) {
// It is possible that Lacros is briefly unavailable, for example if it shuts
// down for an update.
if (!controller_.is_bound())
if (!controller_.is_bound()) {
return;
}
controller_->StopApp(app_id);
}
@ -300,8 +306,9 @@ void StandaloneBrowserExtensionApps::OpenNativeSettings(
const std::string& app_id) {
// It is possible that Lacros is briefly unavailable, for example if it shuts
// down for an update.
if (!controller_.is_bound())
if (!controller_.is_bound()) {
return;
}
controller_->OpenNativeSettings(app_id);
}

@ -310,8 +310,9 @@ void WebAppsCrosapi::ExecuteContextMenuCommand(const std::string& app_id,
}
void WebAppsCrosapi::OnApps(std::vector<AppPtr> deltas) {
if (!web_app::IsWebAppsCrosapiEnabled())
if (!web_app::IsWebAppsCrosapiEnabled()) {
return;
}
on_initial_apps_received_ = true;

@ -44,9 +44,8 @@ WebAppsCrosapiFactory::WebAppsCrosapiFactory()
std::unique_ptr<KeyedService>
WebAppsCrosapiFactory::BuildServiceInstanceForBrowserContext(
content::BrowserContext* context) const {
return std::make_unique<WebAppsCrosapi>(
AppServiceProxyFactory::GetForProfile(
Profile::FromBrowserContext(context)));
return std::make_unique<WebAppsCrosapi>(AppServiceProxyFactory::GetForProfile(
Profile::FromBrowserContext(context)));
}
} // namespace apps

@ -34,7 +34,7 @@ class WebAppsCrosapiFactory : public ProfileKeyedServiceFactory {
// BrowserContextKeyedServiceFactory overrides.
std::unique_ptr<KeyedService> BuildServiceInstanceForBrowserContext(
content::BrowserContext* context) const override;
content::BrowserContext* context) const override;
};
} // namespace apps

@ -28,8 +28,9 @@ UninstallDialog::UninstallDialog(Profile* profile,
app_name_(app_name),
parent_window_(parent_window),
uninstall_callback_(std::move(uninstall_callback)) {
if (parent_window)
if (parent_window) {
parent_window_tracker_ = views::NativeWindowTracker::Create(parent_window);
}
}
UninstallDialog::~UninstallDialog() = default;

@ -125,8 +125,9 @@ std::optional<std::string> GetInstanceAppIdForWebContents(
std::string GetAppIdForWebContents(content::WebContents* web_contents) {
const webapps::AppId* app_id =
web_app::WebAppTabHelper::GetAppId(web_contents);
if (app_id)
if (app_id) {
return *app_id;
}
extensions::TabHelper* extensions_tab_helper =
extensions::TabHelper::FromWebContents(web_contents);

@ -121,8 +121,9 @@ void SetUpdateNeededForApp(Profile* profile,
ScopedDictPrefUpdate generated_webapks(profile->GetPrefs(),
kGeneratedWebApksPref);
base::Value::Dict* app_dict = generated_webapks->FindDict(app_id);
if (app_dict)
if (app_dict) {
app_dict->Set(kUpdateNeededKey, update_needed);
}
}
base::flat_set<std::string> GetUpdateNeededAppIds(Profile* profile) {