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

Rename ContextRecordTaskId -> NavigationTaskId

Bug: 976390
Change-Id: I31c1e474f48c3e621172e69ed64d841f0e504106
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1665196
Commit-Queue: David Maunder <davidjm@chromium.org>
Reviewed-by: default avatarYusuf Ozuysal <yusufo@chromium.org>
Reviewed-by: default avatarMikel Astiz <mastiz@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#676934}
parent c9fa9322
...@@ -12,7 +12,7 @@ import org.chromium.chrome.browser.tab.TabAttributes; ...@@ -12,7 +12,7 @@ import org.chromium.chrome.browser.tab.TabAttributes;
import org.chromium.content_public.browser.WebContents; import org.chromium.content_public.browser.WebContents;
/** /**
* Used for maintaining Task ID (see ContextRecordTaskId) data about a Tab * Used for maintaining Task ID (see NavigationTaskId) data about a Tab
*/ */
@JNINamespace("tasks") @JNINamespace("tasks")
public class TaskTabHelper { public class TaskTabHelper {
......
...@@ -23,11 +23,11 @@ public @interface TabAttributeKeys { ...@@ -23,11 +23,11 @@ public @interface TabAttributeKeys {
/** Whether tab modal dialog is showing or not. */ /** Whether tab modal dialog is showing or not. */
String MODAL_DIALOG_SHOWING = "isTabModalDialogShowing"; String MODAL_DIALOG_SHOWING = "isTabModalDialogShowing";
/** Parent Tab Task Id. See ContextRecordTaskId (context_record_task_id.h) for definition */ /** Parent Tab Task Id. See NavigationTaskId (navigation_task_id.h) for definition */
String PARENT_TAB_TASK_ID = "ParentTaskId"; String PARENT_TAB_TASK_ID = "ParentTaskId";
/** /**
* Parent Tab Root Task Id. See ContextRecordTaskId (context_record_task_id.h) for definition * Parent Tab Root Task Id. See NavigationTaskId (navigation_task_id.h) for definition
*/ */
String PARENT_TAB_ROOT_TASK_ID = "ParentRootTaskId"; String PARENT_TAB_ROOT_TASK_ID = "ParentRootTaskId";
......
...@@ -92,7 +92,7 @@ void TaskTabHelper::NavigationListPruned( ...@@ -92,7 +92,7 @@ void TaskTabHelper::NavigationListPruned(
entry_index_to_spoke_count_map_[current_entry_index]); entry_index_to_spoke_count_map_[current_entry_index]);
} }
sessions::ContextRecordTaskId* TaskTabHelper::GetContextRecordTaskId( sessions::NavigationTaskId* TaskTabHelper::GetCurrentTaskId(
content::WebContents* web_contents) { content::WebContents* web_contents) {
if (!web_contents) if (!web_contents)
return nullptr; return nullptr;
...@@ -100,22 +100,22 @@ sessions::ContextRecordTaskId* TaskTabHelper::GetContextRecordTaskId( ...@@ -100,22 +100,22 @@ sessions::ContextRecordTaskId* TaskTabHelper::GetContextRecordTaskId(
web_contents->GetController().GetLastCommittedEntry(); web_contents->GetController().GetLastCommittedEntry();
if (!navigation_entry) if (!navigation_entry)
return nullptr; return nullptr;
sessions::ContextRecordTaskId* context_record_task_id = sessions::NavigationTaskId* navigation_task_id =
sessions::ContextRecordTaskId::Get(navigation_entry); sessions::NavigationTaskId::Get(navigation_entry);
if (!context_record_task_id) if (!navigation_task_id)
return nullptr; return nullptr;
return context_record_task_id; return navigation_task_id;
} }
void TaskTabHelper::UpdateAndRecordTaskIds( void TaskTabHelper::UpdateAndRecordTaskIds(
const content::LoadCommittedDetails& load_details) { const content::LoadCommittedDetails& load_details) {
sessions::ContextRecordTaskId* context_record_task_id = sessions::NavigationTaskId* navigation_task_id =
sessions::ContextRecordTaskId::Get(load_details.entry); sessions::NavigationTaskId::Get(load_details.entry);
// The Task ID is the Global ID of the first navigation. The first // The Task ID is the Global ID of the first navigation. The first
// navigation is detected if the Task ID hasn't been set yet. // navigation is detected if the Task ID hasn't been set yet.
if (context_record_task_id->task_id() == -1) { if (navigation_task_id->id() == -1) {
context_record_task_id->set_task_id( navigation_task_id->set_id(
load_details.entry->GetTimestamp().since_origin().InMicroseconds()); load_details.entry->GetTimestamp().since_origin().InMicroseconds());
} }
...@@ -126,29 +126,27 @@ void TaskTabHelper::UpdateAndRecordTaskIds( ...@@ -126,29 +126,27 @@ void TaskTabHelper::UpdateAndRecordTaskIds(
load_details.previous_entry_index); load_details.previous_entry_index);
if (prev_nav_entry != nullptr) { if (prev_nav_entry != nullptr) {
sessions::ContextRecordTaskId* prev_context_record_task_id = sessions::NavigationTaskId* prev_navigation_task_id =
sessions::ContextRecordTaskId::Get(prev_nav_entry); sessions::NavigationTaskId::Get(prev_nav_entry);
context_record_task_id->set_parent_task_id( navigation_task_id->set_parent_id(prev_navigation_task_id->id());
prev_context_record_task_id->task_id()); navigation_task_id->set_root_id(prev_navigation_task_id->root_id());
context_record_task_id->set_root_task_id(
prev_context_record_task_id->root_task_id());
} }
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
else { else {
// Cross-tab navigation - only supported in Android. In this case // Cross-tab navigation - only supported in Android. In this case
// the parent and parent root Task IDs are passed from the Java layer // the parent and parent root Task IDs are passed from the Java layer
if (this->GetParentTaskId() != -1) { if (this->GetParentTaskId() != -1) {
context_record_task_id->set_parent_task_id(this->GetParentTaskId()); navigation_task_id->set_parent_id(this->GetParentTaskId());
context_record_task_id->set_root_task_id(this->GetParentRootTaskId()); navigation_task_id->set_root_id(this->GetParentRootTaskId());
} }
} }
#endif // defined(OS_ANDROID) #endif // defined(OS_ANDROID)
} }
} else { } else {
context_record_task_id->set_root_task_id(context_record_task_id->task_id()); navigation_task_id->set_root_id(navigation_task_id->id());
} }
local_context_record_task_id_map_.emplace(load_details.entry->GetUniqueID(), local_navigation_task_id_map_.emplace(load_details.entry->GetUniqueID(),
*context_record_task_id); *navigation_task_id);
} }
void TaskTabHelper::RecordHubAndSpokeNavigationUsage(int spokes) { void TaskTabHelper::RecordHubAndSpokeNavigationUsage(int spokes) {
...@@ -192,11 +190,11 @@ int64_t TaskTabHelper::GetParentRootTaskId() { ...@@ -192,11 +190,11 @@ int64_t TaskTabHelper::GetParentRootTaskId() {
jlong JNI_TaskTabHelper_GetTaskId(JNIEnv* env, jlong JNI_TaskTabHelper_GetTaskId(JNIEnv* env,
const JavaParamRef<jobject>& jweb_contents) { const JavaParamRef<jobject>& jweb_contents) {
sessions::ContextRecordTaskId* context_record_task_id = sessions::NavigationTaskId* navigation_task_id =
TaskTabHelper::GetContextRecordTaskId( TaskTabHelper::GetCurrentTaskId(
content::WebContents::FromJavaWebContents(jweb_contents)); content::WebContents::FromJavaWebContents(jweb_contents));
if (context_record_task_id) { if (navigation_task_id) {
return context_record_task_id->task_id(); return navigation_task_id->id();
} }
return -1; return -1;
} }
...@@ -204,11 +202,11 @@ jlong JNI_TaskTabHelper_GetTaskId(JNIEnv* env, ...@@ -204,11 +202,11 @@ jlong JNI_TaskTabHelper_GetTaskId(JNIEnv* env,
jlong JNI_TaskTabHelper_GetRootTaskId( jlong JNI_TaskTabHelper_GetRootTaskId(
JNIEnv* env, JNIEnv* env,
const JavaParamRef<jobject>& jweb_contents) { const JavaParamRef<jobject>& jweb_contents) {
sessions::ContextRecordTaskId* context_record_task_id = sessions::NavigationTaskId* navigation_task_id =
TaskTabHelper::GetContextRecordTaskId( TaskTabHelper::GetCurrentTaskId(
content::WebContents::FromJavaWebContents(jweb_contents)); content::WebContents::FromJavaWebContents(jweb_contents));
if (context_record_task_id) { if (navigation_task_id) {
return context_record_task_id->root_task_id(); return navigation_task_id->root_id();
} }
return -1; return -1;
} }
......
...@@ -10,13 +10,13 @@ ...@@ -10,13 +10,13 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "components/sessions/content/content_record_task_id.h" #include "components/sessions/content/navigation_task_id.h"
#include "content/public/browser/navigation_details.h" #include "content/public/browser/navigation_details.h"
#include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_observer.h"
#include "content/public/browser/web_contents_user_data.h" #include "content/public/browser/web_contents_user_data.h"
namespace sessions { namespace sessions {
class ContextRecordTaskId; class NavigationTaskId;
} }
namespace tasks { namespace tasks {
...@@ -33,13 +33,13 @@ class TaskTabHelper : public content::WebContentsObserver, ...@@ -33,13 +33,13 @@ class TaskTabHelper : public content::WebContentsObserver,
const content::LoadCommittedDetails& load_details) override; const content::LoadCommittedDetails& load_details) override;
void NavigationListPruned( void NavigationListPruned(
const content::PrunedDetails& pruned_details) override; const content::PrunedDetails& pruned_details) override;
static sessions::ContextRecordTaskId* GetContextRecordTaskId( static sessions::NavigationTaskId* GetCurrentTaskId(
content::WebContents* web_contents); content::WebContents* web_contents);
const sessions::ContextRecordTaskId* get_context_record_task_id( const sessions::NavigationTaskId* get_task_id_for_navigation(
int nav_id) const { int nav_id) const {
if (!base::Contains(local_context_record_task_id_map_, nav_id)) if (!base::Contains(local_navigation_task_id_map_, nav_id))
return nullptr; return nullptr;
return &local_context_record_task_id_map_.find(nav_id)->second; return &local_navigation_task_id_map_.find(nav_id)->second;
} }
protected: protected:
...@@ -68,8 +68,8 @@ class TaskTabHelper : public content::WebContentsObserver, ...@@ -68,8 +68,8 @@ class TaskTabHelper : public content::WebContentsObserver,
int last_pruned_navigation_entry_index_; int last_pruned_navigation_entry_index_;
std::map<int, int> entry_index_to_spoke_count_map_; std::map<int, int> entry_index_to_spoke_count_map_;
std::unordered_map<int, sessions::ContextRecordTaskId> std::unordered_map<int, sessions::NavigationTaskId>
local_context_record_task_id_map_; local_navigation_task_id_map_;
WEB_CONTENTS_USER_DATA_KEY_DECL(); WEB_CONTENTS_USER_DATA_KEY_DECL();
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include "base/test/metrics/histogram_tester.h" #include "base/test/metrics/histogram_tester.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h" #include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "components/sessions/content/content_record_task_id.h" #include "components/sessions/content/navigation_task_id.h"
#include "content/public/test/navigation_simulator.h" #include "content/public/test/navigation_simulator.h"
#include "content/public/test/web_contents_tester.h" #include "content/public/test/web_contents_tester.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
...@@ -183,7 +183,7 @@ TEST_F(TaskTabHelperUnitTest, ComplexRecordHubAndSpokeUsage) { ...@@ -183,7 +183,7 @@ TEST_F(TaskTabHelperUnitTest, ComplexRecordHubAndSpokeUsage) {
testing::ElementsAre(base::Bucket(2, 1))); testing::ElementsAre(base::Bucket(2, 1)));
} }
TEST_F(TaskTabHelperUnitTest, TestGetContextRecordTaskId) { TEST_F(TaskTabHelperUnitTest, TestGetCurrentTaskId) {
std::unique_ptr<content::WebContents> test_parent_web_contents( std::unique_ptr<content::WebContents> test_parent_web_contents(
content::WebContentsTester::CreateTestWebContents( content::WebContentsTester::CreateTestWebContents(
web_contents()->GetBrowserContext(), nullptr)); web_contents()->GetBrowserContext(), nullptr));
...@@ -193,77 +193,72 @@ TEST_F(TaskTabHelperUnitTest, TestGetContextRecordTaskId) { ...@@ -193,77 +193,72 @@ TEST_F(TaskTabHelperUnitTest, TestGetContextRecordTaskId) {
content::NavigationEntry* navigation_entry = content::NavigationEntry* navigation_entry =
test_parent_web_contents->GetController().GetLastCommittedEntry(); test_parent_web_contents->GetController().GetLastCommittedEntry();
sessions::ContextRecordTaskId* context_record_task_id = sessions::NavigationTaskId* navigation_task_id =
sessions::ContextRecordTaskId::Get(navigation_entry); sessions::NavigationTaskId::Get(navigation_entry);
context_record_task_id->set_task_id(3); navigation_task_id->set_id(3);
context_record_task_id->set_root_task_id(4); navigation_task_id->set_root_id(4);
EXPECT_EQ(tasks::TaskTabHelper::GetContextRecordTaskId( EXPECT_EQ(
test_parent_web_contents.get()) tasks::TaskTabHelper::GetCurrentTaskId(test_parent_web_contents.get())
->task_id(), ->id(),
3); 3);
EXPECT_EQ(tasks::TaskTabHelper::GetContextRecordTaskId( EXPECT_EQ(
test_parent_web_contents.get()) tasks::TaskTabHelper::GetCurrentTaskId(test_parent_web_contents.get())
->root_task_id(), ->root_id(),
4); 4);
} }
TEST_F(TaskTabHelperUnitTest, TestTaskIdExistingChain) { TEST_F(TaskTabHelperUnitTest, TestTaskIdExistingChain) {
NavigateAndCommit(GURL("http://a.com")); NavigateAndCommit(GURL("http://a.com"));
sessions::ContextRecordTaskId a_context_record_task_id = sessions::NavigationTaskId a_navigation_task_id =
*sessions::ContextRecordTaskId::Get(GetLastCommittedEntry()); *sessions::NavigationTaskId::Get(GetLastCommittedEntry());
NavigateAndCommit(GURL("http://b.com")); NavigateAndCommit(GURL("http://b.com"));
sessions::ContextRecordTaskId b_context_record_task_id = sessions::NavigationTaskId b_navigation_task_id =
*sessions::ContextRecordTaskId::Get(GetLastCommittedEntry()); *sessions::NavigationTaskId::Get(GetLastCommittedEntry());
EXPECT_EQ(b_context_record_task_id.parent_task_id(), EXPECT_EQ(b_navigation_task_id.parent_id(), a_navigation_task_id.id());
a_context_record_task_id.task_id()); EXPECT_EQ(a_navigation_task_id.root_id(), b_navigation_task_id.root_id());
EXPECT_EQ(a_context_record_task_id.root_task_id(),
b_context_record_task_id.root_task_id());
} }
TEST_F(TaskTabHelperUnitTest, TestTaskIdNewChain) { TEST_F(TaskTabHelperUnitTest, TestTaskIdNewChain) {
NavigateAndCommit(GURL("http://a.com")); NavigateAndCommit(GURL("http://a.com"));
sessions::ContextRecordTaskId a_context_record_task_id = sessions::NavigationTaskId a_navigation_task_id =
*sessions::ContextRecordTaskId::Get(GetLastCommittedEntry()); *sessions::NavigationTaskId::Get(GetLastCommittedEntry());
NavigateAndCommit(GURL("http://b.com"), ui::PAGE_TRANSITION_TYPED); NavigateAndCommit(GURL("http://b.com"), ui::PAGE_TRANSITION_TYPED);
sessions::ContextRecordTaskId b_context_record_task_id = sessions::NavigationTaskId b_navigation_task_id =
*sessions::ContextRecordTaskId::Get(GetLastCommittedEntry()); *sessions::NavigationTaskId::Get(GetLastCommittedEntry());
EXPECT_EQ(b_context_record_task_id.parent_task_id(), -1); EXPECT_EQ(b_navigation_task_id.parent_id(), -1);
EXPECT_NE(a_context_record_task_id.root_task_id(), EXPECT_NE(a_navigation_task_id.root_id(), b_navigation_task_id.root_id());
b_context_record_task_id.root_task_id());
} }
TEST_F(TaskTabHelperUnitTest, TestTaskIdBackButton) { TEST_F(TaskTabHelperUnitTest, TestTaskIdBackButton) {
NavigateAndCommit(GURL("http://a.com"), ui::PAGE_TRANSITION_TYPED); NavigateAndCommit(GURL("http://a.com"), ui::PAGE_TRANSITION_TYPED);
NavigateAndCommit(GURL("http://b.com")); NavigateAndCommit(GURL("http://b.com"));
sessions::ContextRecordTaskId b_context_record_task_id = sessions::NavigationTaskId b_navigation_task_id =
*sessions::ContextRecordTaskId::Get(GetLastCommittedEntry()); *sessions::NavigationTaskId::Get(GetLastCommittedEntry());
GoBack(); GoBack();
sessions::ContextRecordTaskId a_context_record_task_id = sessions::NavigationTaskId a_navigation_task_id =
*sessions::ContextRecordTaskId::Get(GetLastCommittedEntry()); *sessions::NavigationTaskId::Get(GetLastCommittedEntry());
// A should still have no parent after a back navigation and // A should still have no parent after a back navigation and
// shouldn't link to B (like it would if we navigated a.com -> b.com -> a.com // shouldn't link to B (like it would if we navigated a.com -> b.com -> a.com
// via clicking links) // via clicking links)
EXPECT_EQ(a_context_record_task_id.parent_task_id(), -1); EXPECT_EQ(a_navigation_task_id.parent_id(), -1);
EXPECT_NE(a_context_record_task_id.parent_task_id(), EXPECT_NE(a_navigation_task_id.parent_id(), b_navigation_task_id.id());
b_context_record_task_id.task_id());
} }
TEST_F(TaskTabHelperUnitTest, TestTaskIdBackViaLink) { TEST_F(TaskTabHelperUnitTest, TestTaskIdBackViaLink) {
NavigateAndCommit(GURL("http://a.com"), ui::PAGE_TRANSITION_TYPED); NavigateAndCommit(GURL("http://a.com"), ui::PAGE_TRANSITION_TYPED);
NavigateAndCommit(GURL("http://b.com")); NavigateAndCommit(GURL("http://b.com"));
sessions::ContextRecordTaskId b_context_record_task_id = sessions::NavigationTaskId b_navigation_task_id =
*sessions::ContextRecordTaskId::Get(GetLastCommittedEntry()); *sessions::NavigationTaskId::Get(GetLastCommittedEntry());
NavigateAndCommit(GURL("http://a.com")); NavigateAndCommit(GURL("http://a.com"));
sessions::ContextRecordTaskId a_context_record_task_id = sessions::NavigationTaskId a_navigation_task_id =
*sessions::ContextRecordTaskId::Get(GetLastCommittedEntry()); *sessions::NavigationTaskId::Get(GetLastCommittedEntry());
// We got back to a.com via a link (not back button) so it should now point to // We got back to a.com via a link (not back button) so it should now point to
// B. // B.
EXPECT_NE(a_context_record_task_id.parent_task_id(), -1); EXPECT_NE(a_navigation_task_id.parent_id(), -1);
EXPECT_EQ(a_context_record_task_id.parent_task_id(), EXPECT_EQ(a_navigation_task_id.parent_id(), b_navigation_task_id.id());
b_context_record_task_id.task_id());
} }
...@@ -167,8 +167,8 @@ int64_t TabContentsSyncedTabDelegate::GetTaskIdForNavigationId( ...@@ -167,8 +167,8 @@ int64_t TabContentsSyncedTabDelegate::GetTaskIdForNavigationId(
int nav_id) const { int nav_id) const {
const tasks::TaskTabHelper* task_tab_helper = this->task_tab_helper(); const tasks::TaskTabHelper* task_tab_helper = this->task_tab_helper();
if (task_tab_helper && if (task_tab_helper &&
task_tab_helper->get_context_record_task_id(nav_id) != nullptr) { task_tab_helper->get_task_id_for_navigation(nav_id) != nullptr) {
return task_tab_helper->get_context_record_task_id(nav_id)->task_id(); return task_tab_helper->get_task_id_for_navigation(nav_id)->id();
} }
return -1; return -1;
} }
...@@ -177,9 +177,8 @@ int64_t TabContentsSyncedTabDelegate::GetParentTaskIdForNavigationId( ...@@ -177,9 +177,8 @@ int64_t TabContentsSyncedTabDelegate::GetParentTaskIdForNavigationId(
int nav_id) const { int nav_id) const {
const tasks::TaskTabHelper* task_tab_helper = this->task_tab_helper(); const tasks::TaskTabHelper* task_tab_helper = this->task_tab_helper();
if (task_tab_helper && if (task_tab_helper &&
task_tab_helper->get_context_record_task_id(nav_id) != nullptr) { task_tab_helper->get_task_id_for_navigation(nav_id) != nullptr) {
return task_tab_helper->get_context_record_task_id(nav_id) return task_tab_helper->get_task_id_for_navigation(nav_id)->parent_id();
->parent_task_id();
} }
return -1; return -1;
} }
...@@ -188,8 +187,8 @@ int64_t TabContentsSyncedTabDelegate::GetRootTaskIdForNavigationId( ...@@ -188,8 +187,8 @@ int64_t TabContentsSyncedTabDelegate::GetRootTaskIdForNavigationId(
int nav_id) const { int nav_id) const {
const tasks::TaskTabHelper* task_tab_helper = this->task_tab_helper(); const tasks::TaskTabHelper* task_tab_helper = this->task_tab_helper();
if (task_tab_helper && if (task_tab_helper &&
task_tab_helper->get_context_record_task_id(nav_id) != nullptr) { task_tab_helper->get_task_id_for_navigation(nav_id) != nullptr) {
return task_tab_helper->get_context_record_task_id(nav_id)->root_task_id(); return task_tab_helper->get_task_id_for_navigation(nav_id)->root_id();
} }
return -1; return -1;
} }
......
...@@ -19,13 +19,13 @@ if (!is_ios) { ...@@ -19,13 +19,13 @@ if (!is_ios) {
"content/content_platform_specific_tab_data.h", "content/content_platform_specific_tab_data.h",
"content/content_record_password_state.cc", "content/content_record_password_state.cc",
"content/content_record_password_state.h", "content/content_record_password_state.h",
"content/content_record_task_id.cc",
"content/content_record_task_id.h",
"content/content_serialized_navigation_builder.cc", "content/content_serialized_navigation_builder.cc",
"content/content_serialized_navigation_builder.h", "content/content_serialized_navigation_builder.h",
"content/content_serialized_navigation_driver.cc", "content/content_serialized_navigation_driver.cc",
"content/content_serialized_navigation_driver.h", "content/content_serialized_navigation_driver.h",
"content/extended_info_handler.h", "content/extended_info_handler.h",
"content/navigation_task_id.cc",
"content/navigation_task_id.h",
] ]
configs += [ ":implementation" ] configs += [ ":implementation" ]
...@@ -167,9 +167,9 @@ source_set("unit_tests") { ...@@ -167,9 +167,9 @@ source_set("unit_tests") {
if (!is_ios) { if (!is_ios) {
sources += [ sources += [
"content/content_record_task_id_unittest.cc",
"content/content_serialized_navigation_builder_unittest.cc", "content/content_serialized_navigation_builder_unittest.cc",
"content/content_serialized_navigation_driver_unittest.cc", "content/content_serialized_navigation_driver_unittest.cc",
"content/navigation_task_id_unittest.cc",
] ]
} }
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/sessions/content/content_record_task_id.h"
#include "content/public/browser/navigation_entry.h"
namespace sessions {
const char kTaskIdKey[] = "task_id_data";
ContextRecordTaskId::ContextRecordTaskId() {}
ContextRecordTaskId::ContextRecordTaskId(
const ContextRecordTaskId& context_record_task_id) = default;
ContextRecordTaskId::~ContextRecordTaskId() {}
ContextRecordTaskId* ContextRecordTaskId::Get(content::NavigationEntry* entry) {
ContextRecordTaskId* context_record_task_id =
static_cast<ContextRecordTaskId*>(entry->GetUserData(kTaskIdKey));
if (context_record_task_id)
return context_record_task_id;
auto context_record_task_id_ptr = base::WrapUnique(new ContextRecordTaskId());
context_record_task_id = context_record_task_id_ptr.get();
entry->SetUserData(kTaskIdKey, std::move(context_record_task_id_ptr));
return context_record_task_id;
}
std::unique_ptr<base::SupportsUserData::Data> ContextRecordTaskId::Clone() {
return base::WrapUnique(new ContextRecordTaskId(*this));
}
} // namespace sessions
...@@ -6,9 +6,9 @@ ...@@ -6,9 +6,9 @@
#include "base/logging.h" #include "base/logging.h"
#include "components/sessions/content/content_record_password_state.h" #include "components/sessions/content/content_record_password_state.h"
#include "components/sessions/content/content_record_task_id.h"
#include "components/sessions/content/content_serialized_navigation_driver.h" #include "components/sessions/content/content_serialized_navigation_driver.h"
#include "components/sessions/content/extended_info_handler.h" #include "components/sessions/content/extended_info_handler.h"
#include "components/sessions/content/navigation_task_id.h"
#include "components/sessions/core/serialized_navigation_entry.h" #include "components/sessions/core/serialized_navigation_entry.h"
#include "content/public/browser/browser_context.h" #include "content/public/browser/browser_context.h"
#include "content/public/browser/favicon_status.h" #include "content/public/browser/favicon_status.h"
...@@ -65,12 +65,10 @@ ContentSerializedNavigationBuilder::FromNavigationEntry( ...@@ -65,12 +65,10 @@ ContentSerializedNavigationBuilder::FromNavigationEntry(
navigation.replaced_entry_data_ = navigation.replaced_entry_data_ =
ConvertReplacedEntryData(entry->GetReplacedEntryData()); ConvertReplacedEntryData(entry->GetReplacedEntryData());
navigation.password_state_ = GetPasswordStateFromNavigation(entry); navigation.password_state_ = GetPasswordStateFromNavigation(entry);
navigation.task_id_ = ContextRecordTaskId::Get(entry)->task_id(); navigation.task_id_ = NavigationTaskId::Get(entry)->id();
navigation.parent_task_id_ = navigation.parent_task_id_ = NavigationTaskId::Get(entry)->parent_id();
ContextRecordTaskId::Get(entry)->parent_task_id(); navigation.root_task_id_ = NavigationTaskId::Get(entry)->root_id();
navigation.root_task_id_ = ContextRecordTaskId::Get(entry)->root_task_id(); navigation.children_task_ids_ = NavigationTaskId::Get(entry)->children_ids();
navigation.children_task_ids_ =
ContextRecordTaskId::Get(entry)->children_task_ids();
for (const auto& handler_entry : for (const auto& handler_entry :
ContentSerializedNavigationDriver::GetInstance() ContentSerializedNavigationDriver::GetInstance()
......
...@@ -7,9 +7,9 @@ ...@@ -7,9 +7,9 @@
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "components/sessions/content/content_record_password_state.h" #include "components/sessions/content/content_record_password_state.h"
#include "components/sessions/content/content_record_task_id.h"
#include "components/sessions/content/content_serialized_navigation_driver.h" #include "components/sessions/content/content_serialized_navigation_driver.h"
#include "components/sessions/content/extended_info_handler.h" #include "components/sessions/content/extended_info_handler.h"
#include "components/sessions/content/navigation_task_id.h"
#include "components/sessions/core/serialized_navigation_entry.h" #include "components/sessions/core/serialized_navigation_entry.h"
#include "components/sessions/core/serialized_navigation_entry_test_helper.h" #include "components/sessions/core/serialized_navigation_entry_test_helper.h"
#include "content/public/browser/favicon_status.h" #include "content/public/browser/favicon_status.h"
...@@ -84,14 +84,13 @@ std::unique_ptr<content::NavigationEntry> MakeNavigationEntryForTest() { ...@@ -84,14 +84,13 @@ std::unique_ptr<content::NavigationEntry> MakeNavigationEntryForTest() {
redirect_chain.push_back(test_data::kRedirectURL1); redirect_chain.push_back(test_data::kRedirectURL1);
redirect_chain.push_back(test_data::kVirtualURL); redirect_chain.push_back(test_data::kVirtualURL);
navigation_entry->SetRedirectChain(redirect_chain); navigation_entry->SetRedirectChain(redirect_chain);
ContextRecordTaskId::Get(navigation_entry.get()) NavigationTaskId::Get(navigation_entry.get())->set_id(test_data::kTaskId);
->set_task_id(test_data::kTaskId); NavigationTaskId::Get(navigation_entry.get())
ContextRecordTaskId::Get(navigation_entry.get()) ->set_parent_id(test_data::kParentTaskId);
->set_parent_task_id(test_data::kParentTaskId); NavigationTaskId::Get(navigation_entry.get())
ContextRecordTaskId::Get(navigation_entry.get()) ->set_root_id(test_data::kRootTaskId);
->set_root_task_id(test_data::kRootTaskId); NavigationTaskId::Get(navigation_entry.get())
ContextRecordTaskId::Get(navigation_entry.get()) ->set_children_ids(test_data::kChildrenTaskIds);
->set_children_task_ids(test_data::kChildrenTaskIds);
return navigation_entry; return navigation_entry;
} }
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/sessions/content/navigation_task_id.h"
#include "content/public/browser/navigation_entry.h"
namespace sessions {
const char kTaskIdKey[] = "task_id_data";
NavigationTaskId::NavigationTaskId() {}
NavigationTaskId::NavigationTaskId(const NavigationTaskId& navigation_task_id) =
default;
NavigationTaskId::~NavigationTaskId() {}
NavigationTaskId* NavigationTaskId::Get(content::NavigationEntry* entry) {
NavigationTaskId* navigation_task_id =
static_cast<NavigationTaskId*>(entry->GetUserData(kTaskIdKey));
if (navigation_task_id)
return navigation_task_id;
auto navigation_task_id_ptr = base::WrapUnique(new NavigationTaskId());
navigation_task_id = navigation_task_id_ptr.get();
entry->SetUserData(kTaskIdKey, std::move(navigation_task_id_ptr));
return navigation_task_id;
}
std::unique_ptr<base::SupportsUserData::Data> NavigationTaskId::Clone() {
return base::WrapUnique(new NavigationTaskId(*this));
}
} // namespace sessions
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef COMPONENTS_SESSIONS_CONTENT_CONTENT_RECORD_TASK_ID_H_ #ifndef COMPONENTS_SESSIONS_CONTENT_NAVIGATION_TASK_ID_H_
#define COMPONENTS_SESSIONS_CONTENT_CONTENT_RECORD_TASK_ID_H_ #define COMPONENTS_SESSIONS_CONTENT_NAVIGATION_TASK_ID_H_
#include <stdint.h> #include <stdint.h>
...@@ -20,35 +20,30 @@ namespace sessions { ...@@ -20,35 +20,30 @@ namespace sessions {
// Stores Task ID data in a NavigationEntry. Task IDs track navigations and // Stores Task ID data in a NavigationEntry. Task IDs track navigations and
// relationships between navigations // relationships between navigations
class SESSIONS_EXPORT ContextRecordTaskId class SESSIONS_EXPORT NavigationTaskId : public base::SupportsUserData::Data {
: public base::SupportsUserData::Data {
public: public:
ContextRecordTaskId(); NavigationTaskId();
ContextRecordTaskId(const ContextRecordTaskId& context_record_task_id); NavigationTaskId(const NavigationTaskId& navigation_task_id);
~ContextRecordTaskId() override; ~NavigationTaskId() override;
static ContextRecordTaskId* Get(content::NavigationEntry* entry); static NavigationTaskId* Get(content::NavigationEntry* entry);
int64_t task_id() const { return task_id_; } int64_t id() const { return id_; }
int64_t parent_task_id() const { return parent_task_id_; } int64_t parent_id() const { return parent_id_; }
int64_t root_task_id() const { return root_task_id_; } int64_t root_id() const { return root_id_; }
const std::vector<int64_t>& children_task_ids() const { const std::vector<int64_t>& children_ids() const { return children_ids_; }
return children_task_ids_;
}
void set_task_id(int64_t task_id) { task_id_ = task_id; } void set_id(int64_t id) { id_ = id; }
void set_parent_task_id(int64_t parent_task_id) { void set_parent_id(int64_t parent_id) { parent_id_ = parent_id; }
parent_task_id_ = parent_task_id;
}
void set_root_task_id(int64_t root_task_id) { root_task_id_ = root_task_id; } void set_root_id(int64_t root_id) { root_id_ = root_id; }
void set_children_task_ids(const std::vector<int64_t>& children_task_ids) { void set_children_ids(const std::vector<int64_t>& children_ids) {
children_task_ids_ = children_task_ids; children_ids_ = children_ids;
} }
// base::SupportsUserData::Data: // base::SupportsUserData::Data:
...@@ -72,12 +67,12 @@ class SESSIONS_EXPORT ContextRecordTaskId ...@@ -72,12 +67,12 @@ class SESSIONS_EXPORT ContextRecordTaskId
// Task IDs are tracked for task clustering in the event that an intermediate // Task IDs are tracked for task clustering in the event that an intermediate
// Tab is closed. It is not possible to group the tasks via a tree traversal // Tab is closed. It is not possible to group the tasks via a tree traversal
// in this situation. // in this situation.
int64_t task_id_ = -1; int64_t id_ = -1;
int64_t parent_task_id_ = -1; int64_t parent_id_ = -1;
int64_t root_task_id_ = -1; int64_t root_id_ = -1;
std::vector<int64_t> children_task_ids_; std::vector<int64_t> children_ids_;
}; };
} // namespace sessions } // namespace sessions
#endif // COMPONENTS_SESSIONS_CONTENT_CONTENT_RECORD_TASK_ID_H_ #endif // COMPONENTS_SESSIONS_CONTENT_NAVIGATION_TASK_ID_H_
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "components/sessions/content/content_record_task_id.h" #include "components/sessions/content/navigation_task_id.h"
#include "components/sessions/core/serialized_navigation_entry_test_helper.h" #include "components/sessions/core/serialized_navigation_entry_test_helper.h"
#include "content/public/browser/navigation_entry.h" #include "content/public/browser/navigation_entry.h"
...@@ -10,10 +10,10 @@ ...@@ -10,10 +10,10 @@
namespace sessions { namespace sessions {
class ContentRecordTaskIDTest : public testing::Test { class NavigationTaskIDTest : public testing::Test {
public: public:
ContentRecordTaskIDTest() {} NavigationTaskIDTest() {}
~ContentRecordTaskIDTest() override {} ~NavigationTaskIDTest() override {}
void SetUp() override { void SetUp() override {
navigation_entry_ = content::NavigationEntry::Create(); navigation_entry_ = content::NavigationEntry::Create();
...@@ -23,37 +23,33 @@ class ContentRecordTaskIDTest : public testing::Test { ...@@ -23,37 +23,33 @@ class ContentRecordTaskIDTest : public testing::Test {
std::unique_ptr<content::NavigationEntry> navigation_entry_; std::unique_ptr<content::NavigationEntry> navigation_entry_;
private: private:
DISALLOW_COPY_AND_ASSIGN(ContentRecordTaskIDTest); DISALLOW_COPY_AND_ASSIGN(NavigationTaskIDTest);
}; };
TEST_F(ContentRecordTaskIDTest, TaskIDTest) { TEST_F(NavigationTaskIDTest, TaskIDTest) {
ContextRecordTaskId* context_record_task_id = NavigationTaskId* navigation_task_id =
ContextRecordTaskId::Get(navigation_entry_.get()); NavigationTaskId::Get(navigation_entry_.get());
context_record_task_id->set_task_id(test_data::kTaskId); navigation_task_id->set_id(test_data::kTaskId);
context_record_task_id->set_parent_task_id(test_data::kParentTaskId); navigation_task_id->set_parent_id(test_data::kParentTaskId);
context_record_task_id->set_root_task_id(test_data::kRootTaskId); navigation_task_id->set_root_id(test_data::kRootTaskId);
context_record_task_id->set_children_task_ids(test_data::kChildrenTaskIds); navigation_task_id->set_children_ids(test_data::kChildrenTaskIds);
EXPECT_EQ(test_data::kTaskId, EXPECT_EQ(test_data::kTaskId,
ContextRecordTaskId::Get(navigation_entry_.get())->task_id()); NavigationTaskId::Get(navigation_entry_.get())->id());
EXPECT_EQ( EXPECT_EQ(test_data::kParentTaskId,
test_data::kParentTaskId, NavigationTaskId::Get(navigation_entry_.get())->parent_id());
ContextRecordTaskId::Get(navigation_entry_.get())->parent_task_id());
EXPECT_EQ(test_data::kRootTaskId, EXPECT_EQ(test_data::kRootTaskId,
ContextRecordTaskId::Get(navigation_entry_.get())->root_task_id()); NavigationTaskId::Get(navigation_entry_.get())->root_id());
EXPECT_EQ( EXPECT_EQ(test_data::kChildrenTaskIds,
test_data::kChildrenTaskIds, NavigationTaskId::Get(navigation_entry_.get())->children_ids());
ContextRecordTaskId::Get(navigation_entry_.get())->children_task_ids());
ContextRecordTaskId cloned_context_record_task_id(*context_record_task_id); NavigationTaskId cloned_navigation_task_id(*navigation_task_id);
EXPECT_EQ(test_data::kTaskId, cloned_context_record_task_id.task_id()); EXPECT_EQ(test_data::kTaskId, cloned_navigation_task_id.id());
EXPECT_EQ(test_data::kParentTaskId, EXPECT_EQ(test_data::kParentTaskId, cloned_navigation_task_id.parent_id());
cloned_context_record_task_id.parent_task_id()); EXPECT_EQ(test_data::kRootTaskId, cloned_navigation_task_id.root_id());
EXPECT_EQ(test_data::kRootTaskId,
cloned_context_record_task_id.root_task_id());
EXPECT_EQ(test_data::kChildrenTaskIds, EXPECT_EQ(test_data::kChildrenTaskIds,
cloned_context_record_task_id.children_task_ids()); cloned_navigation_task_id.children_ids());
} }
} // namespace sessions } // namespace sessions
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