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

Side by Side Diff: chrome/browser/extensions/api/terminal/terminal_private_api.cc

Issue 12089062: Move API functions registrations out of ExtensionFunctionRegistry. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 7 years, 10 months 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/extensions/api/terminal/terminal_private_api.h" 5 #include "chrome/browser/extensions/api/terminal/terminal_private_api.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/chromeos/chromeos_version.h" 8 #include "base/chromeos/chromeos_version.h"
9 #include "base/json/json_writer.h" 9 #include "base/json/json_writer.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 } // namespace 68 } // namespace
69 69
70 TerminalPrivateFunction::TerminalPrivateFunction() {} 70 TerminalPrivateFunction::TerminalPrivateFunction() {}
71 71
72 TerminalPrivateFunction::~TerminalPrivateFunction() {} 72 TerminalPrivateFunction::~TerminalPrivateFunction() {}
73 73
74 bool TerminalPrivateFunction::RunImpl() { 74 bool TerminalPrivateFunction::RunImpl() {
75 return RunTerminalFunction(); 75 return RunTerminalFunction();
76 } 76 }
77 77
78 OpenTerminalProcessFunction::OpenTerminalProcessFunction() : command_(NULL) {} 78 TerminalPrivateOpenTerminalProcessFunction::
79 TerminalPrivateOpenTerminalProcessFunction() : command_(NULL) {}
79 80
80 OpenTerminalProcessFunction::~OpenTerminalProcessFunction() {} 81 TerminalPrivateOpenTerminalProcessFunction::
82 ~TerminalPrivateOpenTerminalProcessFunction() {}
81 83
82 bool OpenTerminalProcessFunction::RunTerminalFunction() { 84 bool TerminalPrivateOpenTerminalProcessFunction::RunTerminalFunction() {
83 if (args_->GetSize() != 1) 85 if (args_->GetSize() != 1)
84 return false; 86 return false;
85 87
86 std::string name; 88 std::string name;
87 if (!args_->GetString(0, &name)) 89 if (!args_->GetString(0, &name))
88 return false; 90 return false;
89 91
90 command_ = GetProcessCommandForName(name); 92 command_ = GetProcessCommandForName(name);
91 if (!command_) { 93 if (!command_) {
92 error_ = "Invalid process name."; 94 error_ = "Invalid process name.";
93 return false; 95 return false;
94 } 96 }
95 97
96 // Registry lives on FILE thread. 98 // Registry lives on FILE thread.
97 content::BrowserThread::PostTask(content::BrowserThread::FILE, FROM_HERE, 99 content::BrowserThread::PostTask(content::BrowserThread::FILE, FROM_HERE,
98 base::Bind(&OpenTerminalProcessFunction::OpenOnFileThread, this)); 100 base::Bind(&TerminalPrivateOpenTerminalProcessFunction::OpenOnFileThread,
101 this));
99 return true; 102 return true;
100 } 103 }
101 104
102 void OpenTerminalProcessFunction::OpenOnFileThread() { 105 void TerminalPrivateOpenTerminalProcessFunction::OpenOnFileThread() {
103 DCHECK(command_); 106 DCHECK(command_);
104 107
105 ProcessProxyRegistry* registry = ProcessProxyRegistry::Get(); 108 ProcessProxyRegistry* registry = ProcessProxyRegistry::Get();
106 pid_t pid; 109 pid_t pid;
107 if (!registry->OpenProcess(command_, &pid, 110 if (!registry->OpenProcess(command_, &pid,
108 base::Bind(&NotifyProcessOutput, profile_, extension_id()))) { 111 base::Bind(&NotifyProcessOutput, profile_, extension_id()))) {
109 // If new process could not be opened, we return -1. 112 // If new process could not be opened, we return -1.
110 pid = -1; 113 pid = -1;
111 } 114 }
112 115
113 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, 116 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
114 base::Bind(&OpenTerminalProcessFunction::RespondOnUIThread, this, pid)); 117 base::Bind(&TerminalPrivateOpenTerminalProcessFunction::RespondOnUIThread,
118 this, pid));
115 } 119 }
116 120
117 SendInputToTerminalProcessFunction::~SendInputToTerminalProcessFunction() {} 121 TerminalPrivateSendInputFunction::~TerminalPrivateSendInputFunction() {}
118 122
119 void OpenTerminalProcessFunction::RespondOnUIThread(pid_t pid) { 123 void TerminalPrivateOpenTerminalProcessFunction::RespondOnUIThread(pid_t pid) {
120 SetResult(new base::FundamentalValue(pid)); 124 SetResult(new base::FundamentalValue(pid));
121 SendResponse(true); 125 SendResponse(true);
122 } 126 }
123 127
124 bool SendInputToTerminalProcessFunction::RunTerminalFunction() { 128 bool TerminalPrivateSendInputFunction::RunTerminalFunction() {
125 if (args_->GetSize() != 2) 129 if (args_->GetSize() != 2)
126 return false; 130 return false;
127 131
128 pid_t pid; 132 pid_t pid;
129 std::string text; 133 std::string text;
130 if (!args_->GetInteger(0, &pid) || !args_->GetString(1, &text)) 134 if (!args_->GetInteger(0, &pid) || !args_->GetString(1, &text))
131 return false; 135 return false;
132 136
133 // Registry lives on the FILE thread. 137 // Registry lives on the FILE thread.
134 content::BrowserThread::PostTask(content::BrowserThread::FILE, FROM_HERE, 138 content::BrowserThread::PostTask(content::BrowserThread::FILE, FROM_HERE,
135 base::Bind(&SendInputToTerminalProcessFunction::SendInputOnFileThread, 139 base::Bind(&TerminalPrivateSendInputFunction::SendInputOnFileThread,
136 this, pid, text)); 140 this, pid, text));
137 return true; 141 return true;
138 } 142 }
139 143
140 void SendInputToTerminalProcessFunction::SendInputOnFileThread(pid_t pid, 144 void TerminalPrivateSendInputFunction::SendInputOnFileThread(pid_t pid,
141 const std::string& text) { 145 const std::string& text) {
142 bool success = ProcessProxyRegistry::Get()->SendInput(pid, text); 146 bool success = ProcessProxyRegistry::Get()->SendInput(pid, text);
143 147
144 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, 148 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
145 base::Bind(&SendInputToTerminalProcessFunction::RespondOnUIThread, this, 149 base::Bind(&TerminalPrivateSendInputFunction::RespondOnUIThread, this,
146 success)); 150 success));
147 } 151 }
148 152
149 void SendInputToTerminalProcessFunction::RespondOnUIThread(bool success) { 153 void TerminalPrivateSendInputFunction::RespondOnUIThread(bool success) {
150 SetResult(new base::FundamentalValue(success)); 154 SetResult(new base::FundamentalValue(success));
151 SendResponse(true); 155 SendResponse(true);
152 } 156 }
153 157
154 CloseTerminalProcessFunction::~CloseTerminalProcessFunction() {} 158 TerminalPrivateCloseTerminalProcessFunction::
159 ~TerminalPrivateCloseTerminalProcessFunction() {}
155 160
156 bool CloseTerminalProcessFunction::RunTerminalFunction() { 161 bool TerminalPrivateCloseTerminalProcessFunction::RunTerminalFunction() {
157 if (args_->GetSize() != 1) 162 if (args_->GetSize() != 1)
158 return false; 163 return false;
159 pid_t pid; 164 pid_t pid;
160 if (!args_->GetInteger(0, &pid)) 165 if (!args_->GetInteger(0, &pid))
161 return false; 166 return false;
162 167
163 // Registry lives on the FILE thread. 168 // Registry lives on the FILE thread.
164 content::BrowserThread::PostTask(content::BrowserThread::FILE, FROM_HERE, 169 content::BrowserThread::PostTask(content::BrowserThread::FILE, FROM_HERE,
165 base::Bind(&CloseTerminalProcessFunction::CloseOnFileThread, this, pid)); 170 base::Bind(&TerminalPrivateCloseTerminalProcessFunction::
171 CloseOnFileThread, this, pid));
166 172
167 return true; 173 return true;
168 } 174 }
169 175
170 void CloseTerminalProcessFunction::CloseOnFileThread(pid_t pid) { 176 void TerminalPrivateCloseTerminalProcessFunction::CloseOnFileThread(pid_t pid) {
171 bool success = ProcessProxyRegistry::Get()->CloseProcess(pid); 177 bool success = ProcessProxyRegistry::Get()->CloseProcess(pid);
172 178
173 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, 179 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
174 base::Bind(&CloseTerminalProcessFunction::RespondOnUIThread, this, 180 base::Bind(&TerminalPrivateCloseTerminalProcessFunction::
175 success)); 181 RespondOnUIThread, this, success));
176 } 182 }
177 183
178 void CloseTerminalProcessFunction::RespondOnUIThread(bool success) { 184 void TerminalPrivateCloseTerminalProcessFunction::RespondOnUIThread(
185 bool success) {
179 SetResult(new base::FundamentalValue(success)); 186 SetResult(new base::FundamentalValue(success));
180 SendResponse(true); 187 SendResponse(true);
181 } 188 }
182 189
183 OnTerminalResizeFunction::~OnTerminalResizeFunction() {} 190 TerminalPrivateOnTerminalResizeFunction::
191 ~TerminalPrivateOnTerminalResizeFunction() {}
184 192
185 bool OnTerminalResizeFunction::RunTerminalFunction() { 193 bool TerminalPrivateOnTerminalResizeFunction::RunTerminalFunction() {
186 if (args_->GetSize() != 3) 194 if (args_->GetSize() != 3)
187 return false; 195 return false;
188 196
189 pid_t pid; 197 pid_t pid;
190 if (!args_->GetInteger(0, &pid)) 198 if (!args_->GetInteger(0, &pid))
191 return false; 199 return false;
192 200
193 int width; 201 int width;
194 if (!args_->GetInteger(1, &width)) 202 if (!args_->GetInteger(1, &width))
195 return false; 203 return false;
196 204
197 int height; 205 int height;
198 if (!args_->GetInteger(2, &height)) 206 if (!args_->GetInteger(2, &height))
199 return false; 207 return false;
200 208
201 // Registry lives on the FILE thread. 209 // Registry lives on the FILE thread.
202 content::BrowserThread::PostTask(content::BrowserThread::FILE, FROM_HERE, 210 content::BrowserThread::PostTask(content::BrowserThread::FILE, FROM_HERE,
203 base::Bind(&OnTerminalResizeFunction::OnResizeOnFileThread, this, pid, 211 base::Bind(&TerminalPrivateOnTerminalResizeFunction::OnResizeOnFileThread,
204 width, height)); 212 this, pid, width, height));
205 213
206 return true; 214 return true;
207 } 215 }
208 216
209 void OnTerminalResizeFunction::OnResizeOnFileThread(pid_t pid, 217 void TerminalPrivateOnTerminalResizeFunction::OnResizeOnFileThread(pid_t pid,
210 int width, int height) { 218 int width, int height) {
211 bool success = ProcessProxyRegistry::Get()->OnTerminalResize(pid, 219 bool success = ProcessProxyRegistry::Get()->OnTerminalResize(pid,
212 width, height); 220 width, height);
213 221
214 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, 222 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
215 base::Bind(&OnTerminalResizeFunction::RespondOnUIThread, this, 223 base::Bind(&TerminalPrivateOnTerminalResizeFunction::RespondOnUIThread,
216 success)); 224 this, success));
217 } 225 }
218 226
219 void OnTerminalResizeFunction::RespondOnUIThread(bool success) { 227 void TerminalPrivateOnTerminalResizeFunction::RespondOnUIThread(bool success) {
220 SetResult(new base::FundamentalValue(success)); 228 SetResult(new base::FundamentalValue(success));
221 SendResponse(true); 229 SendResponse(true);
222 } 230 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698