Skip to content

Commit

Permalink
Prefer opening Downloads Home showing prefetched articles
Browse files Browse the repository at this point in the history
When opening the Downloads Home from the dino/offline page, if there are
available prefetched articles, it should be opened focusing on
presenting them.

Bug: 852872
Change-Id: Icccc4669fe4c5d2b44676fefb3a691a2b35c11cc
Reviewed-on: https://chromium-review.googlesource.com/1196015
Reviewed-by: Min Qin <qinmin@chromium.org>
Reviewed-by: Dan H <harringtond@google.com>
Commit-Queue: Carlos Knippschild <carlosk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#587373}
  • Loading branch information
chuim authored and Commit Bot committed Aug 30, 2018
1 parent d99176f commit 80999dd
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1663,8 +1663,8 @@ private void onDownloadItemRemoved(String guid, boolean isOffTheRecord) {
}

@CalledByNative
private void showDownloadManager() {
DownloadManagerService.openDownloadsPage(ContextUtils.getApplicationContext());
private void showDownloadManager(boolean showPrefetchedContent) {
DownloadUtils.showDownloadManager(null, null, showPrefetchedContent);
}

@CalledByNative
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ void AvailableOfflineContentProvider::LaunchItem(
}

void AvailableOfflineContentProvider::LaunchDownloadsPage() {
DownloadManagerService::GetInstance()->ShowDownloadManager();
DownloadManagerService::GetInstance()->ShowDownloadManager(
has_prefetched_content_);
}

void AvailableOfflineContentProvider::Create(
Expand Down Expand Up @@ -251,6 +252,7 @@ void AvailableOfflineContentProvider::SummarizeFinalize(
summary->has_audio = true;
}
}
has_prefetched_content_ = summary->has_prefetched_page;
std::move(callback).Run(std::move(summary));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ class AvailableOfflineContentProvider

content::BrowserContext* browser_context_;

// Records if the last content fetch indicated that prefetched articles are
// available or not.
// TODO(carlosk): Directly check the existence of prefetched articles.
bool has_prefetched_content_ = false;

base::WeakPtrFactory<AvailableOfflineContentProvider> weak_ptr_factory_;

DISALLOW_COPY_AND_ASSIGN(AvailableOfflineContentProvider);
Expand Down
5 changes: 3 additions & 2 deletions chrome/browser/android/download/download_manager_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,10 @@ DownloadManagerService::RetriveInProgressDownloadManager(
return nullptr;
}

void DownloadManagerService::ShowDownloadManager() {
void DownloadManagerService::ShowDownloadManager(bool show_prefetched_content) {
JNIEnv* env = base::android::AttachCurrentThread();
Java_DownloadManagerService_showDownloadManager(env, java_ref_);
Java_DownloadManagerService_showDownloadManager(
env, java_ref_, static_cast<jboolean>(show_prefetched_content));
}

void DownloadManagerService::OpenDownload(download::DownloadItem* download,
Expand Down
5 changes: 3 additions & 2 deletions chrome/browser/android/download/download_manager_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ class DownloadManagerService
// Called when full browser process starts.
void OnFullBrowserStarted(JNIEnv* env, jobject obj);

// Called to show the download manager.
void ShowDownloadManager();
// Called to show the download manager, with a choice to focus on prefetched
// content instead of regular downloads.
void ShowDownloadManager(bool show_prefetched_content);

// Called to open a given download item.
void OpenDownload(download::DownloadItem* download, int source);
Expand Down

0 comments on commit 80999dd

Please sign in to comment.