Commit 7852489c authored by Min Qin's avatar Min Qin Committed by Commit Bot

Handle some cases download is running without full browser

When browser is not fully running, Profile cannot be accessed.
This CL also disables the use of toast as it is very expensive when
full browser is not running.

BUG=695115

Change-Id: I7560e3684307741e0a1ba01ec8efec0ff97fdbc4
Reviewed-on: https://chromium-review.googlesource.com/1165849Reviewed-by: default avatarXing Liu <xingliu@chromium.org>
Commit-Queue: Min Qin <qinmin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#581358}
parent d330e3cf
...@@ -17,11 +17,13 @@ import org.chromium.base.ApplicationStatus; ...@@ -17,11 +17,13 @@ import org.chromium.base.ApplicationStatus;
import org.chromium.base.Callback; import org.chromium.base.Callback;
import org.chromium.base.ContextUtils; import org.chromium.base.ContextUtils;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.library_loader.LibraryProcessType;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeActivity; import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.tab.Tab; import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tabmodel.TabModelSelector; import org.chromium.chrome.browser.tabmodel.TabModelSelector;
import org.chromium.chrome.browser.util.FeatureUtilities; import org.chromium.chrome.browser.util.FeatureUtilities;
import org.chromium.content_public.browser.BrowserStartupController;
import org.chromium.content_public.browser.WebContents; import org.chromium.content_public.browser.WebContents;
import org.chromium.ui.base.AndroidPermissionDelegate; import org.chromium.ui.base.AndroidPermissionDelegate;
import org.chromium.ui.base.PermissionCallback; import org.chromium.ui.base.PermissionCallback;
...@@ -252,6 +254,10 @@ public class DownloadController { ...@@ -252,6 +254,10 @@ public class DownloadController {
*/ */
@CalledByNative @CalledByNative
private static void onDownloadStarted() { private static void onDownloadStarted() {
if (!BrowserStartupController.get(LibraryProcessType.PROCESS_BROWSER)
.isStartupSuccessfullyCompleted()) {
return;
}
if (FeatureUtilities.isDownloadProgressInfoBarEnabled()) return; if (FeatureUtilities.isDownloadProgressInfoBarEnabled()) return;
DownloadUtils.showDownloadStartToast(ContextUtils.getApplicationContext()); DownloadUtils.showDownloadStartToast(ContextUtils.getApplicationContext());
} }
......
...@@ -1113,7 +1113,9 @@ public class DownloadManagerService ...@@ -1113,7 +1113,9 @@ public class DownloadManagerService
*/ */
private long getNativeDownloadManagerService() { private long getNativeDownloadManagerService() {
if (mNativeDownloadManagerService == 0) { if (mNativeDownloadManagerService == 0) {
mNativeDownloadManagerService = nativeInit(); mNativeDownloadManagerService =
nativeInit(BrowserStartupController.get(LibraryProcessType.PROCESS_BROWSER)
.isStartupSuccessfullyCompleted());
} }
return mNativeDownloadManagerService; return mNativeDownloadManagerService;
} }
...@@ -1887,7 +1889,7 @@ public class DownloadManagerService ...@@ -1887,7 +1889,7 @@ public class DownloadManagerService
private static native boolean nativeIsSupportedMimeType(String mimeType); private static native boolean nativeIsSupportedMimeType(String mimeType);
private static native int nativeGetAutoResumptionLimit(); private static native int nativeGetAutoResumptionLimit();
private native long nativeInit(); private native long nativeInit(boolean isFullBrowserStarted);
private native void nativeOpenDownload(long nativeDownloadManagerService, String downloadGuid, private native void nativeOpenDownload(long nativeDownloadManagerService, String downloadGuid,
boolean isOffTheRecord, int source); boolean isOffTheRecord, int source);
private native void nativeResumeDownload( private native void nativeResumeDownload(
......
...@@ -140,17 +140,13 @@ ScopedJavaLocalRef<jobject> DownloadManagerService::CreateJavaDownloadInfo( ...@@ -140,17 +140,13 @@ ScopedJavaLocalRef<jobject> DownloadManagerService::CreateJavaDownloadInfo(
item->GetLastAccessTime().ToJavaTime(), item->IsDangerous()); item->GetLastAccessTime().ToJavaTime(), item->IsDangerous());
} }
static jlong JNI_DownloadManagerService_Init( static jlong JNI_DownloadManagerService_Init(JNIEnv* env,
JNIEnv* env, const JavaParamRef<jobject>& jobj,
const JavaParamRef<jobject>& jobj) { jboolean is_full_browser_started) {
Profile* profile = ProfileManager::GetActiveUserProfile();
DownloadManagerService* service = DownloadManagerService::GetInstance(); DownloadManagerService* service = DownloadManagerService::GetInstance();
service->Init(env, jobj); service->Init(env, jobj);
DownloadCoreService* download_core_service = if (is_full_browser_started)
DownloadCoreServiceFactory::GetForBrowserContext(profile); service->OnFullBrowserStarted(env, jobj);
DownloadHistory* history = download_core_service->GetDownloadHistory();
if (history)
history->AddObserver(service);
return reinterpret_cast<intptr_t>(service); return reinterpret_cast<intptr_t>(service);
} }
...@@ -175,9 +171,18 @@ void DownloadManagerService::NotifyServiceStarted( ...@@ -175,9 +171,18 @@ void DownloadManagerService::NotifyServiceStarted(
void DownloadManagerService::Init( void DownloadManagerService::Init(
JNIEnv* env, JNIEnv* env,
jobject obj) { jobject obj) {
java_ref_.Reset(env, obj);
}
void DownloadManagerService::OnFullBrowserStarted(JNIEnv* env, jobject obj) {
registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CREATED, registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CREATED,
content::NotificationService::AllSources()); content::NotificationService::AllSources());
java_ref_.Reset(env, obj); Profile* profile = ProfileManager::GetActiveUserProfile();
DownloadCoreService* download_core_service =
DownloadCoreServiceFactory::GetForBrowserContext(profile);
DownloadHistory* history = download_core_service->GetDownloadHistory();
if (history)
history->AddObserver(this);
} }
void DownloadManagerService::Observe( void DownloadManagerService::Observe(
......
...@@ -58,6 +58,9 @@ class DownloadManagerService ...@@ -58,6 +58,9 @@ class DownloadManagerService
// Called to Initialize this object. // Called to Initialize this object.
void Init(JNIEnv* env, jobject obj); void Init(JNIEnv* env, jobject obj);
// Called when full browser process starts.
void OnFullBrowserStarted(JNIEnv* env, jobject obj);
// Called to open a given download item. // Called to open a given download item.
void OpenDownload(download::DownloadItem* download, int source); void OpenDownload(download::DownloadItem* download, int source);
......
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