summaryrefslogtreecommitdiff
path: root/chromium/chrome/browser/ui/webui/media/webrtc_logs_ui.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/chrome/browser/ui/webui/media/webrtc_logs_ui.cc')
-rw-r--r--chromium/chrome/browser/ui/webui/media/webrtc_logs_ui.cc34
1 files changed, 10 insertions, 24 deletions
diff --git a/chromium/chrome/browser/ui/webui/media/webrtc_logs_ui.cc b/chromium/chrome/browser/ui/webui/media/webrtc_logs_ui.cc
index 43e045c5615..69df161dfeb 100644
--- a/chromium/chrome/browser/ui/webui/media/webrtc_logs_ui.cc
+++ b/chromium/chrome/browser/ui/webui/media/webrtc_logs_ui.cc
@@ -13,6 +13,7 @@
#include "base/i18n/time_formatting.h"
#include "base/macros.h"
#include "base/memory/ref_counted_memory.h"
+#include "base/memory/weak_ptr.h"
#include "base/strings/string16.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
@@ -76,7 +77,7 @@ content::WebUIDataSource* CreateWebRtcLogsUIHTMLSource() {
////////////////////////////////////////////////////////////////////////////////
// The handler for Javascript messages for the chrome://webrtc-logs/ page.
-class WebRtcLogsDOMHandler : public WebUIMessageHandler {
+class WebRtcLogsDOMHandler final : public WebUIMessageHandler {
public:
explicit WebRtcLogsDOMHandler(Profile* profile);
~WebRtcLogsDOMHandler() override;
@@ -85,8 +86,6 @@ class WebRtcLogsDOMHandler : public WebUIMessageHandler {
void RegisterMessages() override;
private:
- void OnUploadListAvailable();
-
// Asynchronously fetches the list of upload WebRTC logs. Called from JS.
void HandleRequestWebRtcLogs(const base::ListValue* args);
@@ -99,12 +98,8 @@ class WebRtcLogsDOMHandler : public WebUIMessageHandler {
// The directory where the logs are stored.
base::FilePath log_dir_;
- // Set when |upload_list_| has finished populating the list of logs.
- bool list_available_;
-
- // Set when the webpage wants to update the list (on the webpage) but
- // |upload_list_| hasn't finished populating the list of logs yet.
- bool js_request_pending_;
+ // Factory for creating weak references to instances of this class.
+ base::WeakPtrFactory<WebRtcLogsDOMHandler> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(WebRtcLogsDOMHandler);
};
@@ -113,8 +108,7 @@ WebRtcLogsDOMHandler::WebRtcLogsDOMHandler(Profile* profile)
: log_dir_(
webrtc_logging::LogList::GetWebRtcLogDirectoryForBrowserContextPath(
profile->GetPath())),
- list_available_(false),
- js_request_pending_(false) {
+ weak_ptr_factory_(this) {
upload_list_ = webrtc_logging::LogList::CreateWebRtcLogList(profile);
}
@@ -123,27 +117,19 @@ WebRtcLogsDOMHandler::~WebRtcLogsDOMHandler() {
}
void WebRtcLogsDOMHandler::RegisterMessages() {
- upload_list_->Load(base::BindOnce(
- &WebRtcLogsDOMHandler::OnUploadListAvailable, base::Unretained(this)));
+ upload_list_->Load(base::BindOnce(&WebRtcLogsDOMHandler::UpdateUI,
+ weak_ptr_factory_.GetWeakPtr()));
web_ui()->RegisterMessageCallback(
"requestWebRtcLogsList",
base::BindRepeating(&WebRtcLogsDOMHandler::HandleRequestWebRtcLogs,
- base::Unretained(this)));
+ weak_ptr_factory_.GetWeakPtr()));
}
void WebRtcLogsDOMHandler::HandleRequestWebRtcLogs(
const base::ListValue* args) {
- if (list_available_)
- UpdateUI();
- else
- js_request_pending_ = true;
-}
-
-void WebRtcLogsDOMHandler::OnUploadListAvailable() {
- list_available_ = true;
- if (js_request_pending_)
- UpdateUI();
+ upload_list_->Load(base::BindOnce(&WebRtcLogsDOMHandler::UpdateUI,
+ weak_ptr_factory_.GetWeakPtr()));
}
void WebRtcLogsDOMHandler::UpdateUI() {