Commit 19f16a51 authored by Esmael El-Moslimany's avatar Esmael El-Moslimany Committed by Commit Bot

MD Extensions: avoid sending remove event when adding immediately afterward

Bug: 836988
Cq-Include-Trybots: master.tryserver.chromium.linux:closure_compilation
Change-Id: Iedcac22a68cb73f68f314f35b1e1c771ab52c8ad
Reviewed-on: https://chromium-review.googlesource.com/1036199
Commit-Queue: Esmael El-Moslimany <aee@chromium.org>
Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#557298}
parent bb372ca2
......@@ -430,14 +430,13 @@ void DeveloperPrivateEventRouter::OnAppWindowRemoved(AppWindow* window) {
void DeveloperPrivateEventRouter::OnExtensionCommandAdded(
const std::string& extension_id,
const Command& added_command) {
BroadcastItemStateChanged(developer::EVENT_TYPE_PREFS_CHANGED,
extension_id);
BroadcastItemStateChanged(developer::EVENT_TYPE_COMMAND_ADDED, extension_id);
}
void DeveloperPrivateEventRouter::OnExtensionCommandRemoved(
const std::string& extension_id,
const Command& removed_command) {
BroadcastItemStateChanged(developer::EVENT_TYPE_PREFS_CHANGED,
BroadcastItemStateChanged(developer::EVENT_TYPE_COMMAND_REMOVED,
extension_id);
}
......
......@@ -242,12 +242,19 @@ cr.define('extensions', function() {
case EventType.ERRORS_REMOVED:
case EventType.PREFS_CHANGED:
case EventType.WARNINGS_CHANGED:
case EventType.COMMAND_ADDED:
case EventType.COMMAND_REMOVED:
// |extensionInfo| can be undefined in the case of an extension
// being unloaded right before uninstallation. There's nothing to do
// here.
if (!eventData.extensionInfo)
break;
if (this.delegate.shouldIgnoreUpdate(
eventData.extensionInfo.id, eventData.event_type)) {
break;
}
const listId = this.getListId_(eventData.extensionInfo);
const currentIndex = this[listId].findIndex(
item => item.id == eventData.extensionInfo.id);
......
......@@ -17,6 +17,9 @@ cr.define('extensions', function() {
constructor() {
/** @private {boolean} */
this.isDeleting_ = false;
/** @private {!Set<string>} */
this.eventsToIgnoreOnce_ = new Set();
}
getProfileConfiguration() {
......@@ -29,6 +32,23 @@ cr.define('extensions', function() {
return chrome.developerPrivate.onItemStateChanged;
}
/**
* @param {string} extensionId
* @param {!chrome.developerPrivate.EventType} eventType
* @return {boolean}
*/
shouldIgnoreUpdate(extensionId, eventType) {
return this.eventsToIgnoreOnce_.delete(`${extensionId}_${eventType}`);
}
/**
* @param {string} extensionId
* @param {!chrome.developerPrivate.EventType} eventType
*/
ignoreNextEvent(extensionId, eventType) {
this.eventsToIgnoreOnce_.add(`${extensionId}_${eventType}`);
}
getProfileStateChangedTarget() {
return chrome.developerPrivate.onProfileStateChanged;
}
......@@ -79,6 +99,11 @@ cr.define('extensions', function() {
/** @override */
updateExtensionCommandScope(extensionId, commandName, scope) {
// The COMMAND_REMOVED event needs to be ignored since it is sent before
// the command is added back with the updated scope but can be handled
// after the COMMAND_ADDED event.
this.ignoreNextEvent(
extensionId, chrome.developerPrivate.EventType.COMMAND_REMOVED);
chrome.developerPrivate.updateExtensionCommand({
extensionId: extensionId,
commandName: commandName,
......
......@@ -357,7 +357,9 @@ namespace developerPrivate {
ERROR_ADDED,
ERRORS_REMOVED,
PREFS_CHANGED,
WARNINGS_CHANGED
WARNINGS_CHANGED,
COMMAND_ADDED,
COMMAND_REMOVED
};
dictionary PackDirectoryResponse {
......
......@@ -15,6 +15,7 @@ cr.define('extensions', function() {
'reloadItem',
'setProfileInDevMode',
'setShortcutHandlingSuspended',
'shouldIgnoreUpdate',
'updateAllExtensions',
'updateExtensionCommandKeybinding',
'updateExtensionCommandScope',
......@@ -77,6 +78,11 @@ cr.define('extensions', function() {
this.methodCalled('setShortcutHandlingSuspended', enable);
}
/** @override */
shouldIgnoreUpdate(extensionId, eventType) {
this.methodCalled('shouldIgnoreUpdate', [extensionId, eventType]);
}
/** @override */
updateExtensionCommandKeybinding(item, commandName, keybinding) {
this.methodCalled(
......
......@@ -476,6 +476,8 @@ chrome.developerPrivate.EventType = {
ERRORS_REMOVED: 'ERRORS_REMOVED',
PREFS_CHANGED: 'PREFS_CHANGED',
WARNINGS_CHANGED: 'WARNINGS_CHANGED',
COMMAND_ADDED: 'COMMAND_ADDED',
COMMAND_REMOVED: 'COMMAND_REMOVED',
};
/**
......
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