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) { ...@@ -430,14 +430,13 @@ void DeveloperPrivateEventRouter::OnAppWindowRemoved(AppWindow* window) {
void DeveloperPrivateEventRouter::OnExtensionCommandAdded( void DeveloperPrivateEventRouter::OnExtensionCommandAdded(
const std::string& extension_id, const std::string& extension_id,
const Command& added_command) { const Command& added_command) {
BroadcastItemStateChanged(developer::EVENT_TYPE_PREFS_CHANGED, BroadcastItemStateChanged(developer::EVENT_TYPE_COMMAND_ADDED, extension_id);
extension_id);
} }
void DeveloperPrivateEventRouter::OnExtensionCommandRemoved( void DeveloperPrivateEventRouter::OnExtensionCommandRemoved(
const std::string& extension_id, const std::string& extension_id,
const Command& removed_command) { const Command& removed_command) {
BroadcastItemStateChanged(developer::EVENT_TYPE_PREFS_CHANGED, BroadcastItemStateChanged(developer::EVENT_TYPE_COMMAND_REMOVED,
extension_id); extension_id);
} }
......
...@@ -242,12 +242,19 @@ cr.define('extensions', function() { ...@@ -242,12 +242,19 @@ cr.define('extensions', function() {
case EventType.ERRORS_REMOVED: case EventType.ERRORS_REMOVED:
case EventType.PREFS_CHANGED: case EventType.PREFS_CHANGED:
case EventType.WARNINGS_CHANGED: case EventType.WARNINGS_CHANGED:
case EventType.COMMAND_ADDED:
case EventType.COMMAND_REMOVED:
// |extensionInfo| can be undefined in the case of an extension // |extensionInfo| can be undefined in the case of an extension
// being unloaded right before uninstallation. There's nothing to do // being unloaded right before uninstallation. There's nothing to do
// here. // here.
if (!eventData.extensionInfo) if (!eventData.extensionInfo)
break; break;
if (this.delegate.shouldIgnoreUpdate(
eventData.extensionInfo.id, eventData.event_type)) {
break;
}
const listId = this.getListId_(eventData.extensionInfo); const listId = this.getListId_(eventData.extensionInfo);
const currentIndex = this[listId].findIndex( const currentIndex = this[listId].findIndex(
item => item.id == eventData.extensionInfo.id); item => item.id == eventData.extensionInfo.id);
......
...@@ -17,6 +17,9 @@ cr.define('extensions', function() { ...@@ -17,6 +17,9 @@ cr.define('extensions', function() {
constructor() { constructor() {
/** @private {boolean} */ /** @private {boolean} */
this.isDeleting_ = false; this.isDeleting_ = false;
/** @private {!Set<string>} */
this.eventsToIgnoreOnce_ = new Set();
} }
getProfileConfiguration() { getProfileConfiguration() {
...@@ -29,6 +32,23 @@ cr.define('extensions', function() { ...@@ -29,6 +32,23 @@ cr.define('extensions', function() {
return chrome.developerPrivate.onItemStateChanged; 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() { getProfileStateChangedTarget() {
return chrome.developerPrivate.onProfileStateChanged; return chrome.developerPrivate.onProfileStateChanged;
} }
...@@ -79,6 +99,11 @@ cr.define('extensions', function() { ...@@ -79,6 +99,11 @@ cr.define('extensions', function() {
/** @override */ /** @override */
updateExtensionCommandScope(extensionId, commandName, scope) { 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({ chrome.developerPrivate.updateExtensionCommand({
extensionId: extensionId, extensionId: extensionId,
commandName: commandName, commandName: commandName,
......
...@@ -357,7 +357,9 @@ namespace developerPrivate { ...@@ -357,7 +357,9 @@ namespace developerPrivate {
ERROR_ADDED, ERROR_ADDED,
ERRORS_REMOVED, ERRORS_REMOVED,
PREFS_CHANGED, PREFS_CHANGED,
WARNINGS_CHANGED WARNINGS_CHANGED,
COMMAND_ADDED,
COMMAND_REMOVED
}; };
dictionary PackDirectoryResponse { dictionary PackDirectoryResponse {
......
...@@ -15,6 +15,7 @@ cr.define('extensions', function() { ...@@ -15,6 +15,7 @@ cr.define('extensions', function() {
'reloadItem', 'reloadItem',
'setProfileInDevMode', 'setProfileInDevMode',
'setShortcutHandlingSuspended', 'setShortcutHandlingSuspended',
'shouldIgnoreUpdate',
'updateAllExtensions', 'updateAllExtensions',
'updateExtensionCommandKeybinding', 'updateExtensionCommandKeybinding',
'updateExtensionCommandScope', 'updateExtensionCommandScope',
...@@ -77,6 +78,11 @@ cr.define('extensions', function() { ...@@ -77,6 +78,11 @@ cr.define('extensions', function() {
this.methodCalled('setShortcutHandlingSuspended', enable); this.methodCalled('setShortcutHandlingSuspended', enable);
} }
/** @override */
shouldIgnoreUpdate(extensionId, eventType) {
this.methodCalled('shouldIgnoreUpdate', [extensionId, eventType]);
}
/** @override */ /** @override */
updateExtensionCommandKeybinding(item, commandName, keybinding) { updateExtensionCommandKeybinding(item, commandName, keybinding) {
this.methodCalled( this.methodCalled(
......
...@@ -476,6 +476,8 @@ chrome.developerPrivate.EventType = { ...@@ -476,6 +476,8 @@ chrome.developerPrivate.EventType = {
ERRORS_REMOVED: 'ERRORS_REMOVED', ERRORS_REMOVED: 'ERRORS_REMOVED',
PREFS_CHANGED: 'PREFS_CHANGED', PREFS_CHANGED: 'PREFS_CHANGED',
WARNINGS_CHANGED: 'WARNINGS_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