Commit c83af60d authored by Shakti Sahu's avatar Shakti Sahu Committed by Commit Bot

Offline Item : Set title correctly at the offline pages backend

This CL consolidates the logic for determining the display name
 for offline pages in the backend. Earlier we were doing this
in the front-end at multiple places (e.g. download home,
notifications). With this change, we will set it as title
of the offline item in the backend itself. Downloads will also
follow a similar path after refactor to use offline items.

BUG=842803

Change-Id: I2c1a964f49f90fe5f145e5e7df95783ab6b3d269
Reviewed-on: https://chromium-review.googlesource.com/1054361
Commit-Queue: Shakti Sahu <shaktisahu@chromium.org>
Reviewed-by: default avatarDmitry Titov <dimich@chromium.org>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Cr-Commit-Position: refs/heads/master@{#560380}
parent 0da41847
...@@ -35,7 +35,6 @@ import org.chromium.components.offline_items_collection.LegacyHelpers; ...@@ -35,7 +35,6 @@ import org.chromium.components.offline_items_collection.LegacyHelpers;
import org.chromium.components.offline_items_collection.OfflineContentProvider; import org.chromium.components.offline_items_collection.OfflineContentProvider;
import org.chromium.components.offline_items_collection.OfflineItem; import org.chromium.components.offline_items_collection.OfflineItem;
import org.chromium.components.offline_items_collection.OfflineItemState; import org.chromium.components.offline_items_collection.OfflineItemState;
import org.chromium.components.url_formatter.UrlFormatter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
...@@ -559,7 +558,7 @@ public class DownloadInfoBarController implements OfflineContentProvider.Observe ...@@ -559,7 +558,7 @@ public class DownloadInfoBarController implements OfflineContentProvider.Observe
boolean singleDownloadCompleted = boolean singleDownloadCompleted =
itemCount == 1 && offlineItemState == OfflineItemState.COMPLETE; itemCount == 1 && offlineItemState == OfflineItemState.COMPLETE;
if (singleDownloadCompleted) { if (singleDownloadCompleted) {
info.message = getDisplayName(itemToShow); info.message = itemToShow.title;
info.id = itemToShow.id; info.id = itemToShow.id;
info.link = getContext().getString(R.string.open_downloaded_label); info.link = getContext().getString(R.string.open_downloaded_label);
info.hasAnimation = true; info.hasAnimation = true;
...@@ -759,16 +758,6 @@ public class DownloadInfoBarController implements OfflineContentProvider.Observe ...@@ -759,16 +758,6 @@ public class DownloadInfoBarController implements OfflineContentProvider.Observe
return downloadCount; return downloadCount;
} }
private String getDisplayName(OfflineItem item) {
if (LegacyHelpers.isLegacyOfflinePage(item.id)) {
// TODO(shaktisahu): Set the title in offline page backend.
if (!TextUtils.isEmpty(item.title)) return item.title;
return UrlFormatter.formatUrlForSecurityDisplay(item.pageUrl, false);
}
return item.title;
}
/** /**
* Clears the items in finished state, i.e. completed, failed or pending. * Clears the items in finished state, i.e. completed, failed or pending.
* @param states States to be removed. * @param states States to be removed.
......
...@@ -524,12 +524,7 @@ public abstract class DownloadHistoryItemWrapper extends TimedItem { ...@@ -524,12 +524,7 @@ public abstract class DownloadHistoryItemWrapper extends TimedItem {
@Override @Override
public String getDisplayFileName() { public String getDisplayFileName() {
String title = mItem.title; return mItem.title;
if (TextUtils.isEmpty(title)) {
return getDisplayHostname();
} else {
return title;
}
} }
@Override @Override
......
...@@ -13,23 +13,6 @@ using base::android::AttachCurrentThread; ...@@ -13,23 +13,6 @@ using base::android::AttachCurrentThread;
using base::android::ConvertUTF16ToJavaString; using base::android::ConvertUTF16ToJavaString;
using base::android::ConvertUTF8ToJavaString; using base::android::ConvertUTF8ToJavaString;
namespace {
base::android::ScopedJavaLocalRef<jstring> GetDisplayName(
const OfflineItem& item) {
JNIEnv* env = AttachCurrentThread();
if (!item.title.empty())
return ConvertUTF8ToJavaString(env, item.title);
std::string host = item.page_url.host();
if (!host.empty())
return ConvertUTF8ToJavaString(env, host);
return ConvertUTF8ToJavaString(env, item.page_url.spec());
}
} // namespace
namespace offline_pages { namespace offline_pages {
namespace android { namespace android {
...@@ -38,7 +21,8 @@ void OfflinePageNotificationBridge::NotifyDownloadSuccessful( ...@@ -38,7 +21,8 @@ void OfflinePageNotificationBridge::NotifyDownloadSuccessful(
JNIEnv* env = AttachCurrentThread(); JNIEnv* env = AttachCurrentThread();
Java_OfflinePageNotificationBridge_notifyDownloadSuccessful( Java_OfflinePageNotificationBridge_notifyDownloadSuccessful(
env, ConvertUTF8ToJavaString(env, item.id.id), env, ConvertUTF8ToJavaString(env, item.id.id),
ConvertUTF8ToJavaString(env, item.page_url.spec()), GetDisplayName(item)); ConvertUTF8ToJavaString(env, item.page_url.spec()),
ConvertUTF8ToJavaString(env, item.title));
} }
void OfflinePageNotificationBridge::NotifyDownloadFailed( void OfflinePageNotificationBridge::NotifyDownloadFailed(
...@@ -46,7 +30,8 @@ void OfflinePageNotificationBridge::NotifyDownloadFailed( ...@@ -46,7 +30,8 @@ void OfflinePageNotificationBridge::NotifyDownloadFailed(
JNIEnv* env = AttachCurrentThread(); JNIEnv* env = AttachCurrentThread();
Java_OfflinePageNotificationBridge_notifyDownloadFailed( Java_OfflinePageNotificationBridge_notifyDownloadFailed(
env, ConvertUTF8ToJavaString(env, item.id.id), env, ConvertUTF8ToJavaString(env, item.id.id),
ConvertUTF8ToJavaString(env, item.page_url.spec()), GetDisplayName(item), ConvertUTF8ToJavaString(env, item.page_url.spec()),
ConvertUTF8ToJavaString(env, item.title),
static_cast<jint>(item.fail_state)); static_cast<jint>(item.fail_state));
} }
...@@ -57,21 +42,23 @@ void OfflinePageNotificationBridge::NotifyDownloadProgress( ...@@ -57,21 +42,23 @@ void OfflinePageNotificationBridge::NotifyDownloadProgress(
env, ConvertUTF8ToJavaString(env, item.id.id), env, ConvertUTF8ToJavaString(env, item.id.id),
ConvertUTF8ToJavaString(env, item.page_url.spec()), ConvertUTF8ToJavaString(env, item.page_url.spec()),
item.creation_time.ToJavaTime(), item.received_bytes, item.creation_time.ToJavaTime(), item.received_bytes,
GetDisplayName(item)); ConvertUTF8ToJavaString(env, item.title));
} }
void OfflinePageNotificationBridge::NotifyDownloadPaused( void OfflinePageNotificationBridge::NotifyDownloadPaused(
const OfflineItem& item) { const OfflineItem& item) {
JNIEnv* env = AttachCurrentThread(); JNIEnv* env = AttachCurrentThread();
Java_OfflinePageNotificationBridge_notifyDownloadPaused( Java_OfflinePageNotificationBridge_notifyDownloadPaused(
env, ConvertUTF8ToJavaString(env, item.id.id), GetDisplayName(item)); env, ConvertUTF8ToJavaString(env, item.id.id),
ConvertUTF8ToJavaString(env, item.title));
} }
void OfflinePageNotificationBridge::NotifyDownloadInterrupted( void OfflinePageNotificationBridge::NotifyDownloadInterrupted(
const OfflineItem& item) { const OfflineItem& item) {
JNIEnv* env = AttachCurrentThread(); JNIEnv* env = AttachCurrentThread();
Java_OfflinePageNotificationBridge_notifyDownloadInterrupted( Java_OfflinePageNotificationBridge_notifyDownloadInterrupted(
env, ConvertUTF8ToJavaString(env, item.id.id), GetDisplayName(item), env, ConvertUTF8ToJavaString(env, item.id.id),
ConvertUTF8ToJavaString(env, item.title),
static_cast<jint>(item.pending_state)); static_cast<jint>(item.pending_state));
} }
......
...@@ -18,6 +18,20 @@ using PendingState = offline_items_collection::PendingState; ...@@ -18,6 +18,20 @@ using PendingState = offline_items_collection::PendingState;
namespace { namespace {
const std::string GetDisplayName(const offline_pages::OfflinePageItem& page) {
if (!page.title.empty())
return base::UTF16ToUTF8(page.title);
std::string host = page.url.host();
return host.empty() ? page.url.spec() : host;
}
const std::string GetDisplayName(
const offline_pages::SavePageRequest& request) {
std::string host = request.url().host();
return host.empty() ? request.url().spec() : host;
}
const std::string GetMimeType() { const std::string GetMimeType() {
return offline_pages::IsOfflinePagesSharingEnabled() ? "multipart/related" return offline_pages::IsOfflinePagesSharingEnabled() ? "multipart/related"
: "text/html"; : "text/html";
...@@ -32,7 +46,7 @@ OfflineItem OfflineItemConversions::CreateOfflineItem( ...@@ -32,7 +46,7 @@ OfflineItem OfflineItemConversions::CreateOfflineItem(
bool is_suggested) { bool is_suggested) {
OfflineItem item; OfflineItem item;
item.id = ContentId(kOfflinePageNamespace, page.client_id.id); item.id = ContentId(kOfflinePageNamespace, page.client_id.id);
item.title = base::UTF16ToUTF8(page.title); item.title = GetDisplayName(page);
item.filter = OfflineItemFilter::FILTER_PAGE; item.filter = OfflineItemFilter::FILTER_PAGE;
item.state = OfflineItemState::COMPLETE; item.state = OfflineItemState::COMPLETE;
item.total_size_bytes = page.file_size; item.total_size_bytes = page.file_size;
...@@ -54,6 +68,7 @@ OfflineItem OfflineItemConversions::CreateOfflineItem( ...@@ -54,6 +68,7 @@ OfflineItem OfflineItemConversions::CreateOfflineItem(
const SavePageRequest& request) { const SavePageRequest& request) {
OfflineItem item; OfflineItem item;
item.id = ContentId(kOfflinePageNamespace, request.client_id().id); item.id = ContentId(kOfflinePageNamespace, request.client_id().id);
item.title = GetDisplayName(request);
item.filter = OfflineItemFilter::FILTER_PAGE; item.filter = OfflineItemFilter::FILTER_PAGE;
item.creation_time = request.creation_time(); item.creation_time = request.creation_time();
item.total_size_bytes = -1L; item.total_size_bytes = -1L;
......
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