OLD | NEW |
---|---|
(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 "chrome/browser/component_updater/component_patcher_operation_out_of_pr ocess.h" | |
6 | |
7 #include <vector> | |
8 | |
9 #include "base/bind.h" | |
10 #include "chrome/browser/component_updater/component_updater_service.h" | |
11 #include "chrome/common/chrome_utility_messages.h" | |
12 #include "content/public/browser/browser_thread.h" | |
13 #include "content/public/browser/utility_process_host.h" | |
14 #include "content/public/browser/utility_process_host_client.h" | |
15 #include "courgette/courgette.h" | |
16 #include "courgette/third_party/bsdiff.h" | |
17 #include "ipc/ipc_message_macros.h" | |
18 | |
19 namespace component_updater { | |
20 | |
21 class DeltaUpdateOpPatchHost : public content::UtilityProcessHostClient { | |
waffles
2014/07/31 21:54:26
Can we move this to an anonymous namespace?
tommycli
2014/08/04 20:25:14
I couldn't, as this is forward declared. I tried f
| |
22 public: | |
23 DeltaUpdateOpPatchHost(base::Callback<void(int result)> callback, | |
24 scoped_refptr<base::SequencedTaskRunner> task_runner); | |
25 | |
26 void StartProcess(scoped_ptr<IPC::Message> message); | |
27 | |
28 private: | |
29 virtual ~DeltaUpdateOpPatchHost(); | |
30 | |
31 void OnPatchFinished(int result); | |
32 | |
33 // Overrides of content::UtilityProcessHostClient. | |
34 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | |
35 | |
36 virtual void OnProcessCrashed(int exit_code) OVERRIDE; | |
37 | |
38 base::Callback<void(int result)> callback_; | |
39 scoped_refptr<base::SequencedTaskRunner> task_runner_; | |
40 }; | |
41 | |
42 DeltaUpdateOpPatchHost::DeltaUpdateOpPatchHost( | |
43 base::Callback<void(int result)> callback, | |
44 scoped_refptr<base::SequencedTaskRunner> task_runner) | |
45 : callback_(callback), task_runner_(task_runner) { | |
46 } | |
47 | |
48 DeltaUpdateOpPatchHost::~DeltaUpdateOpPatchHost() { | |
49 } | |
50 | |
51 void DeltaUpdateOpPatchHost::StartProcess(scoped_ptr<IPC::Message> message) { | |
52 // The DeltaUpdateOpPatchHost is not responsible for deleting the | |
53 // UtilityProcessHost object. | |
54 content::UtilityProcessHost* host = content::UtilityProcessHost::Create( | |
55 this, base::MessageLoopProxy::current().get()); | |
56 host->DisableSandbox(); | |
57 host->Send(message.release()); | |
58 } | |
59 | |
60 bool DeltaUpdateOpPatchHost::OnMessageReceived(const IPC::Message& message) { | |
61 bool handled = true; | |
62 IPC_BEGIN_MESSAGE_MAP(DeltaUpdateOpPatchHost, message) | |
63 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_PatchFile_Finished, OnPatchFinished) | |
64 IPC_MESSAGE_UNHANDLED(handled = false) | |
65 IPC_END_MESSAGE_MAP() | |
66 return handled; | |
67 } | |
68 | |
69 void DeltaUpdateOpPatchHost::OnPatchFinished(int result) { | |
70 task_runner_->PostTask(FROM_HERE, base::Bind(callback_, result)); | |
71 task_runner_ = NULL; | |
72 } | |
73 | |
74 void DeltaUpdateOpPatchHost::OnProcessCrashed(int exit_code) { | |
75 task_runner_->PostTask(FROM_HERE, base::Bind(callback_, -1)); | |
76 task_runner_ = NULL; | |
77 } | |
78 | |
79 ChromeOutOfProcessPatcher::ChromeOutOfProcessPatcher() { | |
80 } | |
81 | |
82 ChromeOutOfProcessPatcher::~ChromeOutOfProcessPatcher() { | |
83 } | |
84 | |
85 void ChromeOutOfProcessPatcher::Patch( | |
86 const std::string& operation, | |
87 scoped_refptr<base::SequencedTaskRunner> task_runner, | |
88 base::FilePath& input_abs_path, | |
89 base::FilePath& patch_abs_path, | |
90 base::FilePath& output_abs_path, | |
91 base::Callback<void(int result)> callback) { | |
92 host_ = new DeltaUpdateOpPatchHost(callback, task_runner); | |
waffles
2014/07/31 21:54:26
I would rename DeltaUpdateOpPatchHost to just Patc
tommycli
2014/08/04 20:25:14
Done.
| |
93 scoped_ptr<IPC::Message> patch_message; | |
94 if (operation == kBsdiff) { | |
95 patch_message.reset(new ChromeUtilityMsg_PatchFileBsdiff( | |
96 input_abs_path, patch_abs_path, output_abs_path)); | |
97 } else if (operation == kCourgette) { | |
98 patch_message.reset(new ChromeUtilityMsg_PatchFileCourgette( | |
99 input_abs_path, patch_abs_path, output_abs_path)); | |
100 } else { | |
101 NOTREACHED(); | |
102 } | |
103 | |
104 content::BrowserThread::PostTask( | |
105 content::BrowserThread::IO, | |
106 FROM_HERE, | |
107 base::Bind(&DeltaUpdateOpPatchHost::StartProcess, | |
108 host_, | |
109 base::Passed(&patch_message))); | |
110 } | |
111 | |
112 } // namespace component_updater | |
OLD | NEW |