Commit bf678987 authored by nhiroki's avatar nhiroki Committed by Commit bot

SharedWorker: Clarify that SharedWorkerRepository is owned by RenderFrameImpl

Before this CL, SharedWorkerRepository is implicitly owned by RenderFrameImpl.
It's created when RenderFrameImpl is initialized and destructed on
RenderFrameObserver::OnDestruct called from the dtor of RenderFrameImpl. This
looks confusing.

After this CL, RenderFrameImpl explicitly owns SharedWorkerRepository as its
member field. This should not change behavior.

BUG=612308

Review-Url: https://codereview.chromium.org/2600163002
Cr-Commit-Position: refs/heads/master@{#440734}
parent 84f686de
......@@ -1237,7 +1237,9 @@ void RenderFrameImpl::Initialize() {
#if BUILDFLAG(ENABLE_PLUGINS)
new PepperBrowserConnection(this);
#endif
new SharedWorkerRepository(this);
shared_worker_repository_ = base::MakeUnique<SharedWorkerRepository>(this);
GetWebFrame()->setSharedWorkerRepositoryClient(
shared_worker_repository_.get());
if (IsLocalRoot()) {
// DevToolsAgent is a RenderFrameObserver, and will destruct itself
......
......@@ -149,6 +149,7 @@ class RenderWidget;
class RenderWidgetFullscreenPepper;
class ResourceRequestBodyImpl;
class ScreenOrientationDispatcher;
class SharedWorkerRepository;
class UserMediaClientImpl;
struct CommonNavigationParams;
struct CustomContextMenuContext;
......@@ -1321,6 +1322,7 @@ class CONTENT_EXPORT RenderFrameImpl
#endif
std::unique_ptr<FrameBlameContext> blame_context_;
std::unique_ptr<SharedWorkerRepository> shared_worker_repository_;
// Plugins -------------------------------------------------------------------
#if BUILDFLAG(ENABLE_PLUGINS)
......
......@@ -8,17 +8,13 @@
#include "content/common/view_messages.h"
#include "content/renderer/render_frame_impl.h"
#include "content/renderer/websharedworker_proxy.h"
#include "third_party/WebKit/public/web/WebContentSecurityPolicy.h"
#include "third_party/WebKit/public/web/WebLocalFrame.h"
namespace content {
SharedWorkerRepository::SharedWorkerRepository(RenderFrameImpl* render_frame)
: RenderFrameObserver(render_frame) {
render_frame->GetWebFrame()->setSharedWorkerRepositoryClient(this);
}
: render_frame_(render_frame){};
SharedWorkerRepository::~SharedWorkerRepository() {}
SharedWorkerRepository::~SharedWorkerRepository() = default;
std::unique_ptr<blink::WebSharedWorkerConnector>
SharedWorkerRepository::createSharedWorkerConnector(
......@@ -36,11 +32,11 @@ SharedWorkerRepository::createSharedWorkerConnector(
params.content_security_policy = content_security_policy.utf16();
params.security_policy_type = security_policy_type;
params.document_id = document_id;
params.render_frame_route_id = render_frame()->GetRoutingID();
params.render_frame_route_id = render_frame_->GetRoutingID();
params.creation_address_space = creation_address_space;
params.creation_context_type = creation_context_type;
ViewHostMsg_CreateWorker_Reply reply;
Send(new ViewHostMsg_CreateWorker(params, &reply));
render_frame_->Send(new ViewHostMsg_CreateWorker(params, &reply));
*error = reply.error;
documents_with_workers_.insert(document_id);
return base::MakeUnique<WebSharedWorkerProxy>(
......@@ -51,13 +47,9 @@ void SharedWorkerRepository::documentDetached(DocumentID document) {
std::set<DocumentID>::iterator iter = documents_with_workers_.find(document);
if (iter != documents_with_workers_.end()) {
// Notify the browser process that the document has shut down.
Send(new ViewHostMsg_DocumentDetached(document));
render_frame_->Send(new ViewHostMsg_DocumentDetached(document));
documents_with_workers_.erase(iter);
}
}
void SharedWorkerRepository::OnDestruct() {
delete this;
}
} // namespace content
......@@ -9,7 +9,6 @@
#include <set>
#include "base/macros.h"
#include "content/public/renderer/render_frame_observer.h"
#include "third_party/WebKit/public/platform/WebAddressSpace.h"
#include "third_party/WebKit/public/web/WebContentSecurityPolicy.h"
#include "third_party/WebKit/public/web/WebSharedWorkerCreationContextType.h"
......@@ -19,11 +18,11 @@ namespace content {
class RenderFrameImpl;
class SharedWorkerRepository : public RenderFrameObserver,
public blink::WebSharedWorkerRepositoryClient {
class SharedWorkerRepository final
: public blink::WebSharedWorkerRepositoryClient {
public:
explicit SharedWorkerRepository(RenderFrameImpl* render_frame);
~SharedWorkerRepository() override;
~SharedWorkerRepository();
// WebSharedWorkerRepositoryClient overrides.
std::unique_ptr<blink::WebSharedWorkerConnector> createSharedWorkerConnector(
......@@ -38,9 +37,7 @@ class SharedWorkerRepository : public RenderFrameObserver,
void documentDetached(DocumentID document_id) override;
private:
// RenderFrameObserver implementation.
void OnDestruct() override;
RenderFrameImpl* render_frame_;
std::set<DocumentID> documents_with_workers_;
DISALLOW_COPY_AND_ASSIGN(SharedWorkerRepository);
......
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