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

Unified Diff: chromeos_keyboard.cc

Issue 6709058: Use chromeos::Process in libchromeos.a instead of g_spawn_async. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/cros.git@master
Patch Set: Created 9 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « SConstruct.chromiumos ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chromeos_keyboard.cc
diff --git a/chromeos_keyboard.cc b/chromeos_keyboard.cc
index 4c021bae5df186022cf607a0bf70e7fffb72ff90..15a0e80dd5678ffbbe9741a3aa1e70b6064749aa 100644
--- a/chromeos_keyboard.cc
+++ b/chromeos_keyboard.cc
@@ -16,6 +16,7 @@
#include "base/logging.h"
#include "base/singleton.h"
#include "base/string_util.h"
+#include "chromeos/process.h"
namespace {
@@ -219,32 +220,23 @@ class XKeyboard {
// Executes 'setxkbmap -layout ...' command asynchronously.
// TODO(yusukes): Use libxkbfile.so instead of the command (crosbug.com/13105)
void ExecuteSetLayoutCommand(const std::string& layouts_to_set) {
- gchar* argv[] = {
- g_strdup(kSetxkbmapCommand), g_strdup("-layout"),
- g_strdup(layouts_to_set.c_str()), NULL
- };
-
- const GSpawnFlags flags = static_cast<GSpawnFlags>(
- G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL);
- GError* error = NULL;
- g_spawn_async(NULL, // working_directory
- argv,
- NULL, // envp
- flags,
- NULL, // child_setup
- NULL, // user_data
- NULL, // child_pid
- &error);
-
- for (size_t i = 0; argv[i] != NULL; ++i) {
- g_free(argv[i]);
- }
- if (error) {
- if (error->message) {
- LOG(ERROR) << "Failed to execute setxkbmap: " << error->message;
- }
- g_error_free(error);
+ chromeos::ProcessImpl process;
+ process.AddArg(kSetxkbmapCommand);
+ process.AddStringOption("-layout", layouts_to_set);
+ if (!process.Start()) {
+ LOG(ERROR) << "Failed to execute setxkbmap: " << layouts_to_set;
+ return;
}
+ // g_child_watch_add is necessary to prevent the process from becoming a
+ // zombie.
+ g_child_watch_add(process.pid(),
+ reinterpret_cast<GChildWatchFunc>(OnSetLayoutFinish),
+ this);
+ process.Release(); // do not kill the setxkbmap process on function exit.
+ }
+
+ static void OnSetLayoutFinish(GPid pid, gint status, XKeyboard* self) {
+ DLOG(INFO) << "OnSetLayoutFinish: pid=" << pid;
}
// The XKB layout name which we set last time like "us" and "us(dvorak)".
« no previous file with comments | « SConstruct.chromiumos ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698