Commit 60c28ffd authored by Sorin Jianu's avatar Sorin Jianu Committed by Commit Bot

Make derived classes from updater::App singletons.

Some future work for the COM server requires accessing the ComServer
instance, and there is no way to get to it starting from the
objects instantiated by COM factories as a response to an RPC call.

Bug: 1064498

Change-Id: I45923bf70cd922cb30a766fabea9bee87f524ebe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2119213
Commit-Queue: Sorin Jianu <sorin@chromium.org>
Reviewed-by: default avatarJoshua Pawlicki <waffles@chromium.org>
Cr-Commit-Position: refs/heads/master@{#753249}
parent 4ca9f79e
......@@ -7,11 +7,23 @@
#include "base/callback.h"
#include "base/memory/ref_counted.h"
#include "base/no_destructor.h"
#include "base/strings/string_piece.h"
namespace updater {
// An App is a main processing mode for the updater.
// Creates a ref-counted singleton instance of the type T. Use this function
// to get instances of classes derived from updater::App.
template <typename T>
scoped_refptr<T> AppInstance() {
static base::NoDestructor<scoped_refptr<T>> instance{
base::MakeRefCounted<T>()};
return *instance;
}
// An App is an abstract class used as a main processing mode for the updater.
// Instances of classes derived from App must be accessed as singletons by
// calling the function template AppInstance<T>.
class App : public base::RefCountedThreadSafe<App> {
public:
// Starts the thread pool and task executor, then runs a runloop on the main
......
......@@ -22,6 +22,9 @@ namespace updater {
// AppUninstall uninstalls the updater.
class AppUninstall : public App {
public:
AppUninstall() = default;
private:
~AppUninstall() override = default;
void FirstTaskRun() override;
......@@ -33,8 +36,8 @@ void AppUninstall::FirstTaskRun() {
base::BindOnce(&AppUninstall::Shutdown, this));
}
scoped_refptr<App> MakeAppUninstall() {
return base::MakeRefCounted<AppUninstall>();
scoped_refptr<App> AppUninstallInstance() {
return AppInstance<AppUninstall>();
}
} // namespace updater
......@@ -11,7 +11,7 @@ namespace updater {
class App;
scoped_refptr<App> MakeAppUninstall();
scoped_refptr<App> AppUninstallInstance();
} // namespace updater
......
......@@ -17,6 +17,9 @@
namespace updater {
class AppUpdateAll : public App {
public:
AppUpdateAll() = default;
private:
~AppUpdateAll() override = default;
......@@ -50,8 +53,8 @@ void AppUpdateAll::FirstTaskRun() {
base::BindOnce(&AppUpdateAll::Shutdown, this)));
}
scoped_refptr<App> MakeAppUpdateAll() {
return base::MakeRefCounted<AppUpdateAll>();
scoped_refptr<App> AppUpdateAllInstance() {
return AppInstance<AppUpdateAll>();
}
} // namespace updater
......@@ -11,7 +11,7 @@ namespace updater {
class App;
scoped_refptr<App> MakeAppUpdateAll();
scoped_refptr<App> AppUpdateAllInstance();
} // namespace updater
......
......@@ -11,7 +11,7 @@ namespace updater {
class App;
scoped_refptr<App> MakeAppServer();
scoped_refptr<App> AppServerInstance();
} // namespace updater
......
......@@ -8,7 +8,6 @@
#include <xpc/xpc.h>
#include "base/mac/scoped_nsobject.h"
#include "base/memory/ref_counted.h"
#include "base/strings/sys_string_conversions.h"
#include "base/task/task_traits.h"
#include "base/task/thread_pool.h"
......@@ -57,8 +56,8 @@ void AppServer::FirstTaskRun() {
}
}
scoped_refptr<App> MakeAppServer() {
return base::MakeRefCounted<AppServer>();
scoped_refptr<App> AppServerInstance() {
return AppInstance<AppServer>();
}
} // namespace updater
......@@ -19,7 +19,6 @@
#include <memory>
#include "base/logging.h"
#include "base/memory/ref_counted.h"
#include "base/stl_util.h"
#include "base/system/sys_info.h"
#include "base/task/thread_pool/thread_pool_instance.h"
......@@ -206,8 +205,8 @@ void ComServer::FirstTaskRun() {
Shutdown(hr);
}
scoped_refptr<App> MakeAppServer() {
return base::MakeRefCounted<ComServer>();
scoped_refptr<App> AppServerInstance() {
return AppInstance<ComServer>();
}
} // namespace updater
......@@ -63,7 +63,7 @@ class UpdaterImpl
class App;
scoped_refptr<App> MakeAppServer();
scoped_refptr<App> AppServerInstance();
} // namespace updater
......
......@@ -90,7 +90,7 @@ int HandleUpdaterCommands(const base::CommandLine* command_line) {
#endif
if (command_line->HasSwitch(kServerSwitch)) {
return MakeAppServer()->Run();
return AppServerInstance()->Run();
}
#if defined(OS_WIN)
......@@ -98,14 +98,14 @@ int HandleUpdaterCommands(const base::CommandLine* command_line) {
return ServiceMain::RunComService(command_line);
if (command_line->HasSwitch(kInstallSwitch))
return MakeAppInstall({kChromeAppId})->Run();
return AppInstallInstance()->Run();
#endif // OS_WIN
if (command_line->HasSwitch(kUninstallSwitch))
return MakeAppUninstall()->Run();
return AppUninstallInstance()->Run();
if (command_line->HasSwitch(kUpdateAppsSwitch)) {
return MakeAppUpdateAll()->Run();
return AppUpdateAllInstance()->Run();
}
VLOG(1) << "Unknown command line switch.";
......
......@@ -692,10 +692,11 @@ DWORD InstallAppController::GetUIThreadID() const {
} // namespace
// Installs the updater and one application specified by |app_id|.
// Sets the updater up, shows up a splash screen, then installs an application
// while displaying the UI progress window.
class AppInstall : public App {
public:
explicit AppInstall(const std::string& app_id);
AppInstall() = default;
private:
~AppInstall() override = default;
......@@ -705,7 +706,10 @@ class AppInstall : public App {
void SetupDone(int result);
std::string app_id_;
// TODO(sorin): remove the hardcoding of the application id.
// https://crbug.com/1014298
const std::string app_id_ = {kChromeAppId};
scoped_refptr<Configurator> config_;
scoped_refptr<InstallAppController> app_install_controller_;
......@@ -714,8 +718,6 @@ class AppInstall : public App {
std::unique_ptr<ui::SplashScreen> splash_screen_;
};
AppInstall::AppInstall(const std::string& app_id) : app_id_(app_id) {}
void AppInstall::Initialize() {
base::i18n::InitializeICU();
config_ = base::MakeRefCounted<Configurator>();
......@@ -758,12 +760,12 @@ void AppInstall::SetupDone(int result) {
app_id_, base::BindOnce(&AppInstall::Shutdown, this));
}
scoped_refptr<App> MakeAppInstall(const std::string& app_id) {
scoped_refptr<App> AppInstallInstance() {
// TODO(sorin) "--install" must be run with "--single-process" until
// crbug.com/1053729 is resolved.
DCHECK(
base::CommandLine::ForCurrentProcess()->HasSwitch(kSingleProcessSwitch));
return base::MakeRefCounted<AppInstall>(app_id);
return AppInstance<AppInstall>();
}
} // namespace updater
......@@ -13,9 +13,7 @@ namespace updater {
class App;
// Sets the updater up, shows up a splash screen, then installs an application
// while displaying the UI progress window.
scoped_refptr<App> MakeAppInstall(const std::string& app_id);
scoped_refptr<App> AppInstallInstance();
} // namespace updater
......
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