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

Unified Diff: chromeos/dbus/ibus/ibus_util.cc

Issue 10159004: Extends DBusThreadManager to connect ibus-bus. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 8 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
Index: chromeos/dbus/ibus/ibus_util.cc
diff --git a/chromeos/dbus/ibus/ibus_util.cc b/chromeos/dbus/ibus/ibus_util.cc
new file mode 100644
index 0000000000000000000000000000000000000000..8f4c680d5a5f8a11395634c011b1d5ba1a4bc6b6
--- /dev/null
+++ b/chromeos/dbus/ibus/ibus_util.cc
@@ -0,0 +1,61 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chromeos/dbus/ibus/ibus_util.h"
+
+#include "base/environment.h"
+#include "base/file_util.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/string_util.h"
+
+#include <string>
+#include <vector>
+
+namespace chromeos {
+
+namespace {
+const char kIBusAddressFileEnvKey[] = "IBUS_ADDRESS_FILE";
+const char kIBusAddressKey[] = "IBUS_ADDRESS";
+} // namespace
+
+bool IBusUtil::GetIBusAddress(std::string* address) {
+ DCHECK(address);
+ scoped_ptr<base::Environment> env(base::Environment::Create());
+ std::string address_file_path;
+ if (!env->GetVar(kIBusAddressFileEnvKey, &address_file_path)) {
+ LOG(ERROR) << "Can not find " << kIBusAddressFileEnvKey
+ << " in environment variables.";
+ return false;
+ }
+
+ std::string address_file_contents;
+ if (!file_util::ReadFileToString(FilePath(address_file_path),
satorux1 2012/04/20 23:18:40 Ugh, you cannot do this here. DBusThreadManager is
Seigo Nonaka 2012/04/21 05:35:14 I found a command line flag to specify opening add
Seigo Nonaka 2012/04/23 23:03:21 I made another CL for above. http://codereview.chr
+ &address_file_contents)) {
+ LOG(ERROR) << "Can not read IBus address file:" << address_file_path;
+ return false;
+ }
+
+ std::vector<std::string> lines;
+ Tokenize(address_file_contents, "\r\n", &lines);
satorux1 2012/04/20 23:18:40 Use SplitString instead? \r won't be used in the f
Seigo Nonaka 2012/04/23 23:03:21 Yes, but I removed this file. Thanks On 2012/04/20
+
+ // Prfix matching is enought for ibus address file parsing, because address
+ // file is generated by ibus with fixed format.
+ // https://github.com/ibus/ibus/blob/master/src/ibusshare.c#L234
+ const std::string address_entry_prefix = std::string(kIBusAddressKey)
+ + std::string("=");
+ for (std::vector<std::string>::const_iterator ite = lines.begin();
+ ite != lines.end(); ++ite) {
satorux1 2012/04/20 23:18:40 matter of taste, but for (size_t i = 0; i < lines.
Seigo Nonaka 2012/04/23 23:03:21 I have not strong policy about iterator:) I will d
+
+ if (!StartsWithASCII(*ite, address_entry_prefix, true)) {
+ continue;
+ }
+
+ address->assign(ite->substr(address_entry_prefix.size()));
+ return true;
+ }
+ LOG(ERROR) << "Can not find " << kIBusAddressKey << " entry.";
+ return false;
+}
+
+} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698