1 // Copyright 2019 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 "components/services/unzip/content/unzip_service.h"
6 
7 #include "base/no_destructor.h"
8 #include "components/strings/grit/components_strings.h"
9 #include "content/public/browser/service_process_host.h"
10 
11 namespace unzip {
12 
13 namespace {
14 
GetLaunchOverride()15 LaunchCallback& GetLaunchOverride() {
16   static base::NoDestructor<LaunchCallback> callback;
17   return *callback;
18 }
19 
20 }  // namespace
21 
LaunchUnzipper()22 mojo::PendingRemote<mojom::Unzipper> LaunchUnzipper() {
23   auto& launcher = GetLaunchOverride();
24   if (launcher)
25     return launcher.Run();
26 
27   mojo::PendingRemote<mojom::Unzipper> remote;
28   content::ServiceProcessHost::Launch<mojom::Unzipper>(
29       remote.InitWithNewPipeAndPassReceiver(),
30       content::ServiceProcessHost::Options()
31           .WithSandboxType(service_manager::SandboxType::kUtility)
32           .WithDisplayName(IDS_UNZIP_SERVICE_DISPLAY_NAME)
33           .Pass());
34   return remote;
35 }
36 
SetUnzipperLaunchOverrideForTesting(LaunchCallback callback)37 void SetUnzipperLaunchOverrideForTesting(LaunchCallback callback) {
38   GetLaunchOverride() = std::move(callback);
39 }
40 
41 }  //  namespace unzip
42