Skip to content

Commit

Permalink
CupsProxyService boilerplate
Browse files Browse the repository at this point in the history
DDoc: go/cups-plugin

This sets up the CupsProxy Chrome Service. This service is a singleton, managed
by the ServiceManager and lives in the browser process. The service is currently
started with the Profile; there will be future work to lazily initiate it on first
printing request. Service implementation (ProxyManager) landing in following CL.

Bug: chromium:945409
Test: Builds succeed + service unused so far. Unittests + tast tests landing in future CLs.

Change-Id: I1257f32dbff8a3bdbd5690651b7ccba9e693eb23
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1547813
Reviewed-by: Lei Zhang <thestig@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Ken Rockot <rockot@google.com>
Commit-Queue: Luum Habtemariam <luum@chromium.org>
Cr-Commit-Position: refs/heads/master@{#653723}
  • Loading branch information
Luum Habtemariam authored and Commit Bot committed Apr 24, 2019
1 parent 5f9118b commit c295b4e
Show file tree
Hide file tree
Showing 17 changed files with 261 additions and 0 deletions.
1 change: 1 addition & 0 deletions chrome/app/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,7 @@ source_set("chrome_packaged_service_manifests") {
"//ash/public/cpp:manifest",
"//chrome/browser/chromeos:ash_pref_connector_manifest",
"//chrome/services/cups_ipp_parser/public/cpp:manifest",
"//chrome/services/cups_proxy/public/cpp:manifest",
"//chromeos/services/cellular_setup/public/cpp:manifest",
"//chromeos/services/ime/public/cpp:manifest",
"//chromeos/services/secure_channel/public/cpp:manifest",
Expand Down
1 change: 1 addition & 0 deletions chrome/app/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ specific_include_rules = {
"+ash/components/shortcut_viewer/public",
"+ash/components/tap_visualizer/public",
"+chrome/services/cups_ipp_parser/public",
"+chrome/services/cups_proxy/public",
"+chrome/services/file_util/public",
"+chrome/services/isolated_xr_device/manifest.h",
"+chrome/services/media_gallery_util/public",
Expand Down
2 changes: 2 additions & 0 deletions chrome/app/chrome_packaged_service_manifests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "ash/public/cpp/manifest.h"
#include "chrome/browser/chromeos/prefs/ash_pref_connector_manifest.h"
#include "chrome/services/cups_ipp_parser/public/cpp/manifest.h" // nogncheck
#include "chrome/services/cups_proxy/public/cpp/manifest.h"
#include "chromeos/services/cellular_setup/public/cpp/manifest.h"
#include "chromeos/services/ime/public/cpp/manifest.h"
#include "chromeos/services/secure_channel/public/cpp/manifest.h"
Expand Down Expand Up @@ -171,6 +172,7 @@ GetChromePackagedServiceManifests() {
GetAshPrefConnectorManifest(),
GetCupsIppParserManifest(),
chromeos::cellular_setup::GetManifest(),
chromeos::printing::GetCupsProxyManifest(),
chromeos::ime::GetManifest(),
chromeos::secure_channel::GetManifest(),
ui::GetAXHostManifest(),
Expand Down
1 change: 1 addition & 0 deletions chrome/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -3459,6 +3459,7 @@ jumbo_split_static_library("browser") {
"//ash/public/cpp",
"//chrome/browser/chromeos",
"//chrome/browser/chromeos/kiosk_next_home/mojom",
"//chrome/services/cups_proxy",
"//chromeos/services/assistant/public:feature_flags",
"//chromeos/services/cellular_setup",
"//chromeos/services/device_sync",
Expand Down
1 change: 1 addition & 0 deletions chrome/browser/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ include_rules = [
"+chrome/notification_helper/notification_helper_constants.h",
"+chrome/services/app_service/public/mojom",
"+chrome/services/cups_ipp_parser/public",
"+chrome/services/cups_proxy",
"+chrome/services/diagnosticsd/public",
"+chrome/services/file_util/public",
"+chrome/services/media_gallery_util/public",
Expand Down
9 changes: 9 additions & 0 deletions chrome/browser/chrome_content_browser_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,8 @@
#include "chrome/browser/ui/ash/chrome_browser_main_extra_parts_ash.h"
#include "chrome/browser/ui/ash/tablet_mode_client.h"
#include "chrome/browser/ui/browser_dialogs.h"
#include "chrome/services/cups_proxy/cups_proxy_service.h"
#include "chrome/services/cups_proxy/public/mojom/constants.mojom.h"
#include "chromeos/constants/chromeos_constants.h"
#include "chromeos/constants/chromeos_features.h"
#include "chromeos/constants/chromeos_switches.h"
Expand Down Expand Up @@ -598,6 +600,7 @@
#endif

#if BUILDFLAG(ENABLE_PRINTING) && defined(OS_CHROMEOS)
// TODO(crbug.com/948800): Doesn't match BUILD.gn of use_cups && is_chromeos.
#include "chrome/services/cups_ipp_parser/public/mojom/constants.mojom.h"
#endif

Expand Down Expand Up @@ -4033,6 +4036,12 @@ void ChromeContentBrowserClient::HandleServiceRequest(
std::move(request)));
}

if (service_name == chromeos::printing::mojom::kCupsProxyServiceName) {
service_manager::Service::RunAsyncUntilTermination(
std::make_unique<chromeos::printing::CupsProxyService>(
std::move(request)));
}

auto service = ash_service_registry::HandleServiceRequest(service_name,
std::move(request));
if (service)
Expand Down
34 changes: 34 additions & 0 deletions chrome/services/cups_proxy/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright 2019 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.

import("//build/config/features.gni")
import("//printing/buildflags/buildflags.gni")

assert(is_chromeos,
"Non-Chrome-OS builds must not depend on //chrome/services/cups_proxy")

source_set("cups_proxy") {
sources = [
"cups_proxy_service.cpp",
"cups_proxy_service.h",
]

deps = [
"//base",
"//chrome/services/cups_proxy/public/mojom",
"//chromeos/dbus",
"//net",
"//services/service_manager/public/cpp",
"//services/service_manager/public/mojom",
]

# We stub this service if libCUPS is not present.
if (use_cups) {
configs += [ "//printing:cups" ]
}

public_deps = [
"//printing",
]
}
7 changes: 7 additions & 0 deletions chrome/services/cups_proxy/OWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
luum@chromium.org
skau@chromium.org

per-file manifest.cc=set noparent
per-file manifest.cc=file://ipc/SECURITY_OWNERS
per-file manifest.h=set noparent
per-file manifest.h=file://ipc/SECURITY_OWNERS
42 changes: 42 additions & 0 deletions chrome/services/cups_proxy/cups_proxy_service.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright 2019 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/services/cups_proxy/cups_proxy_service.h"

#include <string>
#include <utility>
#include <vector>

namespace chromeos {
namespace printing {

CupsProxyService::CupsProxyService(
service_manager::mojom::ServiceRequest request)
: service_binding_(this, std::move(request)) {}

CupsProxyService::~CupsProxyService() = default;

void CupsProxyService::OnStart() {
BindToCupsProxyDaemon();
}

void CupsProxyService::OnConnect(
const service_manager::BindSourceInfo& source_info,
const std::string& interface_name,
mojo::ScopedMessagePipeHandle interface_pipe) {
DLOG(WARNING) << "CupsProxyService incorrectly received interface_request";
}

void CupsProxyService::BindToCupsProxyDaemon() {
// TODO(crbug.com/945409): Implement this.
}

void CupsProxyService::OnBindToCupsProxyDaemon(const bool success) {
if (!success) {
DLOG(WARNING) << "CupsProxyDaemonConnection bootstrap failed";
}
}

} // namespace printing
} // namespace chromeos
59 changes: 59 additions & 0 deletions chrome/services/cups_proxy/cups_proxy_service.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright 2019 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.

#ifndef CHROME_SERVICES_CUPS_PROXY_CUPS_PROXY_SERVICE_H_
#define CHROME_SERVICES_CUPS_PROXY_CUPS_PROXY_SERVICE_H_

#include <memory>
#include <string>

#include "mojo/public/cpp/bindings/binding_set.h"
#include "services/service_manager/public/cpp/binder_registry.h"
#include "services/service_manager/public/cpp/service.h"
#include "services/service_manager/public/cpp/service_binding.h"
#include "services/service_manager/public/mojom/service.mojom.h"

namespace chromeos {
namespace printing {

// CupsProxy Service Implementation.
//
// Singleton Chrome Service managed by the ServiceManager and lives in the
// browser process. Lazily initializes mojom::CupsProxier handler,
// |proxy_manager_|, and handles binding all incoming
// mojom::CupsProxierRequest's to it.
//
// Note: Service lifetime is the same as Profile; there will be future work to
// lazily intiate it on first use.
class CupsProxyService : public service_manager::Service {
public:
explicit CupsProxyService(service_manager::mojom::ServiceRequest request);
~CupsProxyService() override;

private:
// service_manager::Service override.
void OnStart() override;

// This method is stubbed since the only expected consumer of this service is
// a ChromeOS daemon; this connection is bootstrapped over D-Bus by the
// below binding methods.
void OnConnect(const service_manager::BindSourceInfo& source_info,
const std::string& interface_name,
mojo::ScopedMessagePipeHandle interface_pipe) override;

// Binds |proxy_manager| to a CupsProxierPtr and passes it to the
// CupsProxyDaemon. The binding is accomplished via D-Bus bootstrap.
void BindToCupsProxyDaemon();
void OnBindToCupsProxyDaemon(const bool success);

service_manager::ServiceBinding service_binding_;
service_manager::BinderRegistry binder_registry_;

DISALLOW_COPY_AND_ASSIGN(CupsProxyService);
};

} // namespace printing
} // namespace chromeos

#endif // CHROME_SERVICES_CUPS_PROXY_CUPS_PROXY_SERVICE_H_
21 changes: 21 additions & 0 deletions chrome/services/cups_proxy/public/cpp/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2019 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.

import("//build/config/features.gni")
import("//printing/buildflags/buildflags.gni")

assert(is_chromeos, "Non-Chrome-OS builds must not depend on this")

source_set("manifest") {
sources = [
"manifest.cc",
"manifest.h",
]

deps = [
"//base",
"//chrome/services/cups_proxy/public/mojom",
"//services/service_manager/public/cpp",
]
}
4 changes: 4 additions & 0 deletions chrome/services/cups_proxy/public/cpp/OWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
per-file manifest.cc=set noparent
per-file manifest.cc=file://ipc/SECURITY_OWNERS
per-file manifest.h=set noparent
per-file manifest.h=file://ipc/SECURITY_OWNERS
32 changes: 32 additions & 0 deletions chrome/services/cups_proxy/public/cpp/manifest.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2019 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/services/cups_proxy/public/cpp/manifest.h"

#include "base/no_destructor.h"
#include "chrome/services/cups_proxy/public/mojom/constants.mojom.h"
#include "services/service_manager/public/cpp/manifest_builder.h"

namespace chromeos {
namespace printing {

const service_manager::Manifest& GetCupsProxyManifest() {
static base::NoDestructor<service_manager::Manifest> manifest{
service_manager::ManifestBuilder()
.WithServiceName(mojom::kCupsProxyServiceName)
.WithDisplayName("CupsProxyService")
.WithOptions(service_manager::ManifestOptionsBuilder()
.WithSandboxType("utility")
.WithInstanceSharingPolicy(
service_manager::Manifest::
InstanceSharingPolicy::kSingleton)
.Build())
.ExposeCapability(mojom::kCupsProxierCapability,
service_manager::Manifest::InterfaceList<>())
.Build()};
return *manifest;
}

} // namespace printing
} // namespace chromeos
18 changes: 18 additions & 0 deletions chrome/services/cups_proxy/public/cpp/manifest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2019 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.

#ifndef CHROME_SERVICES_CUPS_PROXY_PUBLIC_CPP_MANIFEST_H_
#define CHROME_SERVICES_CUPS_PROXY_PUBLIC_CPP_MANIFEST_H_

#include "services/service_manager/public/cpp/manifest.h"

namespace chromeos {
namespace printing {

const service_manager::Manifest& GetCupsProxyManifest();

} // namespace printing
} // namespace chromeos

#endif // CHROME_SERVICES_CUPS_PROXY_PUBLIC_CPP_MANIFEST_H_
16 changes: 16 additions & 0 deletions chrome/services/cups_proxy/public/mojom/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2019 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.

import("//build/config/features.gni")
import("//mojo/public/tools/bindings/mojom.gni")

mojom("mojom") {
sources = [
"constants.mojom",
]

public_deps = [
"//mojo/public/mojom/base",
]
}
2 changes: 2 additions & 0 deletions chrome/services/cups_proxy/public/mojom/OWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
per-file *.mojom=set noparent
per-file *.mojom=file://ipc/SECURITY_OWNERS
11 changes: 11 additions & 0 deletions chrome/services/cups_proxy/public/mojom/constants.mojom
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright 2019 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.

module chromeos.printing.mojom;

// Service id.
const string kCupsProxyServiceName = "cups_proxy";

// IppProxier capability id.
const string kCupsProxierCapability = "cups_proxier";

0 comments on commit c295b4e

Please sign in to comment.