Commit 98057b96 authored by Joel Hockey's avatar Joel Hockey Committed by Commit Bot

Add WakeLock during Plugin VM installation

Download for most URLs will already set WakeLock in ResourceDownloader,
but for Drive downloads, and then for the post-download installation we
want to set the WakeLock to avoid the devices sleeping.

Bug: b/155345403
Change-Id: I62a1b6abdc25c0f90ec26df4d5152e7e07d5414d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2398747Reviewed-by: default avatarJason Lin <lxj@google.com>
Commit-Queue: Joel Hockey <joelhockey@chromium.org>
Cr-Commit-Position: refs/heads/master@{#805620}
parent 8deb0673
...@@ -35,8 +35,10 @@ ...@@ -35,8 +35,10 @@
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "content/public/browser/browser_task_traits.h" #include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/device_service.h"
#include "content/public/browser/network_service_instance.h" #include "content/public/browser/network_service_instance.h"
#include "net/traffic_annotation/network_traffic_annotation.h" #include "net/traffic_annotation/network_traffic_annotation.h"
#include "services/device/public/mojom/wake_lock_provider.mojom.h"
namespace plugin_vm { namespace plugin_vm {
...@@ -171,6 +173,9 @@ void PluginVmInstaller::Cancel() { ...@@ -171,6 +173,9 @@ void PluginVmInstaller::Cancel() {
} }
void PluginVmInstaller::CheckLicense() { void PluginVmInstaller::CheckLicense() {
// Request wake lock when state_ goes to kInstalling, and cancel it when state
// goes back to kIdle.
GetWakeLock()->RequestWakeLock();
state_ = State::kInstalling; state_ = State::kInstalling;
UpdateInstallingState(InstallingState::kCheckingLicense); UpdateInstallingState(InstallingState::kCheckingLicense);
...@@ -920,6 +925,7 @@ void PluginVmInstaller::OnTemporaryImageRemoved(bool success) { ...@@ -920,6 +925,7 @@ void PluginVmInstaller::OnTemporaryImageRemoved(bool success) {
void PluginVmInstaller::CancelFinished() { void PluginVmInstaller::CancelFinished() {
DCHECK_EQ(state_, State::kCancelling); DCHECK_EQ(state_, State::kCancelling);
state_ = State::kIdle; state_ = State::kIdle;
GetWakeLock()->CancelWakeLock();
installing_state_ = InstallingState::kInactive; installing_state_ = InstallingState::kInactive;
if (observer_) if (observer_)
...@@ -928,6 +934,7 @@ void PluginVmInstaller::CancelFinished() { ...@@ -928,6 +934,7 @@ void PluginVmInstaller::CancelFinished() {
void PluginVmInstaller::InstallFailed(FailureReason reason) { void PluginVmInstaller::InstallFailed(FailureReason reason) {
state_ = State::kIdle; state_ = State::kIdle;
GetWakeLock()->CancelWakeLock();
installing_state_ = InstallingState::kInactive; installing_state_ = InstallingState::kInactive;
base::UmaHistogramEnumeration(kFailureReasonHistogram, reason); base::UmaHistogramEnumeration(kFailureReasonHistogram, reason);
RecordPluginVmSetupResultHistogram(PluginVmSetupResult::kError); RecordPluginVmSetupResultHistogram(PluginVmSetupResult::kError);
...@@ -939,7 +946,21 @@ void PluginVmInstaller::InstallFinished() { ...@@ -939,7 +946,21 @@ void PluginVmInstaller::InstallFinished() {
base::UmaHistogramLongTimes(kSetupTimeHistogram, base::UmaHistogramLongTimes(kSetupTimeHistogram,
base::TimeTicks::Now() - setup_start_tick_); base::TimeTicks::Now() - setup_start_tick_);
state_ = State::kIdle; state_ = State::kIdle;
GetWakeLock()->CancelWakeLock();
installing_state_ = InstallingState::kInactive; installing_state_ = InstallingState::kInactive;
} }
device::mojom::WakeLock* PluginVmInstaller::GetWakeLock() {
if (!wake_lock_) {
mojo::Remote<device::mojom::WakeLockProvider> wake_lock_provider;
content::GetDeviceService().BindWakeLockProvider(
wake_lock_provider.BindNewPipeAndPassReceiver());
wake_lock_provider->GetWakeLockWithoutContext(
device::mojom::WakeLockType::kPreventAppSuspension,
device::mojom::WakeLockReason::kOther, "Plugin VM Installer",
wake_lock_.BindNewPipeAndPassReceiver());
}
return wake_lock_.get();
}
} // namespace plugin_vm } // namespace plugin_vm
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
#include "chromeos/dbus/dlcservice/dlcservice_client.h" #include "chromeos/dbus/dlcservice/dlcservice_client.h"
#include "components/download/public/background_service/download_params.h" #include "components/download/public/background_service/download_params.h"
#include "components/keyed_service/core/keyed_service.h" #include "components/keyed_service/core/keyed_service.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "services/device/public/mojom/wake_lock.mojom.h"
namespace download { namespace download {
class DownloadService; class DownloadService;
...@@ -265,6 +267,10 @@ class PluginVmInstaller : public KeyedService, ...@@ -265,6 +267,10 @@ class PluginVmInstaller : public KeyedService,
void RemoveTemporaryImageIfExists(); void RemoveTemporaryImageIfExists();
void OnTemporaryImageRemoved(bool success); void OnTemporaryImageRemoved(bool success);
// Keep the system awake during installation.
device::mojom::WakeLock* GetWakeLock();
mojo::Remote<device::mojom::WakeLock> wake_lock_;
base::WeakPtrFactory<PluginVmInstaller> weak_ptr_factory_{this}; base::WeakPtrFactory<PluginVmInstaller> weak_ptr_factory_{this};
DISALLOW_COPY_AND_ASSIGN(PluginVmInstaller); DISALLOW_COPY_AND_ASSIGN(PluginVmInstaller);
......
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