Commit d85655c6 authored by John Abd-El-Malek's avatar John Abd-El-Malek Committed by Commit Bot

Add a WebLayer API to prewarm a spare renderer process.

Bug: 1114946
Change-Id: Id73c5537ab2de1912af57e3235e88adcdb52016c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2343770
Commit-Queue: John Abd-El-Malek <jam@chromium.org>
Reviewed-by: default avatarDarin Fisher <darin@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#797754}
parent dfbadf68
......@@ -199,6 +199,13 @@ public final class ProfileImpl extends IProfile.Stub implements BrowserContextHa
ProfileImplJni.get().removeBrowserPersistenceStorage(mNativeProfile, ids, baseCallback);
}
@Override
public void prepareForPossibleCrossOriginNavigation() {
StrictModeWorkaround.apply();
checkNotDestroyed();
ProfileImplJni.get().prepareForPossibleCrossOriginNavigation(mNativeProfile);
}
void checkNotDestroyed() {
if (!mBeingDeleted) return;
throw new IllegalArgumentException("Profile being destroyed: " + mName);
......@@ -266,5 +273,6 @@ public final class ProfileImpl extends IProfile.Stub implements BrowserContextHa
void getBrowserPersistenceIds(long nativeProfileImpl, Callback<String[]> callback);
void removeBrowserPersistenceStorage(
long nativeProfileImpl, String[] ids, Callback<Boolean> callback);
void prepareForPossibleCrossOriginNavigation(long nativeProfileImpl);
}
}
......@@ -35,4 +35,5 @@ interface IProfile {
void getBrowserPersistenceIds(in IObjectWrapper resultCallback) = 9;
void removeBrowserPersistenceStorage(in String[] ids,
in IObjectWrapper resultCallback) = 10;
void prepareForPossibleCrossOriginNavigation() = 11;
}
......@@ -26,6 +26,7 @@
#include "content/public/browser/browsing_data_remover.h"
#include "content/public/browser/device_service.h"
#include "content/public/browser/download_manager.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/storage_partition.h"
#include "services/network/public/mojom/network_context.mojom.h"
#include "weblayer/browser/android/metrics/weblayer_metrics_service_client.h"
......@@ -544,6 +545,10 @@ void ProfileImpl::RemoveBrowserPersistenceStorage(
base::flat_set<std::string>(ids.begin(), ids.end()));
}
void ProfileImpl::PrepareForPossibleCrossOriginNavigation(JNIEnv* env) {
PrepareForPossibleCrossOriginNavigation();
}
#endif // OS_ANDROID
base::FilePath ProfileImpl::GetBrowserPersisterDataBaseDir() const {
......@@ -627,6 +632,10 @@ void ProfileImpl::GetCachedFaviconForPageUrl(
&cancelable_task_tracker_);
}
void ProfileImpl::PrepareForPossibleCrossOriginNavigation() {
content::RenderProcessHost::WarmupSpareRenderProcessHost(GetBrowserContext());
}
int ProfileImpl::GetNumberOfBrowsers() {
const auto& browsers = BrowserList::GetInstance()->browsers();
return std::count_if(browsers.begin(), browsers.end(),
......
......@@ -94,6 +94,7 @@ class ProfileImpl : public Profile {
void GetCachedFaviconForPageUrl(
const GURL& page_url,
base::OnceCallback<void(gfx::Image)> callback) override;
void PrepareForPossibleCrossOriginNavigation() override;
#if defined(OS_ANDROID)
ProfileImpl(JNIEnv* env,
......@@ -125,6 +126,7 @@ class ProfileImpl : public Profile {
JNIEnv* env,
const base::android::JavaRef<jobjectArray>& j_ids,
const base::android::JavaRef<jobject>& j_callback);
void PrepareForPossibleCrossOriginNavigation(JNIEnv* env);
#endif
const base::FilePath& download_directory() { return download_directory_; }
......
......@@ -313,6 +313,30 @@ public class Profile {
}
}
/**
* If an embedder knows that a cross-origin navigation is likely starting soon they can call
* this method to start a spare renderer process. A subsequent navigation may use this
* preinitialized process, improving performance.
*
* It is safe to call this multiple times or when it is not certain that the spare renderer will
* be used, although calling this too eagerly may reduce performance as unnecessary processes
* are created.
*
* @since 85
*/
public void prepareForPossibleCrossOriginNavigation() {
ThreadCheck.ensureOnUiThread();
if (WebLayer.getSupportedMajorVersionInternal() < 85) {
throw new UnsupportedOperationException();
}
try {
mImpl.prepareForPossibleCrossOriginNavigation();
} catch (RemoteException e) {
throw new APICallException(e);
}
}
static final class DownloadCallbackClientImpl extends IDownloadCallbackClient.Stub {
private final DownloadCallback mCallback;
......
......@@ -102,6 +102,15 @@ class Profile {
virtual void GetCachedFaviconForPageUrl(
const GURL& page_url,
base::OnceCallback<void(gfx::Image)> callback) = 0;
// If an embedder knows that a cross-origin navigation is likely starting soon
// they can call this method to start a spare renderer process. A subsequent
// navigation may use this preinitialized process, improving performance.
// It is safe to call this multiple times or when it is not certain that the
// spare renderer will be used, although calling this too eagerly may reduce
// performance as unnecessary processes are created.
virtual void PrepareForPossibleCrossOriginNavigation() = 0;
};
} // namespace weblayer
......
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