Commit b6bc5bf8 authored by David Maunder's avatar David Maunder Committed by Commit Bot

Add methods for acquiring Task IDs in Sync (without SyncedTabDelegate depending on chrome/browser)

Bug: 961356
Change-Id: Ibc00f936ffe9978e8599e132dfdf7f1a1a70c2c7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1612662
Commit-Queue: David Maunder <davidjm@chromium.org>
Reviewed-by: default avatarMikel Astiz <mastiz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#660956}
parent 9375cae1
......@@ -5,6 +5,7 @@
#include "chrome/browser/ui/sync/tab_contents_synced_tab_delegate.h"
#include "base/memory/ref_counted.h"
#include "chrome/browser/complex_tasks/task_tab_helper.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/buildflags.h"
#include "components/sessions/content/content_serialized_navigation_builder.h"
......@@ -149,6 +150,16 @@ bool TabContentsSyncedTabDelegate::ShouldSync(
return false;
}
int64_t TabContentsSyncedTabDelegate::GetTaskIdForNavigationId(
int nav_id) const {
const tasks::TaskTabHelper* task_tab_helper = this->task_tab_helper();
if (task_tab_helper &&
task_tab_helper->get_context_record_task_id(nav_id) != nullptr) {
return task_tab_helper->get_context_record_task_id(nav_id)->task_id();
}
return -1;
}
const content::WebContents* TabContentsSyncedTabDelegate::web_contents() const {
return web_contents_;
}
......@@ -161,3 +172,10 @@ void TabContentsSyncedTabDelegate::SetWebContents(
content::WebContents* web_contents) {
web_contents_ = web_contents;
}
const tasks::TaskTabHelper* TabContentsSyncedTabDelegate::task_tab_helper()
const {
if (web_contents_ == nullptr)
return nullptr;
return tasks::TaskTabHelper::FromWebContents(web_contents_);
}
......@@ -17,6 +17,10 @@ namespace content {
class WebContents;
}
namespace tasks {
class TaskTabHelper;
}
// Partial implementation of SyncedTabDelegate for the cases where the tab has
// (either initially or late) a WebContents.
class TabContentsSyncedTabDelegate : public sync_sessions::SyncedTabDelegate {
......@@ -40,6 +44,7 @@ class TabContentsSyncedTabDelegate : public sync_sessions::SyncedTabDelegate {
const std::vector<std::unique_ptr<const sessions::SerializedNavigationEntry>>*
GetBlockedNavigations() const override;
bool ShouldSync(sync_sessions::SyncSessionsClient* sessions_client) override;
int64_t GetTaskIdForNavigationId(int nav_id) const override;
protected:
const content::WebContents* web_contents() const;
......@@ -47,6 +52,8 @@ class TabContentsSyncedTabDelegate : public sync_sessions::SyncedTabDelegate {
void SetWebContents(content::WebContents* web_contents);
private:
const tasks::TaskTabHelper* task_tab_helper() const;
content::WebContents* web_contents_;
DISALLOW_COPY_AND_ASSIGN(TabContentsSyncedTabDelegate);
......
......@@ -69,6 +69,11 @@ class SyncedTabDelegate {
// tab should be preserved.
virtual bool IsPlaceholderTab() const = 0;
// Task IDs represent navigations and relationships between navigations. -1
// indicates the Task ID is unknown. A Navigation ID is a Unique ID and
// is stored on a NavigationEntry and SerialiedNavigationEntry.
virtual int64_t GetTaskIdForNavigationId(int nav_id) const = 0;
protected:
SyncedTabDelegate();
};
......
......@@ -152,6 +152,12 @@ SessionID TestSyncedTabDelegate::GetSourceTabID() const {
return SessionID::InvalidValue();
}
int64_t TestSyncedTabDelegate::GetTaskIdForNavigationId(int nav_id) const {
// Task IDs are currently not used in the tests. -1 signals an unknown Task
// ID.
return -1;
}
PlaceholderTabDelegate::PlaceholderTabDelegate(SessionID tab_id)
: tab_id_(tab_id) {}
......@@ -236,6 +242,13 @@ SessionID PlaceholderTabDelegate::GetSourceTabID() const {
return SessionID::InvalidValue();
}
int64_t PlaceholderTabDelegate::GetTaskIdForNavigationId(int nav_id) const {
// Task IDs are currently not used in the tests. -1 signals an unknown Task
// ID.
NOTREACHED() << "Task IDs are not used for Placeholder Tabs";
return -1;
}
TestSyncedWindowDelegate::TestSyncedWindowDelegate(
SessionID window_id,
sync_pb::SessionWindow_BrowserType type)
......
......@@ -60,6 +60,7 @@ class TestSyncedTabDelegate : public SyncedTabDelegate {
bool IsPlaceholderTab() const override;
bool ShouldSync(SyncSessionsClient* sessions_client) override;
SessionID GetSourceTabID() const override;
int64_t GetTaskIdForNavigationId(int nav_id) const override;
private:
const SessionID window_id_;
......@@ -106,6 +107,7 @@ class PlaceholderTabDelegate : public SyncedTabDelegate {
GetBlockedNavigations() const override;
bool ShouldSync(SyncSessionsClient* sessions_client) override;
SessionID GetSourceTabID() const override;
int64_t GetTaskIdForNavigationId(int nav_id) const override;
private:
const SessionID tab_id_;
......
......@@ -41,6 +41,7 @@ class IOSChromeSyncedTabDelegate
GetBlockedNavigations() const override;
bool IsPlaceholderTab() const override;
bool ShouldSync(sync_sessions::SyncSessionsClient* sessions_client) override;
int64_t GetTaskIdForNavigationId(int nav_id) const override;
private:
explicit IOSChromeSyncedTabDelegate(web::WebState* web_state);
......
......@@ -135,4 +135,9 @@ bool IOSChromeSyncedTabDelegate::ShouldSync(
return false;
}
int64_t IOSChromeSyncedTabDelegate::GetTaskIdForNavigationId(int nav_id) const {
// TODO: (davidjm) Implement for iOS - bug 964356
return -1;
}
WEB_STATE_USER_DATA_KEY_IMPL(IOSChromeSyncedTabDelegate)
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