Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8596)

Unified Diff: chrome/browser/ui/webui/conflicts_ui.cc

Issue 2037883004: [Win] Add reporting of total number of modules loaded in browser process. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/conflicts_ui.cc
diff --git a/chrome/browser/ui/webui/conflicts_ui.cc b/chrome/browser/ui/webui/conflicts_ui.cc
index e4166b6af9c7495ed594f87c007eb2109566257e..d39f36787e8f7b3fbaf2402eb9633c9de31c4fcf 100644
--- a/chrome/browser/ui/webui/conflicts_ui.cc
+++ b/chrome/browser/ui/webui/conflicts_ui.cc
@@ -12,6 +12,7 @@
#include "base/bind_helpers.h"
#include "base/macros.h"
#include "base/memory/ref_counted_memory.h"
+#include "base/scoped_observer.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
@@ -77,11 +78,11 @@ content::WebUIDataSource* CreateConflictsUIHTMLSource() {
//
////////////////////////////////////////////////////////////////////////////////
-// The handler for JavaScript messages for the about:flags page.
+// The handler for JavaScript messages for the about:conflicts page.
class ConflictsDOMHandler : public WebUIMessageHandler,
- public content::NotificationObserver {
+ public EnumerateModulesModel::Observer {
public:
- ConflictsDOMHandler() {}
+ ConflictsDOMHandler();
~ConflictsDOMHandler() override {}
// WebUIMessageHandler implementation.
@@ -93,15 +94,19 @@ class ConflictsDOMHandler : public WebUIMessageHandler,
private:
void SendModuleList();
- void Observe(int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) override;
+ // EnumerateModulesModel::Observer implementation.
+ void OnScanCompleted() override;
- content::NotificationRegistrar registrar_;
+ ScopedObserver<EnumerateModulesModel,
+ EnumerateModulesModel::Observer> observer_;
DISALLOW_COPY_AND_ASSIGN(ConflictsDOMHandler);
};
+ConflictsDOMHandler::ConflictsDOMHandler()
+ : observer_(this) {
+}
+
void ConflictsDOMHandler::RegisterMessages() {
web_ui()->RegisterMessageCallback("requestModuleList",
base::Bind(&ConflictsDOMHandler::HandleRequestModuleList,
@@ -109,14 +114,20 @@ void ConflictsDOMHandler::RegisterMessages() {
}
void ConflictsDOMHandler::HandleRequestModuleList(const base::ListValue* args) {
- // This request is handled asynchronously. See Observe for when we reply back.
- registrar_.Add(this, chrome::NOTIFICATION_MODULE_LIST_ENUMERATED,
- content::NotificationService::AllSources());
- EnumerateModulesModel::GetInstance()->ScanNow();
+ // The request is handled asynchronously, and will callback via
+ // OnScanCompleted on completion.
+ auto* model = EnumerateModulesModel::GetInstance();
+
+ // The JS shouldn't be abusive and call 'requestModuleList' twice, but it's
+ // easy enough to defend against this.
+ if (!observer_.IsObserving(model)) {
+ observer_.Add(model);
+ model->ScanNow();
+ }
}
void ConflictsDOMHandler::SendModuleList() {
- EnumerateModulesModel* loaded_modules = EnumerateModulesModel::GetInstance();
+ auto* loaded_modules = EnumerateModulesModel::GetInstance();
base::ListValue* list = loaded_modules->GetModuleList();
base::DictionaryValue results;
results.Set("moduleList", list);
@@ -141,13 +152,9 @@ void ConflictsDOMHandler::SendModuleList() {
web_ui()->CallJavascriptFunctionUnsafe("returnModuleList", results);
}
-void ConflictsDOMHandler::Observe(int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) {
- DCHECK_EQ(chrome::NOTIFICATION_MODULE_LIST_ENUMERATED, type);
-
+void ConflictsDOMHandler::OnScanCompleted() {
SendModuleList();
- registrar_.RemoveAll();
+ observer_.Remove(EnumerateModulesModel::GetInstance());
}
} // namespace
« no previous file with comments | « chrome/browser/ui/views/conflicting_module_view_win.cc ('k') | chrome/browser/win/enumerate_modules_model.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698