Skip to content

Commit

Permalink
[extensions] Move ChannelDelegate and PortId into base class.
Browse files Browse the repository at this point in the history
Move some members that will be useful when porting extension messaging
to mojo into the base class.

Bug: 993189
Change-Id: Ia3bd8cf22f5c7693d341893334d362250a8cd0ae
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4935296
Reviewed-by: Reilly Grant <reillyg@chromium.org>
Commit-Queue: Dave Tapuska <dtapuska@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1209451}
  • Loading branch information
dtapuska authored and Chromium LUCI CQ committed Oct 13, 2023
1 parent a16439a commit 1cba116
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,8 @@ NativeMessagePort::NativeMessagePort(
base::WeakPtr<ChannelDelegate> channel_delegate,
const PortId& port_id,
std::unique_ptr<NativeMessageHost> native_message_host)
: weak_channel_delegate_(channel_delegate),
host_task_runner_(native_message_host->task_runner()),
port_id_(port_id) {
: MessagePort(std::move(channel_delegate), port_id),
host_task_runner_(native_message_host->task_runner()) {
core_ = std::make_unique<Core>(
std::move(native_message_host), weak_factory_.GetWeakPtr(),
base::SingleThreadTaskRunner::GetCurrentDefault());
Expand Down
2 changes: 0 additions & 2 deletions chrome/browser/extensions/api/messaging/native_message_port.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ class NativeMessagePort : public MessagePort {
void CloseChannel(const std::string& error_message);

base::ThreadChecker thread_checker_;
base::WeakPtr<ChannelDelegate> weak_channel_delegate_;
scoped_refptr<base::SingleThreadTaskRunner> host_task_runner_;
const PortId port_id_;
std::unique_ptr<Core> core_;

base::WeakPtrFactory<NativeMessagePort> weak_factory_{this};
Expand Down
6 changes: 2 additions & 4 deletions extensions/browser/api/messaging/extension_message_port.cc
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,7 @@ ExtensionMessagePort::ExtensionMessagePort(
const std::string& extension_id,
content::RenderFrameHost* render_frame_host,
bool include_child_frames)
: weak_channel_delegate_(channel_delegate),
port_id_(port_id),
: MessagePort(std::move(channel_delegate), port_id),
extension_id_(extension_id),
browser_context_(render_frame_host->GetProcess()->GetBrowserContext()),
frame_tracker_(new FrameTracker(this)) {
Expand Down Expand Up @@ -232,8 +231,7 @@ ExtensionMessagePort::ExtensionMessagePort(
const ExtensionId& extension_id,
content::BrowserContext* browser_context,
PassKey)
: weak_channel_delegate_(channel_delegate),
port_id_(port_id),
: MessagePort(std::move(channel_delegate), port_id),
extension_id_(extension_id),
browser_context_(browser_context) {}

Expand Down
2 changes: 0 additions & 2 deletions extensions/browser/api/messaging/extension_message_port.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,7 @@ class ExtensionMessagePort : public MessagePort {
// alive.
bool IsServiceWorkerActivity(Activity::Type activity_type);

base::WeakPtr<ChannelDelegate> weak_channel_delegate_;

const PortId port_id_;
ExtensionId extension_id_;
raw_ptr<content::BrowserContext> browser_context_ = nullptr;

Expand Down
5 changes: 4 additions & 1 deletion extensions/browser/api/messaging/message_port.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@

namespace extensions {

MessagePort::MessagePort() = default;
MessagePort::MessagePort(base::WeakPtr<ChannelDelegate> channel_delegate,
const PortId& port_id)
: weak_channel_delegate_(channel_delegate), port_id_(port_id) {}

MessagePort::~MessagePort() = default;

void MessagePort::RemoveCommonFrames(const MessagePort& port) {}
Expand Down
8 changes: 7 additions & 1 deletion extensions/browser/api/messaging/message_port.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@

#include <string>

#include "base/memory/weak_ptr.h"
#include "base/values.h"
#include "extensions/browser/activity.h"
#include "extensions/browser/extension_api_frame_id_map.h"
#include "extensions/common/api/messaging/port_id.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "url/origin.h"

Expand All @@ -23,7 +25,6 @@ namespace extensions {
enum class ChannelType;
struct Message;
struct MessagingEndpoint;
struct PortId;
struct PortContext;

// One side of the communication handled by extensions::MessageService.
Expand All @@ -42,6 +43,8 @@ class MessagePort {
virtual void PostMessage(const PortId& port_id, const Message& message) = 0;
};

explicit MessagePort(base::WeakPtr<ChannelDelegate> channel_delegate,
const PortId& port_id);
MessagePort(const MessagePort&) = delete;
MessagePort& operator=(const MessagePort&) = delete;

Expand Down Expand Up @@ -114,6 +117,9 @@ class MessagePort {
protected:
MessagePort();

base::WeakPtr<ChannelDelegate> weak_channel_delegate_;
const PortId port_id_;

private:
// This port should keep the service worker alive while it is open.
bool should_have_strong_keepalive_ = false;
Expand Down

0 comments on commit 1cba116

Please sign in to comment.