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

Unified Diff: extensions/browser/mojo/service_registration_manager.cc

Issue 652793002: Add service registration for apps APIs implemented as mojo services. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: extensions/browser/mojo Created 6 years, 2 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: extensions/browser/mojo/service_registration_manager.cc
diff --git a/extensions/browser/mojo/service_registration_manager.cc b/extensions/browser/mojo/service_registration_manager.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d08bb14a0309a5d849a829b0378326c2bf015e5a
--- /dev/null
+++ b/extensions/browser/mojo/service_registration_manager.cc
@@ -0,0 +1,81 @@
+// Copyright 2014 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 "extensions/browser/mojo/service_registration_manager.h"
+
+#include "base/command_line.h"
+#include "base/lazy_instance.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/render_frame_host.h"
+#include "content/public/browser/render_process_host.h"
+#include "content/public/browser/site_instance.h"
+#include "device/serial/serial_service_impl.h"
+#include "extensions/browser/extension_registry.h"
+#include "extensions/browser/process_map.h"
+#include "extensions/common/constants.h"
+#include "extensions/common/extension_api.h"
+#include "extensions/common/switches.h"
+
+namespace extensions {
+namespace {
+
+base::LazyInstance<ServiceRegistrationManager> g_lazy_instance =
+ LAZY_INSTANCE_INITIALIZER;
+
+} // namespace
+
+ServiceRegistrationManager::ServiceRegistrationManager() {
+ if (base::CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kEnableMojoSerialService)) {
+ AddServiceFactory(
+ "serial",
+ base::Bind(device::SerialServiceImpl::CreateOnMessageLoop,
+ content::BrowserThread::GetMessageLoopProxyForThread(
+ content::BrowserThread::FILE),
+ content::BrowserThread::GetMessageLoopProxyForThread(
+ content::BrowserThread::IO),
+ content::BrowserThread::GetMessageLoopProxyForThread(
+ content::BrowserThread::UI)));
+ }
+}
+
+ServiceRegistrationManager::~ServiceRegistrationManager() {
+}
+
+ServiceRegistrationManager* ServiceRegistrationManager::GetSharedInstance() {
+ return g_lazy_instance.Pointer();
+}
+
+void ServiceRegistrationManager::AddServicesToRenderFrame(
+ content::RenderFrameHost* render_frame_host) {
+ content::BrowserContext* context =
+ render_frame_host->GetProcess()->GetBrowserContext();
+ content::SiteInstance* site_instance = render_frame_host->GetSiteInstance();
+ GURL extension_url = site_instance->GetSiteURL();
+ ExtensionRegistry* registry = ExtensionRegistry::Get(context);
+
+ // TODO(sammc): Handle content scripts and web pages that have access to some
+ // extension APIs.
+ if (!extension_url.SchemeIs(kExtensionScheme)) {
+ return;
+ }
+
+ const Extension* extension =
+ registry->enabled_extensions().GetByID(extension_url.host());
+ if (!extension)
+ return;
+
+ Feature::Context context_type =
+ ProcessMap::Get(context)->GetMostLikelyContextType(
+ extension, render_frame_host->GetProcess()->GetID());
+ for (const auto& factory : factories_) {
+ if (ExtensionAPI::GetSharedInstance()
+ ->IsAvailable(factory.first, extension, context_type, extension_url)
+ .is_available()) {
raymes 2014/10/23 22:12:56 nit: can we pull this out of the if-statement to m
Sam McNally 2014/10/23 23:31:17 Done.
+ factory.second->Register(render_frame_host->GetServiceRegistry());
+ }
+ }
+}
+
+} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698