Commit 4d93009e authored by Scott Violet's avatar Scott Violet Committed by Commit Bot

android: disable sync when hiding navigations

This is a follow on to:
https://chromium-review.googlesource.com/c/chromium/src/+/2505698/

Without this patch, when signed in with history sync enabled,
chrome://history would still show visits from CCT. This patch makes it
so such visits are no longer pushed to sync and won't be
visible in chrome://history.

This is for an experiment, and only enabled for 1 parties if the right
intent extra is provided.

This code is temporary, and will be reverted once data from
experiment has been collected.

BUG=1145208
TEST=TabAndroidBrowserTest.SetHideFutureNavigationsPropagatesToSyncedTabDelegate

Change-Id: I9008ea6c581c7e90737128e4643fd066105cc6dd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2518403Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Reviewed-by: default avatarMikel Astiz <mastiz@chromium.org>
Commit-Queue: Scott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#823775}
parent 2e895d25
......@@ -118,6 +118,8 @@ class TabAndroid : public base::SupportsUserData {
return should_add_api2_transition_to_future_navigations_;
}
bool hide_future_navigations() const { return hide_future_navigations_; }
// Observers -----------------------------------------------------------------
// Adds/Removes an Observer.
......
// Copyright 2020 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 "chrome/browser/android/tab_android.h"
#include "chrome/browser/sync/session_sync_service_factory.h"
#include "chrome/test/base/android/android_browser_test.h"
#include "chrome/test/base/chrome_test_utils.h"
#include "components/sync_sessions/session_sync_service_impl.h"
#include "components/sync_sessions/sync_sessions_client.h"
#include "components/sync_sessions/synced_tab_delegate.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "testing/gmock/include/gmock/gmock.h"
class TabAndroidBrowserTest : public AndroidBrowserTest {
public:
// AndroidBrowserTest:
void SetUpOnMainThread() override {
embedded_test_server()->ServeFilesFromSourceDirectory("content/test/data");
ASSERT_TRUE(embedded_test_server()->Start());
}
};
IN_PROC_BROWSER_TEST_F(TabAndroidBrowserTest,
SetHideFutureNavigationsPropagatesToSyncedTabDelegate) {
auto* tab = TabAndroid::FromWebContents(
chrome_test_utils::GetActiveWebContents(this));
ASSERT_TRUE(tab);
// ShouldSync() returns false with about:blank. Load something to prevent
// that.
const GURL url =
embedded_test_server()->GetURL("localhost", "/simple_page.html");
ASSERT_TRUE(content::NavigateToURL(tab->web_contents(), url));
auto* sync_service = static_cast<sync_sessions::SessionSyncServiceImpl*>(
SessionSyncServiceFactory::GetForProfile(tab->GetProfile()));
ASSERT_TRUE(sync_service);
sync_sessions::SyncSessionsClient* sessions_client =
sync_service->GetSessionsClientForTest();
ASSERT_TRUE(sessions_client);
sync_sessions::SyncedTabDelegate* synced_tab_delegate =
tab->GetSyncedTabDelegate();
ASSERT_TRUE(synced_tab_delegate);
// Default is sync is enabled.
EXPECT_TRUE(synced_tab_delegate->ShouldSync(sessions_client));
// When navigations are hidden, sync should be disabled.
tab->SetHideFutureNavigations(/* env */ nullptr, /* hide */ true);
EXPECT_FALSE(synced_tab_delegate->ShouldSync(sessions_client));
// Disable hiding navigations, and sync should be enabled.
tab->SetHideFutureNavigations(/* env */ nullptr, /* hide */ false);
EXPECT_TRUE(synced_tab_delegate->ShouldSync(sessions_client));
}
......@@ -49,6 +49,12 @@ bool SyncedTabDelegateAndroid::IsPlaceholderTab() const {
return web_contents() == nullptr;
}
bool SyncedTabDelegateAndroid::ShouldSync(
sync_sessions::SyncSessionsClient* sessions_client) {
return TabContentsSyncedTabDelegate::ShouldSync(sessions_client) &&
!tab_android_->hide_future_navigations();
}
void SyncedTabDelegateAndroid::SetWebContents(
content::WebContents* web_contents,
int source_tab_android_id) {
......
......@@ -33,6 +33,7 @@ class SyncedTabDelegateAndroid : public TabContentsSyncedTabDelegate {
SessionID GetWindowId() const override;
SessionID GetSessionId() const override;
bool IsPlaceholderTab() const override;
bool ShouldSync(sync_sessions::SyncSessionsClient* sessions_client) override;
// Set the web contents for this tab and handles source tab ID initialization.
void SetWebContents(content::WebContents* web_contents, int source_tab_id);
......
......@@ -556,6 +556,7 @@ if (is_android) {
sources = [
"../browser/android/customtabs/custom_tabs_browsertest.cc",
"../browser/android/tab_android_browsertest.cc",
"../browser/android/webapk/webapk_icon_hasher_browsertest.cc",
"../browser/engagement/important_sites_util_browsertest.cc",
"../browser/games/games_service_browsertest.cc",
......
......@@ -52,6 +52,10 @@ class SessionSyncServiceImpl : public SessionSyncService {
// useful for tests.
OpenTabsUIDelegate* GetUnderlyingOpenTabsUIDelegateForTest();
SyncSessionsClient* GetSessionsClientForTest() {
return sessions_client_.get();
}
private:
void NotifyForeignSessionUpdated();
......
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