Commit e076f3a9 authored by David Davidović's avatar David Davidović Committed by Commit Bot

[sync] Add CLI flag to capture specifics

When visiting chrome://sync-internals, a checkbox labeled "Capture
Specifics" is available. It controls whether the specifics of each sync
event are captured in the log displayed on the page.

Every time the page is refreshed or reopened, this checkbox is reset to
its initial, unchecked state. The flag is immensely useful for
debugging, but having to check the checkbox after each browser restart
or reopen of the page is cumbersome.

To that end, add a command-line switch "--sync-include-specifics" which
will set the initial value for the "Capture Specifics" flag on
chrome://sync-internals page load to true.

Bug: 859878
Change-Id: I43b04e2d3aabdda2e8f3bc64cb80f906f56c78b2
Reviewed-on: https://chromium-review.googlesource.com/1147221
Commit-Queue: David Davidović <davidovic@google.com>
Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Reviewed-by: default avatarvitaliii <vitaliii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#582613}
parent 2f74c00e
...@@ -64,6 +64,13 @@ bool HasSomethingAtIndex(const base::ListValue* list, int index) { ...@@ -64,6 +64,13 @@ bool HasSomethingAtIndex(const base::ListValue* list, int index) {
return false; return false;
} }
// Returns the initial state of the "include specifics" flag, based on whether
// or not the corresponding command-line switch is set.
bool GetIncludeSpecificsInitialState() {
return base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kSyncIncludeSpecificsInProtocolLog);
}
} // namespace } // namespace
SyncInternalsMessageHandler::SyncInternalsMessageHandler() SyncInternalsMessageHandler::SyncInternalsMessageHandler()
...@@ -72,7 +79,8 @@ SyncInternalsMessageHandler::SyncInternalsMessageHandler() ...@@ -72,7 +79,8 @@ SyncInternalsMessageHandler::SyncInternalsMessageHandler()
SyncInternalsMessageHandler::SyncInternalsMessageHandler( SyncInternalsMessageHandler::SyncInternalsMessageHandler(
AboutSyncDataDelegate about_sync_data_delegate) AboutSyncDataDelegate about_sync_data_delegate)
: about_sync_data_delegate_(std::move(about_sync_data_delegate)), : include_specifics_(GetIncludeSpecificsInitialState()),
about_sync_data_delegate_(std::move(about_sync_data_delegate)),
weak_ptr_factory_(this) {} weak_ptr_factory_(this) {}
SyncInternalsMessageHandler::~SyncInternalsMessageHandler() { SyncInternalsMessageHandler::~SyncInternalsMessageHandler() {
...@@ -114,6 +122,12 @@ void SyncInternalsMessageHandler::RegisterMessages() { ...@@ -114,6 +122,12 @@ void SyncInternalsMessageHandler::RegisterMessages() {
&SyncInternalsMessageHandler::HandleRequestListOfTypes, &SyncInternalsMessageHandler::HandleRequestListOfTypes,
base::Unretained(this))); base::Unretained(this)));
web_ui()->RegisterMessageCallback(
syncer::sync_ui_util::kRequestIncludeSpecificsInitialState,
base::BindRepeating(&SyncInternalsMessageHandler::
HandleRequestIncludeSpecificsInitialState,
base::Unretained(this)));
web_ui()->RegisterMessageCallback( web_ui()->RegisterMessageCallback(
syncer::sync_ui_util::kRequestUserEventsVisibility, syncer::sync_ui_util::kRequestUserEventsVisibility,
base::BindRepeating( base::BindRepeating(
...@@ -212,6 +226,19 @@ void SyncInternalsMessageHandler::HandleRequestListOfTypes( ...@@ -212,6 +226,19 @@ void SyncInternalsMessageHandler::HandleRequestListOfTypes(
DispatchEvent(syncer::sync_ui_util::kOnReceivedListOfTypes, event_details); DispatchEvent(syncer::sync_ui_util::kOnReceivedListOfTypes, event_details);
} }
void SyncInternalsMessageHandler::HandleRequestIncludeSpecificsInitialState(
const ListValue* args) {
DCHECK(args->empty());
AllowJavascript();
DictionaryValue value;
value.SetBoolean(syncer::sync_ui_util::kIncludeSpecifics,
GetIncludeSpecificsInitialState());
DispatchEvent(syncer::sync_ui_util::kOnReceivedIncludeSpecificsInitialState,
value);
}
void SyncInternalsMessageHandler::HandleGetAllNodes(const ListValue* args) { void SyncInternalsMessageHandler::HandleGetAllNodes(const ListValue* args) {
DCHECK_EQ(1U, args->GetSize()); DCHECK_EQ(1U, args->GetSize());
AllowJavascript(); AllowJavascript();
......
...@@ -52,9 +52,12 @@ class SyncInternalsMessageHandler : public content::WebUIMessageHandler, ...@@ -52,9 +52,12 @@ class SyncInternalsMessageHandler : public content::WebUIMessageHandler,
// Fires an event to send updated info back to the page. // Fires an event to send updated info back to the page.
void HandleRequestUpdatedAboutInfo(const base::ListValue* args); void HandleRequestUpdatedAboutInfo(const base::ListValue* args);
// Fires and event to send the list of types back to the page. // Fires an event to send the list of types back to the page.
void HandleRequestListOfTypes(const base::ListValue* args); void HandleRequestListOfTypes(const base::ListValue* args);
// Fires an event to send the initial state of the "include specifics" flag.
void HandleRequestIncludeSpecificsInitialState(const base::ListValue* args);
// Handler for getAllNodes message. Needs a |request_id| argument. // Handler for getAllNodes message. Needs a |request_id| argument.
void HandleGetAllNodes(const base::ListValue* args); void HandleGetAllNodes(const base::ListValue* args);
......
...@@ -50,25 +50,30 @@ const char kGetAllNodes[] = "getAllNodes"; ...@@ -50,25 +50,30 @@ const char kGetAllNodes[] = "getAllNodes";
const char kGetAllNodesCallback[] = "chrome.sync.getAllNodesCallback"; const char kGetAllNodesCallback[] = "chrome.sync.getAllNodesCallback";
const char kRegisterForEvents[] = "registerForEvents"; const char kRegisterForEvents[] = "registerForEvents";
const char kRegisterForPerTypeCounters[] = "registerForPerTypeCounters"; const char kRegisterForPerTypeCounters[] = "registerForPerTypeCounters";
const char kRequestIncludeSpecificsInitialState[] =
"requestIncludeSpecificsInitialState";
const char kRequestListOfTypes[] = "requestListOfTypes"; const char kRequestListOfTypes[] = "requestListOfTypes";
const char kRequestStart[] = "requestStart";
const char kRequestStop[] = "requestStop";
const char kRequestUpdatedAboutInfo[] = "requestUpdatedAboutInfo"; const char kRequestUpdatedAboutInfo[] = "requestUpdatedAboutInfo";
const char kRequestUserEventsVisibility[] = "requestUserEventsVisibility"; const char kRequestUserEventsVisibility[] = "requestUserEventsVisibility";
const char kSetIncludeSpecifics[] = "setIncludeSpecifics"; const char kSetIncludeSpecifics[] = "setIncludeSpecifics";
const char kTriggerRefresh[] = "triggerRefresh";
const char kUserEventsVisibilityCallback[] = const char kUserEventsVisibilityCallback[] =
"chrome.sync.userEventsVisibilityCallback"; "chrome.sync.userEventsVisibilityCallback";
const char kWriteUserEvent[] = "writeUserEvent"; const char kWriteUserEvent[] = "writeUserEvent";
const char kRequestStart[] = "requestStart";
const char kRequestStop[] = "requestStop";
const char kTriggerRefresh[] = "triggerRefresh";
// Other strings. // Other strings.
const char kCommit[] = "commit"; const char kCommit[] = "commit";
const char kCounters[] = "counters"; const char kCounters[] = "counters";
const char kCounterType[] = "counterType"; const char kCounterType[] = "counterType";
const char kIncludeSpecifics[] = "includeSpecifics";
const char kModelType[] = "modelType"; const char kModelType[] = "modelType";
const char kOnAboutInfoUpdated[] = "onAboutInfoUpdated"; const char kOnAboutInfoUpdated[] = "onAboutInfoUpdated";
const char kOnCountersUpdated[] = "onCountersUpdated"; const char kOnCountersUpdated[] = "onCountersUpdated";
const char kOnProtocolEvent[] = "onProtocolEvent"; const char kOnProtocolEvent[] = "onProtocolEvent";
const char kOnReceivedIncludeSpecificsInitialState[] =
"onReceivedIncludeSpecificsInitialState";
const char kOnReceivedListOfTypes[] = "onReceivedListOfTypes"; const char kOnReceivedListOfTypes[] = "onReceivedListOfTypes";
const char kStatus[] = "status"; const char kStatus[] = "status";
const char kTypes[] = "types"; const char kTypes[] = "types";
......
...@@ -47,25 +47,28 @@ extern const char kGetAllNodes[]; ...@@ -47,25 +47,28 @@ extern const char kGetAllNodes[];
extern const char kGetAllNodesCallback[]; extern const char kGetAllNodesCallback[];
extern const char kRegisterForEvents[]; extern const char kRegisterForEvents[];
extern const char kRegisterForPerTypeCounters[]; extern const char kRegisterForPerTypeCounters[];
extern const char kRequestIncludeSpecificsInitialState[];
extern const char kRequestListOfTypes[]; extern const char kRequestListOfTypes[];
extern const char kRequestStart[];
extern const char kRequestStop[];
extern const char kRequestUpdatedAboutInfo[]; extern const char kRequestUpdatedAboutInfo[];
extern const char kRequestUserEventsVisibility[]; extern const char kRequestUserEventsVisibility[];
extern const char kSetIncludeSpecifics[]; extern const char kSetIncludeSpecifics[];
extern const char kTriggerRefresh[];
extern const char kUserEventsVisibilityCallback[]; extern const char kUserEventsVisibilityCallback[];
extern const char kWriteUserEvent[]; extern const char kWriteUserEvent[];
extern const char kRequestStart[];
extern const char kRequestStop[];
extern const char kTriggerRefresh[];
// Other strings. // Other strings.
// Must match the constants used in the resource files. // Must match the constants used in the resource files.
extern const char kCommit[]; extern const char kCommit[];
extern const char kCounters[]; extern const char kCounters[];
extern const char kCounterType[]; extern const char kCounterType[];
extern const char kIncludeSpecifics[];
extern const char kModelType[]; extern const char kModelType[];
extern const char kOnAboutInfoUpdated[]; extern const char kOnAboutInfoUpdated[];
extern const char kOnCountersUpdated[]; extern const char kOnCountersUpdated[];
extern const char kOnProtocolEvent[]; extern const char kOnProtocolEvent[];
extern const char kOnReceivedIncludeSpecificsInitialState[];
extern const char kOnReceivedListOfTypes[]; extern const char kOnReceivedListOfTypes[];
extern const char kStatus[]; extern const char kStatus[];
extern const char kTypes[]; extern const char kTypes[];
......
...@@ -62,7 +62,7 @@ cr.define('chrome.sync', function() { ...@@ -62,7 +62,7 @@ cr.define('chrome.sync', function() {
} }
/** /**
* Asks the browser to refresh our snapshot of sync state. Should result * Asks the browser to refresh our snapshot of sync state. Should result
* in an onAboutInfoUpdated event being emitted. * in an onAboutInfoUpdated event being emitted.
*/ */
var requestUpdatedAboutInfo = function() { var requestUpdatedAboutInfo = function() {
...@@ -70,13 +70,22 @@ cr.define('chrome.sync', function() { ...@@ -70,13 +70,22 @@ cr.define('chrome.sync', function() {
}; };
/** /**
* Asks the browser to send us the list of registered types. Should result * Asks the browser to send us the list of registered types. Should result
* in an onReceivedListOfTypes event being emitted. * in an onReceivedListOfTypes event being emitted.
*/ */
var requestListOfTypes = function() { var requestListOfTypes = function() {
chrome.send('requestListOfTypes'); chrome.send('requestListOfTypes');
}; };
/**
* Asks the browser to send us the initial state of the "include specifics"
* flag. Should result in an onReceivedIncludeSpecificsInitialState event
* being emitted.
*/
var requestIncludeSpecificsInitialState = function() {
chrome.send('requestIncludeSpecificsInitialState');
}
/** /**
* Asks the browser if we should show the User Events tab or not. * Asks the browser if we should show the User Events tab or not.
*/ */
...@@ -170,6 +179,7 @@ cr.define('chrome.sync', function() { ...@@ -170,6 +179,7 @@ cr.define('chrome.sync', function() {
registerForEvents: registerForEvents, registerForEvents: registerForEvents,
registerForPerTypeCounters: registerForPerTypeCounters, registerForPerTypeCounters: registerForPerTypeCounters,
requestUpdatedAboutInfo: requestUpdatedAboutInfo, requestUpdatedAboutInfo: requestUpdatedAboutInfo,
requestIncludeSpecificsInitialState: requestIncludeSpecificsInitialState,
requestListOfTypes: requestListOfTypes, requestListOfTypes: requestListOfTypes,
requestUserEventsVisibility: requestUserEventsVisibility, requestUserEventsVisibility: requestUserEventsVisibility,
setIncludeSpecifics: setIncludeSpecifics, setIncludeSpecifics: setIncludeSpecifics,
......
...@@ -191,11 +191,20 @@ function onReceivedListOfTypes(e) { ...@@ -191,11 +191,20 @@ function onReceivedListOfTypes(e) {
onReceivedListOfTypes); onReceivedListOfTypes);
} }
function onReceivedIncludeSpecificsInitialState(e) {
$('capture-specifics').checked = e.details.includeSpecifics;
}
document.addEventListener('DOMContentLoaded', function() { document.addEventListener('DOMContentLoaded', function() {
chrome.sync.events.addEventListener( chrome.sync.events.addEventListener(
'onReceivedListOfTypes', 'onReceivedListOfTypes',
onReceivedListOfTypes); onReceivedListOfTypes);
chrome.sync.requestListOfTypes(); chrome.sync.requestListOfTypes();
chrome.sync.events.addEventListener(
'onReceivedIncludeSpecificsInitialState',
onReceivedIncludeSpecificsInitialState);
chrome.sync.requestIncludeSpecificsInitialState();
}); });
var dumpToFileLink = $('dump-to-file'); var dumpToFileLink = $('dump-to-file');
......
...@@ -17,6 +17,10 @@ const char kSyncDisableDeferredStartup[] = "sync-disable-deferred-startup"; ...@@ -17,6 +17,10 @@ const char kSyncDisableDeferredStartup[] = "sync-disable-deferred-startup";
// Enables feature to avoid unnecessary GetUpdate requests. // Enables feature to avoid unnecessary GetUpdate requests.
const char kSyncEnableGetUpdateAvoidance[] = "sync-enable-get-update-avoidance"; const char kSyncEnableGetUpdateAvoidance[] = "sync-enable-get-update-avoidance";
// Controls whether the initial state of the "Capture Specifics" flag on
// chrome://sync-internals is enabled.
const char kSyncIncludeSpecificsInProtocolLog[] = "sync-include-specifics";
// Overrides the default server used for profile sync. // Overrides the default server used for profile sync.
const char kSyncServiceURL[] = "sync-url"; const char kSyncServiceURL[] = "sync-url";
......
...@@ -15,6 +15,7 @@ namespace switches { ...@@ -15,6 +15,7 @@ namespace switches {
extern const char kSyncDeferredStartupTimeoutSeconds[]; extern const char kSyncDeferredStartupTimeoutSeconds[];
extern const char kSyncDisableDeferredStartup[]; extern const char kSyncDisableDeferredStartup[];
extern const char kSyncEnableGetUpdateAvoidance[]; extern const char kSyncEnableGetUpdateAvoidance[];
extern const char kSyncIncludeSpecificsInProtocolLog[];
extern const char kSyncServiceURL[]; extern const char kSyncServiceURL[];
extern const char kSyncShortInitialRetryOverride[]; extern const char kSyncShortInitialRetryOverride[];
extern const char kSyncShortNudgeDelayForTest[]; extern const char kSyncShortNudgeDelayForTest[];
......
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