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

Side by Side Diff: extensions/browser/mojo/service_registration_manager.cc

Issue 919943002: Remove extensions::ServiceRegistrationManager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 10 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 unified diff | Download patch
« no previous file with comments | « extensions/browser/mojo/service_registration_manager.h ('k') | extensions/extensions.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "extensions/browser/mojo/service_registration_manager.h"
6
7 #include "base/command_line.h"
8 #include "base/lazy_instance.h"
9 #include "content/public/browser/browser_thread.h"
10 #include "content/public/browser/render_frame_host.h"
11 #include "content/public/browser/render_process_host.h"
12 #include "content/public/browser/site_instance.h"
13 #include "device/serial/serial_service_impl.h"
14 #include "extensions/browser/extension_registry.h"
15 #include "extensions/browser/process_map.h"
16 #include "extensions/common/constants.h"
17 #include "extensions/common/extension_api.h"
18 #include "extensions/common/switches.h"
19
20 namespace extensions {
21 namespace {
22
23 base::LazyInstance<ServiceRegistrationManager> g_lazy_instance =
24 LAZY_INSTANCE_INITIALIZER;
25
26 ServiceRegistrationManager* g_test_instance = nullptr;
27
28 } // namespace
29
30 ServiceRegistrationManager::ServiceRegistrationManager() {
31 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
32 switches::kEnableMojoSerialService)) {
33 AddServiceFactory(
34 "serial",
35 base::Bind(device::SerialServiceImpl::CreateOnMessageLoop,
36 content::BrowserThread::GetMessageLoopProxyForThread(
37 content::BrowserThread::FILE),
38 content::BrowserThread::GetMessageLoopProxyForThread(
39 content::BrowserThread::IO),
40 content::BrowserThread::GetMessageLoopProxyForThread(
41 content::BrowserThread::UI)));
42 }
43 }
44
45 ServiceRegistrationManager::~ServiceRegistrationManager() {
46 }
47
48 ServiceRegistrationManager* ServiceRegistrationManager::GetSharedInstance() {
49 if (g_test_instance)
50 return g_test_instance;
51 return g_lazy_instance.Pointer();
52 }
53
54 void ServiceRegistrationManager::AddServicesToRenderFrame(
55 content::RenderFrameHost* render_frame_host) {
56 content::BrowserContext* context =
57 render_frame_host->GetProcess()->GetBrowserContext();
58 content::SiteInstance* site_instance = render_frame_host->GetSiteInstance();
59 GURL extension_url = site_instance->GetSiteURL();
60 ExtensionRegistry* registry = ExtensionRegistry::Get(context);
61
62 // TODO(sammc): Handle content scripts and web pages that have access to some
63 // extension APIs.
64 if (!extension_url.SchemeIs(kExtensionScheme)) {
65 return;
66 }
67
68 const Extension* extension =
69 registry->enabled_extensions().GetByID(extension_url.host());
70 if (!extension)
71 return;
72
73 Feature::Context context_type =
74 ProcessMap::Get(context)->GetMostLikelyContextType(
75 extension, render_frame_host->GetProcess()->GetID());
76 for (const auto& factory : factories_) {
77 auto availability = ExtensionAPI::GetSharedInstance()->IsAvailable(
78 factory.first, extension, context_type, extension_url);
79 if (availability.is_available()) {
80 AddServiceToServiceRegistry(render_frame_host->GetServiceRegistry(),
81 factory.second.get());
82 }
83 }
84 }
85
86 void ServiceRegistrationManager::AddServiceToServiceRegistry(
87 content::ServiceRegistry* service_registry,
88 internal::ServiceFactoryBase* factory) {
89 factory->Register(service_registry);
90 }
91
92 // static
93 void ServiceRegistrationManager::SetServiceRegistrationManagerForTest(
94 ServiceRegistrationManager* service_registration_manager) {
95 g_test_instance = service_registration_manager;
96 }
97
98 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/mojo/service_registration_manager.h ('k') | extensions/extensions.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698