Commit 253a1185 authored by Mohamed Heikal's avatar Mohamed Heikal Committed by Commit Bot

Create PowerMonitor early so that it is usable in reduced mode

Currently the globally accessible PowerMonitor is created and owned by
BrowserMainLoop which is not created/run in reduced. In order to allow
PowerMonitor to be used in reduced mode, it is created in
ContentMainRunner and passed to BrowserMainLoop once full browser
starts.

Bug: 968247
Change-Id: If307dcbfb7f8ff0c7d34c2f4740f4a19ec77bf20
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1635861Reviewed-by: default avatarXi Han <hanxi@chromium.org>
Reviewed-by: default avatarJohn Abd-El-Malek <jam@chromium.org>
Commit-Queue: Mohamed Heikal <mheikal@chromium.org>
Cr-Commit-Position: refs/heads/master@{#664566}
parent 56c8db18
...@@ -32,6 +32,8 @@ ...@@ -32,6 +32,8 @@
#include "base/metrics/field_trial_params.h" #include "base/metrics/field_trial_params.h"
#include "base/metrics/histogram_base.h" #include "base/metrics/histogram_base.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "base/power_monitor/power_monitor.h"
#include "base/power_monitor/power_monitor_device_source.h"
#include "base/process/launch.h" #include "base/process/launch.h"
#include "base/process/memory.h" #include "base/process/memory.h"
#include "base/process/process.h" #include "base/process/process.h"
...@@ -949,6 +951,11 @@ int ContentMainRunnerImpl::RunServiceManager(MainFunctionParams& main_params, ...@@ -949,6 +951,11 @@ int ContentMainRunnerImpl::RunServiceManager(MainFunctionParams& main_params,
} }
} }
// PowerMonitor is needed in reduced mode but is eventually passed on to
// BrowserMainLoop.
power_monitor_ = std::make_unique<base::PowerMonitor>(
std::make_unique<base::PowerMonitorDeviceSource>());
// The thread used to start the ServiceManager is handed-off to // The thread used to start the ServiceManager is handed-off to
// BrowserMain() which may elect to promote it (e.g. to BrowserThread::IO). // BrowserMain() which may elect to promote it (e.g. to BrowserThread::IO).
service_manager_thread_ = BrowserTaskExecutor::CreateIOThread(); service_manager_thread_ = BrowserTaskExecutor::CreateIOThread();
...@@ -970,6 +977,7 @@ int ContentMainRunnerImpl::RunServiceManager(MainFunctionParams& main_params, ...@@ -970,6 +977,7 @@ int ContentMainRunnerImpl::RunServiceManager(MainFunctionParams& main_params,
startup_data_ = std::make_unique<StartupDataImpl>(); startup_data_ = std::make_unique<StartupDataImpl>();
startup_data_->thread = std::move(service_manager_thread_); startup_data_->thread = std::move(service_manager_thread_);
startup_data_->service_manager_context = service_manager_context_.get(); startup_data_->service_manager_context = service_manager_context_.get();
startup_data_->power_monitor = std::move(power_monitor_);
main_params.startup_data = startup_data_.get(); main_params.startup_data = startup_data_.get();
return RunBrowserProcessMain(main_params, delegate_); return RunBrowserProcessMain(main_params, delegate_);
} }
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/callback_forward.h" #include "base/callback_forward.h"
#include "base/memory/scoped_refptr.h" #include "base/memory/scoped_refptr.h"
#include "base/metrics/field_trial.h" #include "base/metrics/field_trial.h"
#include "base/power_monitor/power_monitor.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "content/browser/service_manager/service_manager_context.h" #include "content/browser/service_manager/service_manager_context.h"
#include "content/browser/startup_data_impl.h" #include "content/browser/startup_data_impl.h"
...@@ -57,6 +58,7 @@ class ContentMainRunnerImpl : public ContentMainRunner { ...@@ -57,6 +58,7 @@ class ContentMainRunnerImpl : public ContentMainRunner {
std::unique_ptr<base::FieldTrialList> field_trial_list_; std::unique_ptr<base::FieldTrialList> field_trial_list_;
std::unique_ptr<BrowserProcessSubThread> service_manager_thread_; std::unique_ptr<BrowserProcessSubThread> service_manager_thread_;
std::unique_ptr<ServiceManagerContext> service_manager_context_; std::unique_ptr<ServiceManagerContext> service_manager_context_;
std::unique_ptr<base::PowerMonitor> power_monitor_;
#endif // !defined(CHROME_MULTIPLE_DLL_CHILD) #endif // !defined(CHROME_MULTIPLE_DLL_CHILD)
// True if the runner has been initialized. // True if the runner has been initialized.
......
...@@ -566,6 +566,7 @@ void BrowserMainLoop::Init() { ...@@ -566,6 +566,7 @@ void BrowserMainLoop::Init() {
// resets it). // resets it).
io_thread_ = std::move(startup_data->thread); io_thread_ = std::move(startup_data->thread);
service_manager_context_ = startup_data->service_manager_context; service_manager_context_ = startup_data->service_manager_context;
power_monitor_ = std::move(startup_data->power_monitor);
} }
parts_.reset( parts_.reset(
...@@ -691,10 +692,10 @@ void BrowserMainLoop::PostMainMessageLoopStart() { ...@@ -691,10 +692,10 @@ void BrowserMainLoop::PostMainMessageLoopStart() {
} }
{ {
TRACE_EVENT0("startup", "BrowserMainLoop::Subsystem:PowerMonitor"); TRACE_EVENT0("startup", "BrowserMainLoop::Subsystem:PowerMonitor");
std::unique_ptr<base::PowerMonitorSource> power_monitor_source( if (!power_monitor_) {
new base::PowerMonitorDeviceSource()); power_monitor_ = std::make_unique<base::PowerMonitor>(
power_monitor_.reset( std::make_unique<base::PowerMonitorDeviceSource>());
new base::PowerMonitor(std::move(power_monitor_source))); }
} }
{ {
TRACE_EVENT0("startup", "BrowserMainLoop::Subsystem:HighResTimerManager"); TRACE_EVENT0("startup", "BrowserMainLoop::Subsystem:HighResTimerManager");
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <memory> #include <memory>
#include "base/power_monitor/power_monitor.h"
#include "content/browser/browser_process_sub_thread.h" #include "content/browser/browser_process_sub_thread.h"
#include "content/common/content_export.h" #include "content/common/content_export.h"
#include "content/public/browser/startup_data.h" #include "content/public/browser/startup_data.h"
...@@ -22,6 +23,7 @@ struct CONTENT_EXPORT StartupDataImpl : public StartupData { ...@@ -22,6 +23,7 @@ struct CONTENT_EXPORT StartupDataImpl : public StartupData {
std::unique_ptr<BrowserProcessSubThread> thread; std::unique_ptr<BrowserProcessSubThread> thread;
ServiceManagerContext* service_manager_context; ServiceManagerContext* service_manager_context;
std::unique_ptr<base::PowerMonitor> power_monitor;
}; };
} // namespace content } // namespace content
......
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