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) {
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
SyncInternalsMessageHandler::SyncInternalsMessageHandler()
......@@ -72,7 +79,8 @@ SyncInternalsMessageHandler::SyncInternalsMessageHandler()
SyncInternalsMessageHandler::SyncInternalsMessageHandler(
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) {}
SyncInternalsMessageHandler::~SyncInternalsMessageHandler() {
......@@ -114,6 +122,12 @@ void SyncInternalsMessageHandler::RegisterMessages() {
&SyncInternalsMessageHandler::HandleRequestListOfTypes,
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
syncer::sync_ui_util::kRequestIncludeSpecificsInitialState,
base::BindRepeating(&SyncInternalsMessageHandler::
HandleRequestIncludeSpecificsInitialState,
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
syncer::sync_ui_util::kRequestUserEventsVisibility,
base::BindRepeating(
......@@ -212,6 +226,19 @@ void SyncInternalsMessageHandler::HandleRequestListOfTypes(
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) {
DCHECK_EQ(1U, args->GetSize());
AllowJavascript();
......
......@@ -52,9 +52,12 @@ class SyncInternalsMessageHandler : public content::WebUIMessageHandler,
// Fires an event to send updated info back to the page.
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);
// 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.
void HandleGetAllNodes(const base::ListValue* args);
......
......@@ -50,25 +50,30 @@ const char kGetAllNodes[] = "getAllNodes";
const char kGetAllNodesCallback[] = "chrome.sync.getAllNodesCallback";
const char kRegisterForEvents[] = "registerForEvents";
const char kRegisterForPerTypeCounters[] = "registerForPerTypeCounters";
const char kRequestIncludeSpecificsInitialState[] =
"requestIncludeSpecificsInitialState";
const char kRequestListOfTypes[] = "requestListOfTypes";
const char kRequestStart[] = "requestStart";
const char kRequestStop[] = "requestStop";
const char kRequestUpdatedAboutInfo[] = "requestUpdatedAboutInfo";
const char kRequestUserEventsVisibility[] = "requestUserEventsVisibility";
const char kSetIncludeSpecifics[] = "setIncludeSpecifics";
const char kTriggerRefresh[] = "triggerRefresh";
const char kUserEventsVisibilityCallback[] =
"chrome.sync.userEventsVisibilityCallback";
const char kWriteUserEvent[] = "writeUserEvent";
const char kRequestStart[] = "requestStart";
const char kRequestStop[] = "requestStop";
const char kTriggerRefresh[] = "triggerRefresh";
// Other strings.
const char kCommit[] = "commit";
const char kCounters[] = "counters";
const char kCounterType[] = "counterType";
const char kIncludeSpecifics[] = "includeSpecifics";
const char kModelType[] = "modelType";
const char kOnAboutInfoUpdated[] = "onAboutInfoUpdated";
const char kOnCountersUpdated[] = "onCountersUpdated";
const char kOnProtocolEvent[] = "onProtocolEvent";
const char kOnReceivedIncludeSpecificsInitialState[] =
"onReceivedIncludeSpecificsInitialState";
const char kOnReceivedListOfTypes[] = "onReceivedListOfTypes";
const char kStatus[] = "status";
const char kTypes[] = "types";
......
......@@ -47,25 +47,28 @@ extern const char kGetAllNodes[];
extern const char kGetAllNodesCallback[];
extern const char kRegisterForEvents[];
extern const char kRegisterForPerTypeCounters[];
extern const char kRequestIncludeSpecificsInitialState[];
extern const char kRequestListOfTypes[];
extern const char kRequestStart[];
extern const char kRequestStop[];
extern const char kRequestUpdatedAboutInfo[];
extern const char kRequestUserEventsVisibility[];
extern const char kSetIncludeSpecifics[];
extern const char kTriggerRefresh[];
extern const char kUserEventsVisibilityCallback[];
extern const char kWriteUserEvent[];
extern const char kRequestStart[];
extern const char kRequestStop[];
extern const char kTriggerRefresh[];
// Other strings.
// Must match the constants used in the resource files.
extern const char kCommit[];
extern const char kCounters[];
extern const char kCounterType[];
extern const char kIncludeSpecifics[];
extern const char kModelType[];
extern const char kOnAboutInfoUpdated[];
extern const char kOnCountersUpdated[];
extern const char kOnProtocolEvent[];
extern const char kOnReceivedIncludeSpecificsInitialState[];
extern const char kOnReceivedListOfTypes[];
extern const char kStatus[];
extern const char kTypes[];
......
......@@ -77,6 +77,15 @@ cr.define('chrome.sync', function() {
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.
*/
......@@ -170,6 +179,7 @@ cr.define('chrome.sync', function() {
registerForEvents: registerForEvents,
registerForPerTypeCounters: registerForPerTypeCounters,
requestUpdatedAboutInfo: requestUpdatedAboutInfo,
requestIncludeSpecificsInitialState: requestIncludeSpecificsInitialState,
requestListOfTypes: requestListOfTypes,
requestUserEventsVisibility: requestUserEventsVisibility,
setIncludeSpecifics: setIncludeSpecifics,
......
......@@ -191,11 +191,20 @@ function onReceivedListOfTypes(e) {
onReceivedListOfTypes);
}
function onReceivedIncludeSpecificsInitialState(e) {
$('capture-specifics').checked = e.details.includeSpecifics;
}
document.addEventListener('DOMContentLoaded', function() {
chrome.sync.events.addEventListener(
'onReceivedListOfTypes',
onReceivedListOfTypes);
chrome.sync.requestListOfTypes();
chrome.sync.events.addEventListener(
'onReceivedIncludeSpecificsInitialState',
onReceivedIncludeSpecificsInitialState);
chrome.sync.requestIncludeSpecificsInitialState();
});
var dumpToFileLink = $('dump-to-file');
......
......@@ -17,6 +17,10 @@ const char kSyncDisableDeferredStartup[] = "sync-disable-deferred-startup";
// Enables feature to avoid unnecessary GetUpdate requests.
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.
const char kSyncServiceURL[] = "sync-url";
......
......@@ -15,6 +15,7 @@ namespace switches {
extern const char kSyncDeferredStartupTimeoutSeconds[];
extern const char kSyncDisableDeferredStartup[];
extern const char kSyncEnableGetUpdateAvoidance[];
extern const char kSyncIncludeSpecificsInProtocolLog[];
extern const char kSyncServiceURL[];
extern const char kSyncShortInitialRetryOverride[];
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