Commit 23584fba authored by David Maunder's avatar David Maunder Committed by Commit Bot

Integrate all platforms except iOS with new task tracking code.

Task IDs track navigations and relationships between navigations.

The new implementation allows cross-Tab navigations to be tracked
in addition to enabling better separation of concerns (moving Task ID
book keeping code out of sync).


Bug: 961356
Change-Id: I5ce0f970a35fc7f5f6f201452517c87be410eaca
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1625651
Commit-Queue: David Maunder <davidjm@chromium.org>
Reviewed-by: default avatarMikel Astiz <mastiz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#664395}
parent 3f627e4a
......@@ -160,6 +160,27 @@ int64_t TabContentsSyncedTabDelegate::GetTaskIdForNavigationId(
return -1;
}
int64_t TabContentsSyncedTabDelegate::GetParentTaskIdForNavigationId(
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)
->parent_task_id();
}
return -1;
}
int64_t TabContentsSyncedTabDelegate::GetRootTaskIdForNavigationId(
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)->root_task_id();
}
return -1;
}
const content::WebContents* TabContentsSyncedTabDelegate::web_contents() const {
return web_contents_;
}
......
......@@ -45,6 +45,8 @@ class TabContentsSyncedTabDelegate : public sync_sessions::SyncedTabDelegate {
GetBlockedNavigations() const override;
bool ShouldSync(sync_sessions::SyncSessionsClient* sessions_client) override;
int64_t GetTaskIdForNavigationId(int nav_id) const override;
int64_t GetParentTaskIdForNavigationId(int nav_id) const override;
int64_t GetRootTaskIdForNavigationId(int nav_id) const override;
protected:
const content::WebContents* web_contents() const;
......
......@@ -12,6 +12,7 @@
#include "base/bind.h"
#include "base/metrics/histogram_macros.h"
#include "base/strings/stringprintf.h"
#include "build/build_config.h"
#include "components/sync/model/sync_change.h"
#include "components/sync/protocol/sync.pb.h"
#include "components/sync_sessions/sync_sessions_client.h"
......@@ -290,7 +291,7 @@ void LocalSessionEventHandlerImpl::AssociateTab(
specifics->set_session_tag(current_session_tag_);
specifics->set_tab_node_id(tab_node_id);
GetTabSpecificsFromDelegate(*tab_delegate).Swap(specifics->mutable_tab());
WriteTasksIntoSpecifics(specifics->mutable_tab());
WriteTasksIntoSpecifics(specifics->mutable_tab(), tab_delegate);
// Update the tracker's session representation. Timestamp will be overwriten,
// so we set a null time first to prevent the update from being ignored, if
......@@ -330,17 +331,22 @@ void LocalSessionEventHandlerImpl::UpdateTaskTracker(
}
void LocalSessionEventHandlerImpl::WriteTasksIntoSpecifics(
sync_pb::SessionTab* tab_specifics) {
sync_pb::SessionTab* tab_specifics,
SyncedTabDelegate* tab_delegate) {
#if defined(OS_IOS)
TabTasks* tab_tasks = task_tracker_.GetTabTasks(
SessionID::FromSerializedValue(tab_specifics->tab_id()),
/*parent_tab_id=*/SessionID::InvalidValue());
#endif
for (int i = 0; i < tab_specifics->navigation_size(); i++) {
// Excluding blocked navigations, which are appended at tail.
if (tab_specifics->navigation(i).blocked_state() ==
sync_pb::TabNavigation::STATE_BLOCKED) {
break;
}
// TODO(davidjm) https://crbug.com/946356 - new task track implementation
// doesn't support iOS yet.
#if defined(OS_IOS)
std::vector<int64_t> task_ids = tab_tasks->GetTaskIdsForNavigation(
tab_specifics->navigation(i).unique_id());
if (task_ids.empty()) {
......@@ -355,6 +361,18 @@ void LocalSessionEventHandlerImpl::WriteTasksIntoSpecifics(
tab_specifics->mutable_navigation(i)->add_ancestor_task_id(
ancestor_task_id);
}
#else
int64_t task_id = tab_delegate->GetTaskIdForNavigationId(
tab_specifics->navigation(i).unique_id());
int64_t parent_task_id = tab_delegate->GetParentTaskIdForNavigationId(
tab_specifics->navigation(i).unique_id());
int64_t root_task_id = tab_delegate->GetRootTaskIdForNavigationId(
tab_specifics->navigation(i).unique_id());
tab_specifics->mutable_navigation(i)->set_task_id(task_id);
tab_specifics->mutable_navigation(i)->add_ancestor_task_id(parent_task_id);
tab_specifics->mutable_navigation(i)->add_ancestor_task_id(root_task_id);
#endif
}
}
......
......@@ -99,7 +99,8 @@ class LocalSessionEventHandlerImpl : public LocalSessionEventHandler {
void UpdateTaskTracker(SyncedTabDelegate* const tab_delegate);
// Update |tab_specifics| with the corresponding task ids.
void WriteTasksIntoSpecifics(sync_pb::SessionTab* tab_specifics);
void WriteTasksIntoSpecifics(sync_pb::SessionTab* tab_specifics,
SyncedTabDelegate* tab_delegate);
// Injected dependencies (not owned).
Delegate* const delegate_;
......
......@@ -73,6 +73,8 @@ class SyncedTabDelegate {
// 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;
virtual int64_t GetParentTaskIdForNavigationId(int nav_id) const = 0;
virtual int64_t GetRootTaskIdForNavigationId(int nav_id) const = 0;
protected:
SyncedTabDelegate();
......
......@@ -158,6 +158,19 @@ int64_t TestSyncedTabDelegate::GetTaskIdForNavigationId(int nav_id) const {
return -1;
}
int64_t TestSyncedTabDelegate::GetParentTaskIdForNavigationId(
int nav_id) const {
// Task IDs are currently not used in the tests. -1 signals an unknown Task
// ID.
return -1;
}
int64_t TestSyncedTabDelegate::GetRootTaskIdForNavigationId(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) {}
......@@ -249,6 +262,21 @@ int64_t PlaceholderTabDelegate::GetTaskIdForNavigationId(int nav_id) const {
return -1;
}
int64_t PlaceholderTabDelegate::GetParentTaskIdForNavigationId(
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;
}
int64_t PlaceholderTabDelegate::GetRootTaskIdForNavigationId(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)
......
......@@ -61,6 +61,8 @@ class TestSyncedTabDelegate : public SyncedTabDelegate {
bool ShouldSync(SyncSessionsClient* sessions_client) override;
SessionID GetSourceTabID() const override;
int64_t GetTaskIdForNavigationId(int nav_id) const override;
int64_t GetParentTaskIdForNavigationId(int nav_id) const override;
int64_t GetRootTaskIdForNavigationId(int nav_id) const override;
private:
const SessionID window_id_;
......@@ -108,6 +110,8 @@ class PlaceholderTabDelegate : public SyncedTabDelegate {
bool ShouldSync(SyncSessionsClient* sessions_client) override;
SessionID GetSourceTabID() const override;
int64_t GetTaskIdForNavigationId(int nav_id) const override;
int64_t GetParentTaskIdForNavigationId(int nav_id) const override;
int64_t GetRootTaskIdForNavigationId(int nav_id) const override;
private:
const SessionID tab_id_;
......
......@@ -42,6 +42,8 @@ class IOSChromeSyncedTabDelegate
bool IsPlaceholderTab() const override;
bool ShouldSync(sync_sessions::SyncSessionsClient* sessions_client) override;
int64_t GetTaskIdForNavigationId(int nav_id) const override;
int64_t GetParentTaskIdForNavigationId(int nav_id) const override;
int64_t GetRootTaskIdForNavigationId(int nav_id) const override;
private:
explicit IOSChromeSyncedTabDelegate(web::WebState* web_state);
......
......@@ -136,7 +136,22 @@ bool IOSChromeSyncedTabDelegate::ShouldSync(
}
int64_t IOSChromeSyncedTabDelegate::GetTaskIdForNavigationId(int nav_id) const {
// TODO: (davidjm) Implement for iOS - bug 964356
// TODO(davidjm) https://crbug.com/946356 - new task track implementation
// doesn't support iOS yet.
return -1;
}
int64_t IOSChromeSyncedTabDelegate::GetParentTaskIdForNavigationId(
int nav_id) const {
// TODO(davidjm) https://crbug.com/946356 - new task track implementation
// doesn't support iOS yet.
return -1;
}
int64_t IOSChromeSyncedTabDelegate::GetRootTaskIdForNavigationId(
int nav_id) const {
// TODO(davidjm) https://crbug.com/946356 - new task track implementation
// doesn't support iOS yet.
return -1;
}
......
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