Commit 61adfd22 authored by Adam Rice's avatar Adam Rice Committed by Commit Bot

Eliminate usage of SupportsWeakPtr from WebSocketFactory

Inheriting from SupportsWeakPtr<T> is error-prone because weak pointers
are not invalidated until the parent object has been partially
destroyed.

Use WeakPtrFactory instead in WebSocketFactory::Delegate.
WebSocketFactory doesn't need weak pointers at all, so remove it
completely from there.

Bug: 721400
Cq-Include-Trybots: master.tryserver.chromium.linux:linux_mojo
Change-Id: I94f8dc6fa20b4ede14295760db44bdeaae207610
Reviewed-on: https://chromium-review.googlesource.com/981964Reviewed-by: default avatarYutaka Hirano <yhirano@chromium.org>
Commit-Queue: Adam Rice <ricea@chromium.org>
Cr-Commit-Position: refs/heads/master@{#546074}
parent e261fd46
......@@ -14,12 +14,10 @@
namespace network {
class WebSocketFactory::Delegate final
: public WebSocket::Delegate,
public base::SupportsWeakPtr<Delegate> {
class WebSocketFactory::Delegate final : public WebSocket::Delegate {
public:
Delegate(WebSocketFactory* factory, int32_t process_id)
: factory_(factory), process_id_(process_id) {}
: factory_(factory), process_id_(process_id), weak_factory_(this) {}
~Delegate() override {}
net::URLRequestContext* GetURLRequestContext() override {
......@@ -54,7 +52,7 @@ class WebSocketFactory::Delegate final
process_id, render_frame_id, request_id, resource_type, url, ssl_info,
fatal,
base::BindRepeating(&Delegate::OnSSLCertificateErrorResponse,
AsWeakPtr(), ssl_info));
weak_factory_.GetWeakPtr(), ssl_info));
}
void ReportBadMessage(BadMessageReason reason, WebSocket* impl) override {
......@@ -86,6 +84,8 @@ class WebSocketFactory::Delegate final
const int process_id_;
std::unique_ptr<net::WebSocketEventInterface::SSLErrorCallbacks> callbacks_;
base::WeakPtrFactory<Delegate> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(Delegate);
};
......
......@@ -8,7 +8,6 @@
#include <vector>
#include "base/containers/unique_ptr_adapters.h"
#include "base/memory/weak_ptr.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "services/network/public/mojom/websocket.mojom.h"
#include "services/network/websocket.h"
......@@ -22,8 +21,7 @@ namespace network {
class NetworkContext;
// TODO(yhirano): Implement throttling.
class WebSocketFactory final : public base::SupportsWeakPtr<WebSocketFactory> {
class WebSocketFactory final {
public:
explicit WebSocketFactory(NetworkContext* context);
~WebSocketFactory();
......
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