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 #ifndef CHROME_CHROME_CLEANER_ENGINES_BROKER_ENGINE_REQUESTS_IMPL_H_
6 #define CHROME_CHROME_CLEANER_ENGINES_BROKER_ENGINE_REQUESTS_IMPL_H_
7 
8 #include <string>
9 #include <vector>
10 
11 #include "base/process/process_handle.h"
12 #include "chrome/chrome_cleaner/engines/broker/interface_metadata_observer.h"
13 #include "chrome/chrome_cleaner/ipc/mojo_task_runner.h"
14 #include "chrome/chrome_cleaner/mojom/engine_requests.mojom.h"
15 #include "chrome/chrome_cleaner/strings/wstring_embedded_nulls.h"
16 #include "mojo/public/cpp/bindings/associated_receiver.h"
17 #include "mojo/public/cpp/bindings/pending_associated_remote.h"
18 
19 namespace chrome_cleaner {
20 
21 class EngineRequestsImpl : public mojom::EngineRequests {
22  public:
23   EngineRequestsImpl(scoped_refptr<MojoTaskRunner> mojo_task_runner,
24                      InterfaceMetadataObserver* metadata_observer = nullptr);
25   ~EngineRequestsImpl() override;
26 
27   void Bind(mojo::PendingAssociatedRemote<mojom::EngineRequests>* remote);
28 
29   // mojom::EngineRequests
30   void SandboxGetFileAttributes(
31       const base::FilePath& file_name,
32       SandboxGetFileAttributesCallback result_callback) override;
33   void SandboxGetKnownFolderPath(
34       mojom::KnownFolder folder_id,
35       SandboxGetKnownFolderPathCallback result_callback) override;
36   void SandboxGetProcesses(
37       SandboxGetProcessesCallback result_callback) override;
38   void SandboxGetTasks(SandboxGetTasksCallback result_callback) override;
39   void SandboxGetProcessImagePath(
40       base::ProcessId pid,
41       SandboxGetProcessImagePathCallback result_callback) override;
42   void SandboxGetLoadedModules(
43       base::ProcessId pid,
44       SandboxGetLoadedModulesCallback result_callback) override;
45   void SandboxGetProcessCommandLine(
46       base::ProcessId pid,
47       SandboxGetProcessCommandLineCallback result_callback) override;
48   void SandboxGetUserInfoFromSID(
49       mojom::StringSidPtr string_sid,
50       SandboxGetUserInfoFromSIDCallback result_callback) override;
51   void SandboxOpenReadOnlyRegistry(
52       HANDLE root_key_handle,
53       const std::wstring& sub_key,
54       uint32_t dw_access,
55       SandboxOpenReadOnlyRegistryCallback result_callback) override;
56   void SandboxNtOpenReadOnlyRegistry(
57       HANDLE root_key_handle,
58       const WStringEmbeddedNulls& sub_key,
59       uint32_t dw_access,
60       SandboxNtOpenReadOnlyRegistryCallback result_callback) override;
61 
62  private:
63   void GetFileAttributes(const base::FilePath& file_name,
64                          SandboxGetFileAttributesCallback result_callback);
65   void GetKnownFolderPath(mojom::KnownFolder folder_id,
66                           SandboxGetKnownFolderPathCallback result_callback);
67   void GetProcesses(SandboxGetProcessesCallback result_callback);
68   void GetTasks(SandboxGetTasksCallback result_callback);
69   void GetProcessImagePath(base::ProcessId pid,
70                            SandboxGetProcessImagePathCallback result_callback);
71   void GetLoadedModules(base::ProcessId pid,
72                         SandboxGetLoadedModulesCallback result_callback);
73   void GetProcessCommandLine(
74       base::ProcessId pid,
75       SandboxGetProcessCommandLineCallback result_callback);
76   void GetUserInfoFromSID(mojom::StringSidPtr string_sid,
77                           SandboxGetUserInfoFromSIDCallback result_callback);
78   void OpenReadOnlyRegistry(
79       HANDLE root_key_handle,
80       const std::wstring& sub_key,
81       uint32_t dw_access,
82       SandboxOpenReadOnlyRegistryCallback result_callback);
83   void NtOpenReadOnlyRegistry(
84       HANDLE root_key_handle,
85       const WStringEmbeddedNulls& sub_key,
86       uint32_t dw_access,
87       SandboxNtOpenReadOnlyRegistryCallback result_callback);
88 
89   scoped_refptr<MojoTaskRunner> mojo_task_runner_;
90   InterfaceMetadataObserver* metadata_observer_ = nullptr;
91   mojo::AssociatedReceiver<mojom::EngineRequests> receiver_{this};
92 };
93 
94 }  // namespace chrome_cleaner
95 
96 #endif  // CHROME_CHROME_CLEANER_ENGINES_BROKER_ENGINE_REQUESTS_IMPL_H_
97