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

Unified Diff: chrome/browser/extensions/api/messaging/extension_message_port.cc

Issue 10818013: Native Messaging! (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: MultiPlatform and UnitTest! Created 8 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/extensions/api/messaging/extension_message_port.cc
diff --git a/chrome/browser/extensions/api/messaging/extension_message_port.cc b/chrome/browser/extensions/api/messaging/extension_message_port.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f391775af9e856cdd34f5247eacd81aa9fe899fd
--- /dev/null
+++ b/chrome/browser/extensions/api/messaging/extension_message_port.cc
@@ -0,0 +1,72 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/extensions/api/messaging/extension_message_port.h"
+
+#include "chrome/browser/extensions/extension_host.h"
+#include "chrome/browser/extensions/extension_process_manager.h"
+#include "chrome/browser/extensions/extension_system.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/common/extensions/extension_messages.h"
+#include "content/public/browser/render_process_host.h"
+
+namespace extensions {
+
+ExtensionMessagePort::ExtensionMessagePort(content::RenderProcessHost* process,
+ int routing_id,
+ const std::string& extension_id)
+ : process_(process),
+ routing_id_(routing_id),
+ extension_id_(extension_id),
+ background_host_ptr_(NULL) {
+}
+
+void ExtensionMessagePort::DispatchOnConnect(
+ int dest_port_id,
+ const std::string& channel_name,
+ const std::string& tab_json,
+ const std::string& source_extension_id,
+ const std::string& target_extension_id) {
+ process_->Send(new ExtensionMsg_DispatchOnConnect(
+ routing_id_, dest_port_id, channel_name,
+ tab_json, source_extension_id, target_extension_id));
+}
+
+void ExtensionMessagePort::DispatchOnDisconnect(int source_port_id,
+ bool connection_error) {
+ process_->Send(new ExtensionMsg_DispatchOnDisconnect(
+ routing_id_, source_port_id, connection_error));
+}
+
+void ExtensionMessagePort::DispatchOnMessage(const std::string& message,
+ int target_port_id) {
+ process_->Send(new ExtensionMsg_DeliverMessage(
+ routing_id_, target_port_id, message));
+}
+
+void ExtensionMessagePort::IncrementLazyKeepaliveCount() {
+ Profile* profile =
+ Profile::FromBrowserContext(process_->GetBrowserContext());
+ ExtensionProcessManager* pm =
+ ExtensionSystem::Get(profile)->process_manager();
+ ExtensionHost* host = pm->GetBackgroundHostForExtension(extension_id_);
+ if (host && host->extension()->has_lazy_background_page())
+ pm->IncrementLazyKeepaliveCount(host->extension());
+
+ // Keep track of the background host, so when we decrement, we only do so if
+ // the host hasn't reloaded.
+ background_host_ptr_ = host;
+}
+
+void ExtensionMessagePort::DecrementLazyKeepaliveCount() {
+ Profile* profile =
+ Profile::FromBrowserContext(process_->GetBrowserContext());
+ ExtensionProcessManager* pm =
+ ExtensionSystem::Get(profile)->process_manager();
+ ExtensionHost* host = pm->GetBackgroundHostForExtension(extension_id_);
+ if (host && host == background_host_ptr_)
+ pm->DecrementLazyKeepaliveCount(host->extension());
+}
+
+} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698