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 { ...@@ -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(); private static final Object sCachedApplicationStateLock = new Object();
@SuppressLint("SupportAnnotationUsage") @SuppressLint("SupportAnnotationUsage")
......
...@@ -22,16 +22,15 @@ public class ComponentsBrowserTestsApplication extends Application { ...@@ -22,16 +22,15 @@ public class ComponentsBrowserTestsApplication extends Application {
@Override @Override
protected void attachBaseContext(Context base) { protected void attachBaseContext(Context base) {
super.attachBaseContext(base); super.attachBaseContext(base);
if (BuildConfig.IS_MULTIDEX_ENABLED) {
ChromiumMultiDexInstaller.install(this);
}
ContextUtils.initApplicationContext(this); 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);
} }
if (isBrowserProcess) {
@Override
public void onCreate() {
super.onCreate();
PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX); PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX);
ApplicationStatus.initialize(this); ApplicationStatus.initialize(this);
} }
}
} }
...@@ -22,16 +22,16 @@ public class ContentBrowserTestsApplication extends Application { ...@@ -22,16 +22,16 @@ public class ContentBrowserTestsApplication extends Application {
@Override @Override
protected void attachBaseContext(Context base) { protected void attachBaseContext(Context base) {
super.attachBaseContext(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) { if (BuildConfig.IS_MULTIDEX_ENABLED) {
ChromiumMultiDexInstaller.install(this); ChromiumMultiDexInstaller.install(this);
} }
ContextUtils.initApplicationContext(this); // The test harness runs in the main process, and browser in :test_process.
} if (ContextUtils.getProcessName().contains(":test")) {
@Override
public void onCreate() {
super.onCreate();
PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX); PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX);
ApplicationStatus.initialize(this); ApplicationStatus.initialize(this);
} }
}
} }
...@@ -25,13 +25,15 @@ public class ContentShellApplication extends Application { ...@@ -25,13 +25,15 @@ public class ContentShellApplication extends Application {
@Override @Override
protected void attachBaseContext(Context base) { protected void attachBaseContext(Context base) {
super.attachBaseContext(base); super.attachBaseContext(base);
ContextUtils.initApplicationContext(this);
if (ContextUtils.isMainProcess()) {
if (BuildConfig.IS_MULTIDEX_ENABLED) { if (BuildConfig.IS_MULTIDEX_ENABLED) {
ChromiumMultiDexInstaller.install(this); ChromiumMultiDexInstaller.install(this);
} }
ContextUtils.initApplicationContext(this);
PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX); PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX);
ApplicationStatus.initialize(this); ApplicationStatus.initialize(this);
} }
}
public void initCommandLine() { public void initCommandLine() {
if (!CommandLine.isInitialized()) { if (!CommandLine.isInitialized()) {
......
...@@ -74,12 +74,6 @@ GpuChannelManager::GpuChannelManager( ...@@ -74,12 +74,6 @@ GpuChannelManager::GpuChannelManager(
gpu_memory_buffer_factory_(gpu_memory_buffer_factory), gpu_memory_buffer_factory_(gpu_memory_buffer_factory),
gpu_feature_info_(gpu_feature_info), gpu_feature_info_(gpu_feature_info),
#if defined(OS_ANDROID) #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), is_backgrounded_for_testing_(false),
#endif #endif
exiting_for_lost_context_(false), exiting_for_lost_context_(false),
...@@ -92,6 +86,18 @@ GpuChannelManager::GpuChannelManager( ...@@ -92,6 +86,18 @@ GpuChannelManager::GpuChannelManager(
DCHECK(task_runner->BelongsToCurrentThread()); DCHECK(task_runner->BelongsToCurrentThread());
DCHECK(io_task_runner); DCHECK(io_task_runner);
DCHECK(scheduler); 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() { GpuChannelManager::~GpuChannelManager() {
...@@ -270,8 +276,7 @@ void GpuChannelManager::OnApplicationStateChange( ...@@ -270,8 +276,7 @@ void GpuChannelManager::OnApplicationStateChange(
// https://crbug.com/792120. Re-enable when the fix lands. // https://crbug.com/792120. Re-enable when the fix lands.
return; return;
if (state != base::android::APPLICATION_STATE_HAS_STOPPED_ACTIVITIES || if (state != base::android::APPLICATION_STATE_HAS_STOPPED_ACTIVITIES) {
!is_running_on_low_end_mode_) {
return; return;
} }
...@@ -302,9 +307,6 @@ void GpuChannelManager::OnApplicationBackgrounded() { ...@@ -302,9 +307,6 @@ void GpuChannelManager::OnApplicationBackgrounded() {
return; return;
} }
if (!is_running_on_low_end_mode_)
return;
// Delete all the GL contexts when the channel does not use WebGL and Chrome // Delete all the GL contexts when the channel does not use WebGL and Chrome
// goes to background on low-end devices. // goes to background on low-end devices.
std::vector<int> channels_to_clear; std::vector<int> channels_to_clear;
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "base/memory/memory_pressure_listener.h" #include "base/memory/memory_pressure_listener.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/optional.h"
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "gpu/command_buffer/common/activity_flags.h" #include "gpu/command_buffer/common/activity_flags.h"
...@@ -128,10 +129,6 @@ class GPU_IPC_SERVICE_EXPORT GpuChannelManager { ...@@ -128,10 +129,6 @@ class GPU_IPC_SERVICE_EXPORT GpuChannelManager {
void OnApplicationStateChange(base::android::ApplicationState state); void OnApplicationStateChange(base::android::ApplicationState state);
void set_low_end_mode_for_testing(bool mode) {
is_running_on_low_end_mode_ = mode;
}
void OnApplicationBackgroundedForTesting(); void OnApplicationBackgroundedForTesting();
#endif #endif
...@@ -193,8 +190,8 @@ class GPU_IPC_SERVICE_EXPORT GpuChannelManager { ...@@ -193,8 +190,8 @@ class GPU_IPC_SERVICE_EXPORT GpuChannelManager {
base::TimeTicks last_gpu_access_time_; base::TimeTicks last_gpu_access_time_;
base::TimeTicks begin_wake_up_time_; base::TimeTicks begin_wake_up_time_;
base::android::ApplicationStatusListener application_status_listener_; base::Optional<base::android::ApplicationStatusListener>
bool is_running_on_low_end_mode_; application_status_listener_;
bool is_backgrounded_for_testing_; bool is_backgrounded_for_testing_;
#endif #endif
......
...@@ -72,19 +72,12 @@ TEST_F(GpuChannelManagerTest, EstablishChannel) { ...@@ -72,19 +72,12 @@ TEST_F(GpuChannelManagerTest, EstablishChannel) {
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
TEST_F(GpuChannelManagerTest, OnLowEndBackgroundedWithoutWebGL) { TEST_F(GpuChannelManagerTest, OnLowEndBackgroundedWithoutWebGL) {
channel_manager()->set_low_end_mode_for_testing(true);
TestOnApplicationStateChange(CONTEXT_TYPE_OPENGLES2, true); TestOnApplicationStateChange(CONTEXT_TYPE_OPENGLES2, true);
} }
TEST_F(GpuChannelManagerTest, OnLowEndBackgroundedWithWebGL) { TEST_F(GpuChannelManagerTest, OnLowEndBackgroundedWithWebGL) {
channel_manager()->set_low_end_mode_for_testing(true);
TestOnApplicationStateChange(CONTEXT_TYPE_WEBGL2, false); TestOnApplicationStateChange(CONTEXT_TYPE_WEBGL2, false);
} }
TEST_F(GpuChannelManagerTest, OnHighEndBackgrounded) {
channel_manager()->set_low_end_mode_for_testing(false);
TestOnApplicationStateChange(CONTEXT_TYPE_OPENGLES2, false);
}
#endif #endif
} // namespace gpu } // 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