Commit 98446f4d authored by sebsg's avatar sebsg Committed by Commit Bot

[SendTabToSelf] Handle null navigation entries when creating new shares.

Bug: 990685
Change-Id: Ie639f3910a56cc6ec92551881312e5423586d0e2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1737429
Commit-Queue: Jeffrey Cohen <jeffreycohen@chromium.org>
Reviewed-by: default avatarJeffrey Cohen <jeffreycohen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#684367}
parent e4f1ea15
...@@ -28,37 +28,47 @@ void CreateNewEntry(content::WebContents* tab, ...@@ -28,37 +28,47 @@ void CreateNewEntry(content::WebContents* tab,
const std::string& target_device_name, const std::string& target_device_name,
const std::string& target_device_guid, const std::string& target_device_guid,
const GURL& link_url) { const GURL& link_url) {
DCHECK(tab);
GURL shared_url = link_url;
std::string title = "";
base::Time navigation_time = base::Time();
content::NavigationEntry* navigation_entry = content::NavigationEntry* navigation_entry =
tab->GetController().GetLastCommittedEntry(); tab->GetController().GetLastCommittedEntry();
Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
GURL url = navigation_entry->GetURL();
std::string title = base::UTF16ToUTF8(navigation_entry->GetTitle());
base::Time navigation_time = navigation_entry->GetTimestamp();
// This should either be a valid link share or a valid tab share.
DCHECK(link_url.is_valid() || navigation_entry);
if (!link_url.is_valid()) {
// This is not link share, get the values from the last navigation entry.
shared_url = navigation_entry->GetURL();
title = base::UTF16ToUTF8(navigation_entry->GetTitle());
navigation_time = navigation_entry->GetTimestamp();
}
Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
DCHECK(profile);
SendTabToSelfModel* model = SendTabToSelfModel* model =
SendTabToSelfSyncServiceFactory::GetForProfile(profile) SendTabToSelfSyncServiceFactory::GetForProfile(profile)
->GetSendTabToSelfModel(); ->GetSendTabToSelfModel();
DCHECK(model);
UMA_HISTOGRAM_BOOLEAN("SendTabToSelf.Sync.ModelLoadedInTime", UMA_HISTOGRAM_BOOLEAN("SendTabToSelf.Sync.ModelLoadedInTime",
model->IsReady()); model->IsReady());
if (!model->IsReady()) { if (!model->IsReady()) {
DesktopNotificationHandler(profile).DisplayFailureMessage(url); DesktopNotificationHandler(profile).DisplayFailureMessage(shared_url);
return; return;
} }
const SendTabToSelfEntry* entry; const SendTabToSelfEntry* entry =
if (link_url.is_valid()) { model->AddEntry(shared_url, title, navigation_time, target_device_guid);
// When share a link.
entry = model->AddEntry(link_url, "", base::Time(), target_device_guid);
} else {
// When share a tab.
entry = model->AddEntry(url, title, navigation_time, target_device_guid);
}
if (entry) { if (entry) {
DesktopNotificationHandler(profile).DisplaySendingConfirmation( DesktopNotificationHandler(profile).DisplaySendingConfirmation(
*entry, target_device_name); *entry, target_device_name);
} else { } else {
DesktopNotificationHandler(profile).DisplayFailureMessage(url); DesktopNotificationHandler(profile).DisplayFailureMessage(shared_url);
} }
} }
......
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