Commit 78c18c36 authored by Dan Beam's avatar Dan Beam Committed by Commit Bot

Components: fix dead observer notification crash

When destructing ComponentsHandler, RemoveObserver() was not being
called in all cases, and therefore ComponentUpdaterService had a dead
pointer dangling until it next notifies.

R=groby@chromium.org

Fixed: 1038846
Change-Id: I2ec97e41d062ddd788c7caa6b236b4bfdb56b6be
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1987282
Auto-Submit: Dan Beam <dbeam@chromium.org>
Reviewed-by: default avatarRachel Blum <groby@chromium.org>
Commit-Queue: Dan Beam <dbeam@chromium.org>
Cr-Commit-Position: refs/heads/master@{#728365}
parent 3e9f42ba
...@@ -26,16 +26,11 @@ void ComponentsHandler::RegisterMessages() { ...@@ -26,16 +26,11 @@ void ComponentsHandler::RegisterMessages() {
} }
void ComponentsHandler::OnJavascriptAllowed() { void ComponentsHandler::OnJavascriptAllowed() {
component_updater::ComponentUpdateService* cus = observer_.Add(g_browser_process->component_updater());
g_browser_process->component_updater();
cus->AddObserver(this);
} }
void ComponentsHandler::OnJavascriptDisallowed() { void ComponentsHandler::OnJavascriptDisallowed() {
component_updater::ComponentUpdateService* cus = observer_.RemoveAll();
g_browser_process->component_updater();
if (cus)
cus->RemoveObserver(this);
} }
void ComponentsHandler::HandleRequestComponentsData( void ComponentsHandler::HandleRequestComponentsData(
...@@ -142,7 +137,7 @@ base::string16 ComponentsHandler::ServiceStatusToString( ...@@ -142,7 +137,7 @@ base::string16 ComponentsHandler::ServiceStatusToString(
void ComponentsHandler::OnDemandUpdate(const std::string& component_id) { void ComponentsHandler::OnDemandUpdate(const std::string& component_id) {
component_updater::ComponentUpdateService* cus = component_updater::ComponentUpdateService* cus =
g_browser_process->component_updater(); g_browser_process->component_updater();
if (cus) { if (cus) { // TODO(dbeam): can this return nullptr if called from UI thread?
cus->GetOnDemandUpdater().OnDemandUpdate( cus->GetOnDemandUpdater().OnDemandUpdate(
component_id, component_updater::OnDemandUpdater::Priority::FOREGROUND, component_id, component_updater::OnDemandUpdater::Priority::FOREGROUND,
component_updater::Callback()); component_updater::Callback());
......
...@@ -8,10 +8,10 @@ ...@@ -8,10 +8,10 @@
#include <memory> #include <memory>
#include <string> #include <string>
#include "base/scoped_observer.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "components/component_updater/component_updater_service.h" #include "components/component_updater/component_updater_service.h"
#include "components/update_client/update_client.h" #include "components/update_client/update_client.h"
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/web_ui_message_handler.h" #include "content/public/browser/web_ui_message_handler.h"
namespace base { namespace base {
...@@ -48,7 +48,9 @@ class ComponentsHandler : public content::WebUIMessageHandler, ...@@ -48,7 +48,9 @@ class ComponentsHandler : public content::WebUIMessageHandler,
static std::unique_ptr<base::ListValue> LoadComponents(); static std::unique_ptr<base::ListValue> LoadComponents();
static void OnDemandUpdate(const std::string& component_id); static void OnDemandUpdate(const std::string& component_id);
content::NotificationRegistrar registrar_; ScopedObserver<component_updater::ComponentUpdateService,
component_updater::ComponentUpdateService::Observer>
observer_{this};
}; };
#endif // CHROME_BROWSER_UI_WEBUI_COMPONENTS_COMPONENTS_HANDLER_H_ #endif // CHROME_BROWSER_UI_WEBUI_COMPONENTS_COMPONENTS_HANDLER_H_
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