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

Side by Side Diff: chrome/browser/chromeos/input_method/ibus_ui_controller.cc

Issue 10109001: Replace all LOGs in input_method/, except two user-facing errors, to DVLOG(1). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review 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 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/chromeos/input_method/ibus_ui_controller.h" 5 #include "chrome/browser/chromeos/input_method/ibus_ui_controller.h"
6 6
7 #if defined(HAVE_IBUS) 7 #if defined(HAVE_IBUS)
8 #include <ibus.h> 8 #include <ibus.h>
9 #endif 9 #endif
10 10
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 if (ibus_) { 125 if (ibus_) {
126 return true; 126 return true;
127 } 127 }
128 ibus_init(); 128 ibus_init();
129 ibus_ = ibus_bus_new(); 129 ibus_ = ibus_bus_new();
130 CHECK(ibus_) << "ibus_bus_new() failed. Out of memory?"; 130 CHECK(ibus_) << "ibus_bus_new() failed. Out of memory?";
131 131
132 bool result = false; 132 bool result = false;
133 // Check the IBus connection status. 133 // Check the IBus connection status.
134 if (ibus_bus_is_connected(ibus_)) { 134 if (ibus_bus_is_connected(ibus_)) {
135 LOG(INFO) << "ibus_bus_is_connected(). IBus connection is ready."; 135 DVLOG(1) << "ibus_bus_is_connected(). IBus connection is ready.";
136 FOR_EACH_OBSERVER(Observer, observers_, OnConnectionChange(true)); 136 FOR_EACH_OBSERVER(Observer, observers_, OnConnectionChange(true));
137 result = true; 137 result = true;
138 } 138 }
139 139
140 // Start listening the gobject signals regardless of the bus connection 140 // Start listening the gobject signals regardless of the bus connection
141 // status. 141 // status.
142 ConnectIBusSignals(); 142 ConnectIBusSignals();
143 return result; 143 return result;
144 } 144 }
145 145
146 // Creates IBusPanelService object if |ibus_| is already connected. 146 // Creates IBusPanelService object if |ibus_| is already connected.
147 bool MaybeRestorePanelService() { 147 bool MaybeRestorePanelService() {
148 if (!ibus_ || !ibus_bus_is_connected(ibus_)) { 148 if (!ibus_ || !ibus_bus_is_connected(ibus_)) {
149 return false; 149 return false;
150 } 150 }
151 151
152 if (ibus_panel_service_) { 152 if (ibus_panel_service_) {
153 LOG(ERROR) << "IBusPanelService is already available. Remove it first."; 153 DVLOG(1) << "IBusPanelService is already available. Remove it first.";
154 g_object_set_data(G_OBJECT(ibus_), kPanelObjectKey, NULL); 154 g_object_set_data(G_OBJECT(ibus_), kPanelObjectKey, NULL);
155 g_object_unref(ibus_panel_service_); 155 g_object_unref(ibus_panel_service_);
156 ibus_panel_service_ = NULL; 156 ibus_panel_service_ = NULL;
157 } 157 }
158 158
159 // Create an IBusPanelService object. 159 // Create an IBusPanelService object.
160 GDBusConnection* ibus_connection = ibus_bus_get_connection(ibus_); 160 GDBusConnection* ibus_connection = ibus_bus_get_connection(ibus_);
161 if (!ibus_connection) { 161 if (!ibus_connection) {
162 LOG(ERROR) << "ibus_bus_get_connection() failed"; 162 DVLOG(1) << "ibus_bus_get_connection() failed";
163 return false; 163 return false;
164 } 164 }
165 ibus_panel_service_ = ibus_panel_service_new(ibus_connection); 165 ibus_panel_service_ = ibus_panel_service_new(ibus_connection);
166 if (!ibus_panel_service_) { 166 if (!ibus_panel_service_) {
167 LOG(ERROR) << "ibus_chromeos_panel_service_new() failed"; 167 DVLOG(1) << "ibus_chromeos_panel_service_new() failed";
168 return false; 168 return false;
169 } 169 }
170 ConnectPanelServiceSignals(); 170 ConnectPanelServiceSignals();
171 g_object_set_data(G_OBJECT(ibus_), kPanelObjectKey, ibus_panel_service_); 171 g_object_set_data(G_OBJECT(ibus_), kPanelObjectKey, ibus_panel_service_);
172 LOG(INFO) << "IBusPanelService object is successfully (re-)created."; 172 DVLOG(1) << "IBusPanelService object is successfully (re-)created.";
173 173
174 // Request the well-known name *asynchronously*. 174 // Request the well-known name *asynchronously*.
175 ibus_bus_request_name_async(ibus_, 175 ibus_bus_request_name_async(ibus_,
176 IBUS_SERVICE_PANEL, 176 IBUS_SERVICE_PANEL,
177 0 /* flags */, 177 0 /* flags */,
178 -1 /* timeout */, 178 -1 /* timeout */,
179 NULL /* cancellable */, 179 NULL /* cancellable */,
180 RequestNameCallback, 180 RequestNameCallback,
181 g_object_ref(ibus_)); 181 g_object_ref(ibus_));
182 return true; 182 return true;
183 } 183 }
184 184
185 // IBusUiController override. 185 // IBusUiController override.
186 virtual void NotifyCandidateClicked(int index, 186 virtual void NotifyCandidateClicked(int index,
187 int button, 187 int button,
188 int flags) OVERRIDE { 188 int flags) OVERRIDE {
189 if (!ibus_ || !ibus_bus_is_connected(ibus_)) { 189 if (!ibus_ || !ibus_bus_is_connected(ibus_)) {
190 LOG(ERROR) << "NotifyCandidateClicked: bus is not connected."; 190 DVLOG(1) << "NotifyCandidateClicked: bus is not connected.";
191 return; 191 return;
192 } 192 }
193 if (!ibus_panel_service_) { 193 if (!ibus_panel_service_) {
194 LOG(ERROR) << "NotifyCandidateClicked: panel service is not available."; 194 DVLOG(1) << "NotifyCandidateClicked: panel service is not available.";
195 return; 195 return;
196 } 196 }
197 197
198 /* Send a D-Bus signal to ibus-daemon *asynchronously*. */ 198 /* Send a D-Bus signal to ibus-daemon *asynchronously*. */
199 ibus_panel_service_candidate_clicked(ibus_panel_service_, 199 ibus_panel_service_candidate_clicked(ibus_panel_service_,
200 index, 200 index,
201 button, 201 button,
202 flags); 202 flags);
203 } 203 }
204 204
205 // IBusUiController override. 205 // IBusUiController override.
206 virtual void NotifyCursorUp() OVERRIDE { 206 virtual void NotifyCursorUp() OVERRIDE {
207 if (!ibus_ || !ibus_bus_is_connected(ibus_)) { 207 if (!ibus_ || !ibus_bus_is_connected(ibus_)) {
208 LOG(ERROR) << "NotifyCursorUp: bus is not connected."; 208 DVLOG(1) << "NotifyCursorUp: bus is not connected.";
209 return; 209 return;
210 } 210 }
211 if (!ibus_panel_service_) { 211 if (!ibus_panel_service_) {
212 LOG(ERROR) << "NotifyCursorUp: panel service is not available."; 212 DVLOG(1) << "NotifyCursorUp: panel service is not available.";
213 return; 213 return;
214 } 214 }
215 215
216 /* Send a D-Bus signal to ibus-daemon *asynchronously*. */ 216 /* Send a D-Bus signal to ibus-daemon *asynchronously*. */
217 ibus_panel_service_cursor_up(ibus_panel_service_); 217 ibus_panel_service_cursor_up(ibus_panel_service_);
218 } 218 }
219 219
220 // IBusUiController override. 220 // IBusUiController override.
221 virtual void NotifyCursorDown() OVERRIDE { 221 virtual void NotifyCursorDown() OVERRIDE {
222 if (!ibus_ || !ibus_bus_is_connected(ibus_)) { 222 if (!ibus_ || !ibus_bus_is_connected(ibus_)) {
223 LOG(ERROR) << "NotifyCursorDown: bus is not connected."; 223 DVLOG(1) << "NotifyCursorDown: bus is not connected.";
224 return; 224 return;
225 } 225 }
226 if (!ibus_panel_service_) { 226 if (!ibus_panel_service_) {
227 LOG(ERROR) << "NotifyCursorDown: panel service is not available."; 227 DVLOG(1) << "NotifyCursorDown: panel service is not available.";
228 return; 228 return;
229 } 229 }
230 /* Send a D-Bus signal to ibus-daemon *asynchronously*. */ 230 /* Send a D-Bus signal to ibus-daemon *asynchronously*. */
231 ibus_panel_service_cursor_down(ibus_panel_service_); 231 ibus_panel_service_cursor_down(ibus_panel_service_);
232 } 232 }
233 233
234 // IBusUiController override. 234 // IBusUiController override.
235 virtual void NotifyPageUp() OVERRIDE { 235 virtual void NotifyPageUp() OVERRIDE {
236 if (!ibus_ || !ibus_bus_is_connected(ibus_)) { 236 if (!ibus_ || !ibus_bus_is_connected(ibus_)) {
237 LOG(ERROR) << "NotifyPageUp: bus is not connected."; 237 DVLOG(1) << "NotifyPageUp: bus is not connected.";
238 return; 238 return;
239 } 239 }
240 if (!ibus_panel_service_) { 240 if (!ibus_panel_service_) {
241 LOG(ERROR) << "NotifyPageUp: panel service is not available."; 241 DVLOG(1) << "NotifyPageUp: panel service is not available.";
242 return; 242 return;
243 } 243 }
244 244
245 /* Send a D-Bus signal to ibus-daemon *asynchronously*. */ 245 /* Send a D-Bus signal to ibus-daemon *asynchronously*. */
246 ibus_panel_service_page_up(ibus_panel_service_); 246 ibus_panel_service_page_up(ibus_panel_service_);
247 } 247 }
248 248
249 // IBusUiController override. 249 // IBusUiController override.
250 virtual void NotifyPageDown() OVERRIDE { 250 virtual void NotifyPageDown() OVERRIDE {
251 if (!ibus_ || !ibus_bus_is_connected(ibus_)) { 251 if (!ibus_ || !ibus_bus_is_connected(ibus_)) {
252 LOG(ERROR) << "NotifyPageDown: bus is not connected."; 252 DVLOG(1) << "NotifyPageDown: bus is not connected.";
253 return; 253 return;
254 } 254 }
255 if (!ibus_panel_service_) { 255 if (!ibus_panel_service_) {
256 LOG(ERROR) << "NotifyPageDown: panel service is not available."; 256 DVLOG(1) << "NotifyPageDown: panel service is not available.";
257 return; 257 return;
258 } 258 }
259 259
260 /* Send a D-Bus signal to ibus-daemon *asynchronously*. */ 260 /* Send a D-Bus signal to ibus-daemon *asynchronously*. */
261 ibus_panel_service_page_down(ibus_panel_service_); 261 ibus_panel_service_page_down(ibus_panel_service_);
262 } 262 }
263 263
264 // IBusUiController override. 264 // IBusUiController override.
265 virtual void Connect() OVERRIDE { 265 virtual void Connect() OVERRIDE {
266 // It's totally fine if ConnectToIBus() fails here, as we'll get 266 // It's totally fine if ConnectToIBus() fails here, as we'll get
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 reinterpret_cast<gpointer>(UpdatePreeditTextThunk), 497 reinterpret_cast<gpointer>(UpdatePreeditTextThunk),
498 this); 498 this);
499 g_signal_handlers_disconnect_by_func( 499 g_signal_handlers_disconnect_by_func(
500 ibus_panel_service_, 500 ibus_panel_service_,
501 reinterpret_cast<gpointer>(HidePreeditTextThunk), 501 reinterpret_cast<gpointer>(HidePreeditTextThunk),
502 this); 502 this);
503 } 503 }
504 504
505 // Handles "connected" signal from ibus-daemon. 505 // Handles "connected" signal from ibus-daemon.
506 void IBusBusConnected(IBusBus* bus) { 506 void IBusBusConnected(IBusBus* bus) {
507 LOG(WARNING) << "IBus connection is recovered."; 507 DVLOG(1) << "IBus connection is recovered.";
508 if (!MaybeRestorePanelService()) { 508 if (!MaybeRestorePanelService()) {
509 LOG(ERROR) << "MaybeRestorePanelService() failed"; 509 DVLOG(1) << "MaybeRestorePanelService() failed";
510 return; 510 return;
511 } 511 }
512 512
513 FOR_EACH_OBSERVER(Observer, observers_, OnConnectionChange(true)); 513 FOR_EACH_OBSERVER(Observer, observers_, OnConnectionChange(true));
514 } 514 }
515 515
516 // Handles "disconnected" signal from ibus-daemon. Releases the 516 // Handles "disconnected" signal from ibus-daemon. Releases the
517 // |ibus_panel_service_| object since the connection the service has will be 517 // |ibus_panel_service_| object since the connection the service has will be
518 // destroyed soon. 518 // destroyed soon.
519 void IBusBusDisconnected(IBusBus* bus) { 519 void IBusBusDisconnected(IBusBus* bus) {
520 LOG(WARNING) << "IBus connection is terminated."; 520 DVLOG(1) << "IBus connection is terminated.";
521 if (ibus_panel_service_) { 521 if (ibus_panel_service_) {
522 DisconnectPanelServiceSignals(); 522 DisconnectPanelServiceSignals();
523 // Since the connection being disconnected is currently mutex-locked, 523 // Since the connection being disconnected is currently mutex-locked,
524 // we can't unref the panel service object directly here. Because when the 524 // we can't unref the panel service object directly here. Because when the
525 // service object is deleted, the connection, which the service also has, 525 // service object is deleted, the connection, which the service also has,
526 // will be locked again. To avoid deadlock, we use g_idle_add instead. 526 // will be locked again. To avoid deadlock, we use g_idle_add instead.
527 g_object_set_data(G_OBJECT(ibus_), kPanelObjectKey, NULL); 527 g_object_set_data(G_OBJECT(ibus_), kPanelObjectKey, NULL);
528 g_idle_add(ReleasePanelService, ibus_panel_service_); 528 g_idle_add(ReleasePanelService, ibus_panel_service_);
529 ibus_panel_service_ = NULL; 529 ibus_panel_service_ = NULL;
530 } 530 }
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 GVariant* variant = ibus_serializable_get_attachment( 609 GVariant* variant = ibus_serializable_get_attachment(
610 IBUS_SERIALIZABLE(table), "mozc.candidates"); 610 IBUS_SERIALIZABLE(table), "mozc.candidates");
611 if (variant != NULL) { 611 if (variant != NULL) {
612 gconstpointer ptr = g_variant_get_data(variant); 612 gconstpointer ptr = g_variant_get_data(variant);
613 if (ptr != NULL) { 613 if (ptr != NULL) {
614 gsize size = g_variant_get_size(variant); 614 gsize size = g_variant_get_size(variant);
615 GByteArray* bytearray = g_byte_array_sized_new(size); 615 GByteArray* bytearray = g_byte_array_sized_new(size);
616 g_byte_array_append( 616 g_byte_array_append(
617 bytearray, reinterpret_cast<const guint8*>(ptr), size); 617 bytearray, reinterpret_cast<const guint8*>(ptr), size);
618 if (!lookup_table.mozc_candidates.ParseFromArray( 618 if (!lookup_table.mozc_candidates.ParseFromArray(
619 bytearray->data, bytearray->len)) { 619 bytearray->data, bytearray->len)) {
620 lookup_table.mozc_candidates.Clear(); 620 lookup_table.mozc_candidates.Clear();
621 } 621 }
622 g_byte_array_unref(bytearray); 622 g_byte_array_unref(bytearray);
623 } 623 }
624 } 624 }
625 625
626 // Copy candidates and annotations to |lookup_table|. 626 // Copy candidates and annotations to |lookup_table|.
627 for (int i = 0; ; i++) { 627 for (int i = 0; ; i++) {
628 IBusText *text = ibus_lookup_table_get_candidate(table, i); 628 IBusText *text = ibus_lookup_table_get_candidate(table, i);
629 if (!text) { 629 if (!text) {
(...skipping 22 matching lines...) Expand all
652 break; 652 break;
653 } 653 }
654 lookup_table.labels.push_back(text->text); 654 lookup_table.labels.push_back(text->text);
655 } 655 }
656 656
657 lookup_table.cursor_absolute_index = 657 lookup_table.cursor_absolute_index =
658 ibus_lookup_table_get_cursor_pos(table); 658 ibus_lookup_table_get_cursor_pos(table);
659 lookup_table.page_size = ibus_lookup_table_get_page_size(table); 659 lookup_table.page_size = ibus_lookup_table_get_page_size(table);
660 // Ensure that the page_size is non-zero to avoid div-by-zero error. 660 // Ensure that the page_size is non-zero to avoid div-by-zero error.
661 if (lookup_table.page_size <= 0) { 661 if (lookup_table.page_size <= 0) {
662 LOG(DFATAL) << "Invalid page size: " << lookup_table.page_size; 662 DVLOG(1) << "Invalid page size: " << lookup_table.page_size;
663 lookup_table.page_size = 1; 663 lookup_table.page_size = 1;
664 } 664 }
665 665
666 FOR_EACH_OBSERVER(Observer, observers_, 666 FOR_EACH_OBSERVER(Observer, observers_,
667 OnUpdateLookupTable(lookup_table)); 667 OnUpdateLookupTable(lookup_table));
668 } 668 }
669 669
670 // A callback function that will be called when ibus_bus_request_name_async() 670 // A callback function that will be called when ibus_bus_request_name_async()
671 // request is finished. 671 // request is finished.
672 static void RequestNameCallback(GObject* source_object, 672 static void RequestNameCallback(GObject* source_object,
673 GAsyncResult* res, 673 GAsyncResult* res,
674 gpointer user_data) { 674 gpointer user_data) {
675 IBusBus* bus = IBUS_BUS(user_data); 675 IBusBus* bus = IBUS_BUS(user_data);
676 g_return_if_fail(bus); 676 g_return_if_fail(bus);
677 677
678 GError* error = NULL; 678 GError* error = NULL;
679 const guint service_id = 679 const guint service_id =
680 ibus_bus_request_name_async_finish(bus, res, &error); 680 ibus_bus_request_name_async_finish(bus, res, &error);
681 681
682 if (!service_id) { 682 if (!service_id) {
683 std::string message = "(unknown error)"; 683 std::string message = "(unknown error)";
684 if (error && error->message) { 684 if (error && error->message) {
685 message = error->message; 685 message = error->message;
686 } 686 }
687 LOG(ERROR) << "Failed to register the panel service: " << message; 687 DVLOG(1) << "Failed to register the panel service: " << message;
688 } else { 688 } else {
689 LOG(INFO) << "The panel service is registered: ID=" << service_id; 689 DVLOG(1) << "The panel service is registered: ID=" << service_id;
690 } 690 }
691 691
692 if (error) { 692 if (error) {
693 g_error_free(error); 693 g_error_free(error);
694 } 694 }
695 g_object_unref(bus); 695 g_object_unref(bus);
696 } 696 }
697 697
698 IBusBus* ibus_; 698 IBusBus* ibus_;
699 IBusPanelService* ibus_panel_service_; 699 IBusPanelService* ibus_panel_service_;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
747 IBusUiController::~IBusUiController() { 747 IBusUiController::~IBusUiController() {
748 } 748 }
749 749
750 bool IsActiveForTesting(const std::string& input_method_id, 750 bool IsActiveForTesting(const std::string& input_method_id,
751 const InputMethodDescriptors* descriptors) { 751 const InputMethodDescriptors* descriptors) {
752 return IsActive(input_method_id, descriptors); 752 return IsActive(input_method_id, descriptors);
753 } 753 }
754 754
755 } // namespace input_method 755 } // namespace input_method
756 } // namespace chromeos 756 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698