Chromium Code Reviews| Index: ui/base/ime/input_method_log_collector.cc |
| diff --git a/ui/base/ime/input_method_log_collector.cc b/ui/base/ime/input_method_log_collector.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a0af88d8ad3e2f907fa2f195f533e09aea409d42 |
| --- /dev/null |
| +++ b/ui/base/ime/input_method_log_collector.cc |
| @@ -0,0 +1,56 @@ |
| +// Copyright 2016 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 "ui/base/ime/input_method_log_collector.h" |
| + |
| +#include <string.h> |
| + |
| +#include "base/debug/alias.h" |
| +#include "base/debug/dump_without_crashing.h" |
| +#include "base/strings/string_number_conversions.h" |
| + |
| +namespace ui { |
| + |
| +InputMethodLogCollector::InputMethodLogCollector() {} |
| + |
| +InputMethodLogCollector::~InputMethodLogCollector() {} |
| + |
| +void InputMethodLogCollector::AddString(const char* str_val) { |
| + if (logs_.size() >= 50) |
|
eroman
2016/01/14 19:44:13
I suggest making 50 a constant, since it is re-use
Shu Chen
2016/01/16 04:15:45
Done.
|
| + logs_.erase(logs_.begin()); |
| + logs_.push_back(str_val); |
| +} |
| + |
| +void InputMethodLogCollector::AddBoolean(bool bool_val) { |
| + AddString(bool_val ? "true" : "false"); |
| +} |
| + |
| +void InputMethodLogCollector::AddNumber(int num_val) { |
|
eroman
2016/01/14 19:44:13
AddNumber() is unused as far as I can tell, why in
Shu Chen
2016/01/16 04:15:45
Done. I've removed it.
|
| + number_strings_.push_back(base::IntToString(num_val)); |
| + AddString(number_strings_.back().c_str()); |
|
eroman
2016/01/14 19:44:13
This wouldn't really work since the backing memory
Shu Chen
2016/01/16 04:15:45
Thanks. I've removed the AddNumber method.
|
| +} |
| + |
| +void InputMethodLogCollector::DumpLogs() { |
| + static int dump_times = 0; |
| + if (dump_times > 5) { |
| + ClearLogs(); |
| + return; |
| + } |
| + const char* logs_copy[50]; |
| + size_t log_count = logs_.size(); |
| + for (size_t i = 0; i < log_count; ++i) |
|
eroman
2016/01/14 19:44:13
To be extra safe I suggest writing it as "i < log_
Shu Chen
2016/01/16 04:15:46
Done.
|
| + logs_copy[i] = logs_[i]; |
| + base::debug::Alias(&log_count); |
| + base::debug::Alias(&logs_copy); |
| + base::debug::DumpWithoutCrashing(); |
| + dump_times++; |
| + ClearLogs(); |
| +} |
| + |
| +void InputMethodLogCollector::ClearLogs() { |
| + number_strings_.clear(); |
| + logs_.clear(); |
| +} |
| + |
| +} // namespace ui |