Skip to content

Commit

Permalink
Privacy Guide: fix completion card WAA link (show to signed-in users)
Browse files Browse the repository at this point in the history
Workaround for crbug.com/1322559 to fix crbug.com/1322546: to get the
initial state, the completion card now requests an |UpdateSyncState|
event from the clear browsing data handler, which contains a |signedIn|
variable that indicates if the user is signed in (instead of requesting
a |SyncStatus| event from the people handler, in which |signedIn|
indicates if the user is syncing). The completion card did already use
the UpdateSyncState| event before - it just didn't query it for the
initial update.

Fixed: 1322546
Bug: 1215630
Change-Id: I985be3eabb218e0098977d34bd2b768398f1399c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3635498
Commit-Queue: Rainhard Findling <rainhard@chromium.org>
Reviewed-by: Demetrios Papadopoulos <dpapad@chromium.org>
Reviewed-by: Theodore Olsauskas-Warren <sauski@google.com>
Cr-Commit-Position: refs/heads/main@{#1001952}
  • Loading branch information
Rainhard Findling authored and Chromium LUCI CQ committed May 11, 2022
1 parent 44326f3 commit 66f01bd
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ export interface ClearBrowsingDataBrowserProxy {
* @return Signal when the setup is complete.
*/
initialize(): Promise<void>;

/**
* @return A promise with the current sync state.
*/
getSyncState(): Promise<UpdateSyncStateEvent>;
}

export class ClearBrowsingDataBrowserProxyImpl implements
Expand All @@ -87,6 +92,10 @@ export class ClearBrowsingDataBrowserProxyImpl implements
return sendWithPromise('initializeClearBrowsingData');
}

getSyncState() {
return sendWithPromise('getSyncState');
}

static getInstance(): ClearBrowsingDataBrowserProxy {
return instance || (instance = new ClearBrowsingDataBrowserProxyImpl());
}
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/resources/settings/lazy_load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export {ChromeCleanerScannerResults, ChromeCleanupFilePath, ChromeCleanupIdleRea
export {ChromeCleanupProxy, ChromeCleanupProxyImpl} from './chrome_cleanup_page/chrome_cleanup_proxy.js';
export {CHROME_CLEANUP_DEFAULT_ITEMS_TO_SHOW, ItemsToRemoveListElement} from './chrome_cleanup_page/items_to_remove_list.js';
// </if>
export {ClearBrowsingDataBrowserProxy, ClearBrowsingDataBrowserProxyImpl, ClearBrowsingDataResult, InstalledApp} from './clear_browsing_data_dialog/clear_browsing_data_browser_proxy.js';
export {ClearBrowsingDataBrowserProxy, ClearBrowsingDataBrowserProxyImpl, ClearBrowsingDataResult, InstalledApp, UpdateSyncStateEvent} from './clear_browsing_data_dialog/clear_browsing_data_browser_proxy.js';
export {SettingsClearBrowsingDataDialogElement} from './clear_browsing_data_dialog/clear_browsing_data_dialog.js';
export {SettingsHistoryDeletionDialogElement} from './clear_browsing_data_dialog/history_deletion_dialog.js';
export {SettingsPasswordsDeletionDialogElement} from './clear_browsing_data_dialog/passwords_deletion_dialog.js';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ import './privacy_guide_fragment_shared_css.js';
import {WebUIListenerMixin} from 'chrome://resources/js/web_ui_listener_mixin.js';
import {PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';

import {UpdateSyncStateEvent} from '../../clear_browsing_data_dialog/clear_browsing_data_browser_proxy.js';
import {ClearBrowsingDataBrowserProxyImpl, UpdateSyncStateEvent} from '../../clear_browsing_data_dialog/clear_browsing_data_browser_proxy.js';
import {loadTimeData} from '../../i18n_setup.js';
import {MetricsBrowserProxy, MetricsBrowserProxyImpl, PrivacyGuideInteractions} from '../../metrics_browser_proxy.js';
import {OpenWindowProxyImpl} from '../../open_window_proxy.js';
import {SyncBrowserProxyImpl, SyncStatus} from '../../people_page/sync_browser_proxy.js';
import {Router} from '../../router.js';

import {getTemplate} from './privacy_guide_completion_fragment.html.js';
Expand Down Expand Up @@ -57,11 +56,12 @@ export class PrivacyGuideCompletionFragmentElement extends

override ready() {
super.ready();
SyncBrowserProxyImpl.getInstance().getSyncStatus().then(
(status: SyncStatus) => this.updateWaaLink_(status.signedIn!));
this.addWebUIListener(
'update-sync-state',
(event: UpdateSyncStateEvent) => this.updateWaaLink_(event.signedIn));
ClearBrowsingDataBrowserProxyImpl.getInstance().getSyncState().then(
(status: UpdateSyncStateEvent) =>
this.updateWaaLink_(status.signedIn));
}

override focus() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ void ClearBrowsingDataHandler::RegisterMessages() {
"initializeClearBrowsingData",
base::BindRepeating(&ClearBrowsingDataHandler::HandleInitialize,
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"getSyncState",
base::BindRepeating(&ClearBrowsingDataHandler::HandleGetSyncState,
base::Unretained(this)));
}

void ClearBrowsingDataHandler::OnJavascriptAllowed() {
Expand Down Expand Up @@ -430,11 +434,22 @@ void ClearBrowsingDataHandler::HandleInitialize(const base::Value::List& args) {
ResolveJavascriptCallback(callback_id, base::Value() /* Promise<void> */);
}

void ClearBrowsingDataHandler::HandleGetSyncState(
const base::Value::List& args) {
AllowJavascript();
const base::Value& callback_id = args[0];
ResolveJavascriptCallback(callback_id, CreateSyncStateEvent());
}

void ClearBrowsingDataHandler::OnStateChanged(syncer::SyncService* sync) {
UpdateSyncState();
}

void ClearBrowsingDataHandler::UpdateSyncState() {
FireWebUIListener("update-sync-state", CreateSyncStateEvent());
}

base::DictionaryValue ClearBrowsingDataHandler::CreateSyncStateEvent() {
signin::IdentityManager* identity_manager =
IdentityManagerFactory::GetForProfile(profile_);
base::DictionaryValue event;
Expand Down Expand Up @@ -469,7 +484,7 @@ void ClearBrowsingDataHandler::UpdateSyncState() {
: l10n_util::GetStringUTF16(
IDS_SETTINGS_CLEAR_NON_GOOGLE_SEARCH_HISTORY_NON_PREPOPULATED_DSE));
}
FireWebUIListener("update-sync-state", event);
return event;
}

void ClearBrowsingDataHandler::RefreshHistoryNotice() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,18 @@ class ClearBrowsingDataHandler : public SettingsPageUIHandler,
// Initializes the dialog UI. Called by JavaScript when the DOM is ready.
void HandleInitialize(const base::Value::List& args);

// Returns the current sync state to the WebUI.
void HandleGetSyncState(const base::Value::List& args);

// Implementation of SyncServiceObserver.
void OnStateChanged(syncer::SyncService* sync) override;

// Updates the footer of the dialog when the sync state changes.
virtual void UpdateSyncState();

// Create a SyncStateEvent containing the current sync state.
base::DictionaryValue CreateSyncStateEvent();

// Finds out whether we should show notice about other forms of history stored
// in user's account.
void RefreshHistoryNotice();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

// clang-format off
import {webUIListenerCallback} from 'chrome://resources/js/cr.m.js';
import {ClearBrowsingDataBrowserProxy, ClearBrowsingDataResult, InstalledApp} from 'chrome://settings/lazy_load.js';
import {ClearBrowsingDataBrowserProxy, ClearBrowsingDataResult, InstalledApp, UpdateSyncStateEvent} from 'chrome://settings/lazy_load.js';
import {TestBrowserProxy} from 'chrome://webui-test/test_browser_proxy.js';

// clang-format on
Expand Down Expand Up @@ -58,4 +58,16 @@ export class TestClearBrowsingDataBrowserProxy extends TestBrowserProxy
this.methodCalled('initialize');
return Promise.resolve();
}

getSyncState(): Promise<UpdateSyncStateEvent> {
this.methodCalled('getSyncState');
return Promise.resolve({
signedIn: false,
syncConsented: false,
syncingHistory: false,
shouldShowCookieException: false,
isNonGoogleDse: false,
nonGoogleSearchHistoryString: 'somestring',
});
}
}

0 comments on commit 66f01bd

Please sign in to comment.