Commit 638786f9 authored by Andrew Grieve's avatar Andrew Grieve Committed by Commit Bot

Disallow use of ApplicationStatus on non-main processes

This will help to reduce the main dex size of debug apks.

TBR=agrieve  # ComponentsBrowserTestApplication same as ContentBrowserTestsApplication

Bug: 820570
Cq-Include-Trybots: luci.chromium.try:linux_optional_gpu_tests_rel;master.tryserver.chromium.android:android_optional_gpu_tests_rel;master.tryserver.chromium.linux:linux_optional_gpu_tests_rel;master.tryserver.chromium.mac:mac_optional_gpu_tests_rel;master.tryserver.chromium.win:win_optional_gpu_tests_rel
Change-Id: Ie380d22faa10d2a9b4527574859770f39800af71
Reviewed-on: https://chromium-review.googlesource.com/962874Reviewed-by: default avataragrieve <agrieve@chromium.org>
Reviewed-by: default avatarYaron Friedman <yfriedman@chromium.org>
Reviewed-by: default avatarKenneth Russell <kbr@chromium.org>
Reviewed-by: default avatarSiddhartha S <ssid@chromium.org>
Commit-Queue: agrieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543608}
parent cc9da0dd
......@@ -69,6 +69,15 @@ public class ApplicationStatus {
}
}
static {
// Chrome initializes this only for the main process. This assert aims to try and catch
// usages from GPU / renderers, while still allowing tests.
assert ContextUtils.isMainProcess()
|| ContextUtils.getProcessName().contains(":test")
: "Cannot use ApplicationState from process: "
+ ContextUtils.getProcessName();
}
private static final Object sCachedApplicationStateLock = new Object();
@SuppressLint("SupportAnnotationUsage")
......
......@@ -22,16 +22,15 @@ public class ComponentsBrowserTestsApplication extends Application {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
if (BuildConfig.IS_MULTIDEX_ENABLED) {
ContextUtils.initApplicationContext(this);
// The test harness runs in the main process, and browser in :test_process.
boolean isBrowserProcess = ContextUtils.getProcessName().contains(":test");
if (BuildConfig.IS_MULTIDEX_ENABLED && (ContextUtils.isMainProcess() || isBrowserProcess)) {
ChromiumMultiDexInstaller.install(this);
}
ContextUtils.initApplicationContext(this);
}
@Override
public void onCreate() {
super.onCreate();
PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX);
ApplicationStatus.initialize(this);
if (isBrowserProcess) {
PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX);
ApplicationStatus.initialize(this);
}
}
}
......@@ -22,16 +22,16 @@ public class ContentBrowserTestsApplication extends Application {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
ContextUtils.initApplicationContext(this);
// content_browsertests needs secondary dex in order to run EmbeddedTestServer in a
// privileged process.
if (BuildConfig.IS_MULTIDEX_ENABLED) {
ChromiumMultiDexInstaller.install(this);
}
ContextUtils.initApplicationContext(this);
}
@Override
public void onCreate() {
super.onCreate();
PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX);
ApplicationStatus.initialize(this);
// The test harness runs in the main process, and browser in :test_process.
if (ContextUtils.getProcessName().contains(":test")) {
PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX);
ApplicationStatus.initialize(this);
}
}
}
......@@ -25,12 +25,14 @@ public class ContentShellApplication extends Application {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
if (BuildConfig.IS_MULTIDEX_ENABLED) {
ChromiumMultiDexInstaller.install(this);
}
ContextUtils.initApplicationContext(this);
PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX);
ApplicationStatus.initialize(this);
if (ContextUtils.isMainProcess()) {
if (BuildConfig.IS_MULTIDEX_ENABLED) {
ChromiumMultiDexInstaller.install(this);
}
PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX);
ApplicationStatus.initialize(this);
}
}
public void initCommandLine() {
......
......@@ -74,12 +74,6 @@ GpuChannelManager::GpuChannelManager(
gpu_memory_buffer_factory_(gpu_memory_buffer_factory),
gpu_feature_info_(gpu_feature_info),
#if defined(OS_ANDROID)
// Runs on GPU main thread and unregisters when the listener is destroyed,
// So, Unretained is fine here.
application_status_listener_(
base::Bind(&GpuChannelManager::OnApplicationStateChange,
base::Unretained(this))),
is_running_on_low_end_mode_(base::SysInfo::IsLowEndDevice()),
is_backgrounded_for_testing_(false),
#endif
exiting_for_lost_context_(false),
......@@ -92,6 +86,18 @@ GpuChannelManager::GpuChannelManager(
DCHECK(task_runner->BelongsToCurrentThread());
DCHECK(io_task_runner);
DCHECK(scheduler);
#if defined(OS_ANDROID)
// ApplicationStatusListener does not currently support being used from
// non-browser processes. Enable this optimization only for low-end, where GPU
// is run in-process.
if (base::SysInfo::IsLowEndDevice()) {
// Runs on GPU main thread and unregisters when the listener is destroyed,
// So, Unretained is fine here.
application_status_listener_.emplace(base::Bind(
&GpuChannelManager::OnApplicationStateChange, base::Unretained(this)));
}
#endif
}
GpuChannelManager::~GpuChannelManager() {
......@@ -270,8 +276,7 @@ void GpuChannelManager::OnApplicationStateChange(
// https://crbug.com/792120. Re-enable when the fix lands.
return;
if (state != base::android::APPLICATION_STATE_HAS_STOPPED_ACTIVITIES ||
!is_running_on_low_end_mode_) {
if (state != base::android::APPLICATION_STATE_HAS_STOPPED_ACTIVITIES) {
return;
}
......@@ -302,9 +307,6 @@ void GpuChannelManager::OnApplicationBackgrounded() {
return;
}
if (!is_running_on_low_end_mode_)
return;
// Delete all the GL contexts when the channel does not use WebGL and Chrome
// goes to background on low-end devices.
std::vector<int> channels_to_clear;
......
......@@ -16,6 +16,7 @@
#include "base/memory/memory_pressure_listener.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "base/optional.h"
#include "base/single_thread_task_runner.h"
#include "build/build_config.h"
#include "gpu/command_buffer/common/activity_flags.h"
......@@ -128,10 +129,6 @@ class GPU_IPC_SERVICE_EXPORT GpuChannelManager {
void OnApplicationStateChange(base::android::ApplicationState state);
void set_low_end_mode_for_testing(bool mode) {
is_running_on_low_end_mode_ = mode;
}
void OnApplicationBackgroundedForTesting();
#endif
......@@ -193,8 +190,8 @@ class GPU_IPC_SERVICE_EXPORT GpuChannelManager {
base::TimeTicks last_gpu_access_time_;
base::TimeTicks begin_wake_up_time_;
base::android::ApplicationStatusListener application_status_listener_;
bool is_running_on_low_end_mode_;
base::Optional<base::android::ApplicationStatusListener>
application_status_listener_;
bool is_backgrounded_for_testing_;
#endif
......
......@@ -72,19 +72,12 @@ TEST_F(GpuChannelManagerTest, EstablishChannel) {
#if defined(OS_ANDROID)
TEST_F(GpuChannelManagerTest, OnLowEndBackgroundedWithoutWebGL) {
channel_manager()->set_low_end_mode_for_testing(true);
TestOnApplicationStateChange(CONTEXT_TYPE_OPENGLES2, true);
}
TEST_F(GpuChannelManagerTest, OnLowEndBackgroundedWithWebGL) {
channel_manager()->set_low_end_mode_for_testing(true);
TestOnApplicationStateChange(CONTEXT_TYPE_WEBGL2, false);
}
TEST_F(GpuChannelManagerTest, OnHighEndBackgrounded) {
channel_manager()->set_low_end_mode_for_testing(false);
TestOnApplicationStateChange(CONTEXT_TYPE_OPENGLES2, false);
}
#endif
} // namespace gpu
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