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

Side by Side Diff: chrome/browser/component_updater/component_patcher_operation_out_of_process.cc

Issue 2566053002: Convert utility process out-of-process file patching to mojo (Closed)
Patch Set: Fix linux_chromium_chromeos_ozone_rel_ng apply patch failure. Created 4 years 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/component_updater/component_patcher_operation_out_of_pr ocess.h" 5 #include "chrome/browser/component_updater/component_patcher_operation_out_of_pr ocess.h"
6 6
7 #include <memory> 7 #include <string>
8 #include <vector>
9 8
10 #include "base/bind.h" 9 #include "base/bind.h"
11 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/files/file.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/location.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/single_thread_task_runner.h" 14 #include "base/sequenced_task_runner.h"
15 #include "base/threading/thread_task_runner_handle.h" 15 #include "base/strings/string16.h"
16 #include "chrome/common/chrome_utility_messages.h"
17 #include "chrome/grit/generated_resources.h" 16 #include "chrome/grit/generated_resources.h"
18 #include "components/component_updater/component_updater_service.h" 17 #include "content/public/browser/utility_process_mojo_client.h"
19 #include "content/public/browser/browser_thread.h"
20 #include "content/public/browser/utility_process_host.h"
21 #include "content/public/browser/utility_process_host_client.h"
22 #include "courgette/courgette.h" 18 #include "courgette/courgette.h"
Sam McNally 2016/12/22 02:45:48 I think these can go.
Noel Gordon 2016/12/22 05:06:33 Done.
23 #include "courgette/third_party/bsdiff/bsdiff.h" 19 #include "courgette/third_party/bsdiff/bsdiff.h"
24 #include "ipc/ipc_message_macros.h"
25 #include "ui/base/l10n/l10n_util.h" 20 #include "ui/base/l10n/l10n_util.h"
26 21
27 namespace component_updater { 22 namespace component_updater {
28 23
29 class PatchHost : public content::UtilityProcessHostClient { 24 ChromeOutOfProcessPatcher::ChromeOutOfProcessPatcher() = default;
30 public:
31 PatchHost(base::Callback<void(int result)> callback,
32 scoped_refptr<base::SequencedTaskRunner> task_runner);
33 25
34 void StartProcess(std::unique_ptr<IPC::Message> message); 26 ChromeOutOfProcessPatcher::~ChromeOutOfProcessPatcher() = default;
35
36 private:
37 ~PatchHost() override;
38
39 void OnPatchFinished(int result);
40
41 // Overrides of content::UtilityProcessHostClient.
42 bool OnMessageReceived(const IPC::Message& message) override;
43
44 void OnProcessCrashed(int exit_code) override;
45
46 base::Callback<void(int result)> callback_;
47 scoped_refptr<base::SequencedTaskRunner> task_runner_;
48 };
49
50 PatchHost::PatchHost(base::Callback<void(int result)> callback,
51 scoped_refptr<base::SequencedTaskRunner> task_runner)
52 : callback_(callback), task_runner_(task_runner) {
53 }
54
55 PatchHost::~PatchHost() {
56 }
57
58 void PatchHost::StartProcess(std::unique_ptr<IPC::Message> message) {
59 // The DeltaUpdateOpPatchHost is not responsible for deleting the
60 // UtilityProcessHost object.
61 content::UtilityProcessHost* host = content::UtilityProcessHost::Create(
62 this, base::ThreadTaskRunnerHandle::Get().get());
63 host->SetName(l10n_util::GetStringUTF16(
64 IDS_UTILITY_PROCESS_COMPONENT_PATCHER_NAME));
65 host->Send(message.release());
66 }
67
68 bool PatchHost::OnMessageReceived(const IPC::Message& message) {
69 bool handled = true;
70 IPC_BEGIN_MESSAGE_MAP(PatchHost, message)
71 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_PatchFile_Finished, OnPatchFinished)
72 IPC_MESSAGE_UNHANDLED(handled = false)
73 IPC_END_MESSAGE_MAP()
74 return handled;
75 }
76
77 void PatchHost::OnPatchFinished(int result) {
78 if (task_runner_.get()) {
79 task_runner_->PostTask(FROM_HERE, base::Bind(callback_, result));
80 task_runner_ = NULL;
81 }
82 }
83
84 void PatchHost::OnProcessCrashed(int exit_code) {
85 if (task_runner_.get()) {
86 task_runner_->PostTask(FROM_HERE, base::Bind(callback_, -1));
87 task_runner_ = NULL;
88 }
89 }
90
91 ChromeOutOfProcessPatcher::ChromeOutOfProcessPatcher() {
92 }
93
94 ChromeOutOfProcessPatcher::~ChromeOutOfProcessPatcher() {
95 }
96 27
97 void ChromeOutOfProcessPatcher::Patch( 28 void ChromeOutOfProcessPatcher::Patch(
98 const std::string& operation, 29 const std::string& operation,
99 scoped_refptr<base::SequencedTaskRunner> task_runner, 30 scoped_refptr<base::SequencedTaskRunner> task_runner,
100 const base::FilePath& input_abs_path, 31 const base::FilePath& input_abs_path,
101 const base::FilePath& patch_abs_path, 32 const base::FilePath& patch_abs_path,
102 const base::FilePath& output_abs_path, 33 const base::FilePath& output_abs_path,
103 base::Callback<void(int result)> callback) { 34 base::Callback<void(int result)> callback) {
104 host_ = new PatchHost(callback, task_runner); 35 task_runner_ = task_runner;
Sam McNally 2016/12/22 02:45:48 DCHECK(!utility_process_mojo_client_) DCHECK(task_
Noel Gordon 2016/12/22 05:06:33 Done. And moved all DCHECK to here.
105 IPC::PlatformFileForTransit input = IPC::TakePlatformFileForTransit( 36 callback_ = callback;
106 base::File( 37
107 input_abs_path, base::File::FLAG_OPEN | base::File::FLAG_READ)); 38 const base::string16 utility_process_name =
108 IPC::PlatformFileForTransit patch = IPC::TakePlatformFileForTransit( 39 l10n_util::GetStringUTF16(IDS_UTILITY_PROCESS_COMPONENT_PATCHER_NAME);
109 base::File( 40
110 patch_abs_path, base::File::FLAG_OPEN | base::File::FLAG_READ)); 41 utility_process_mojo_client_.reset(
111 IPC::PlatformFileForTransit output = IPC::TakePlatformFileForTransit( 42 new content::UtilityProcessMojoClient<chrome::mojom::FilePatcher>(
112 base::File( 43 utility_process_name));
113 output_abs_path, 44 utility_process_mojo_client_->set_error_callback(
114 base::File::FLAG_CREATE | 45 base::Bind(&ChromeOutOfProcessPatcher::PatchDone, this, -1));
115 base::File::FLAG_WRITE | 46
116 base::File::FLAG_EXCLUSIVE_WRITE)); 47 utility_process_mojo_client_->Start(); // Start the utility process.
117 std::unique_ptr<IPC::Message> patch_message; 48
49 DCHECK(!input_abs_path.empty());
50 DCHECK(!patch_abs_path.empty());
51 DCHECK(!output_abs_path.empty());
52
53 base::File input_file(input_abs_path,
54 base::File::FLAG_OPEN | base::File::FLAG_READ);
55 base::File patch_file(patch_abs_path,
56 base::File::FLAG_OPEN | base::File::FLAG_READ);
57 base::File output_file(output_abs_path, base::File::FLAG_CREATE |
58 base::File::FLAG_WRITE |
59 base::File::FLAG_EXCLUSIVE_WRITE);
118 if (operation == update_client::kBsdiff) { 60 if (operation == update_client::kBsdiff) {
119 patch_message.reset(new ChromeUtilityMsg_PatchFileBsdiff( 61 utility_process_mojo_client_->service()->PatchFileBsdiff(
120 input, patch, output)); 62 std::move(input_file), std::move(patch_file), std::move(output_file),
63 base::Bind(&ChromeOutOfProcessPatcher::PatchDone, this));
121 } else if (operation == update_client::kCourgette) { 64 } else if (operation == update_client::kCourgette) {
122 patch_message.reset(new ChromeUtilityMsg_PatchFileCourgette( 65 utility_process_mojo_client_->service()->PatchFileCourgette(
123 input, patch, output)); 66 std::move(input_file), std::move(patch_file), std::move(output_file),
67 base::Bind(&ChromeOutOfProcessPatcher::PatchDone, this));
124 } else { 68 } else {
125 NOTREACHED(); 69 NOTREACHED();
126 } 70 }
71 }
127 72
128 content::BrowserThread::PostTask( 73 void ChromeOutOfProcessPatcher::PatchDone(int result) {
129 content::BrowserThread::IO, 74 utility_process_mojo_client_.reset(); // Terminate the utility process.
130 FROM_HERE, 75 if (task_runner_.get()) {
Sam McNally 2016/12/22 02:45:49 This shouldn't be necessary with utility_process_m
Noel Gordon 2016/12/22 05:06:33 Done.
131 base::Bind( 76 task_runner_->PostTask(FROM_HERE, base::Bind(callback_, result));
132 &PatchHost::StartProcess, host_, base::Passed(&patch_message))); 77 task_runner_ = nullptr;
78 }
133 } 79 }
134 80
135 } // namespace component_updater 81 } // namespace component_updater
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698