OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ui/base/ime/input_method_log_collector.h" | |
6 | |
7 #include <string.h> | |
8 | |
9 #include "base/debug/alias.h" | |
10 #include "base/debug/dump_without_crashing.h" | |
11 #include "base/strings/string_number_conversions.h" | |
12 | |
13 namespace ui { | |
14 | |
15 InputMethodLogCollector::InputMethodLogCollector() {} | |
16 | |
17 InputMethodLogCollector::~InputMethodLogCollector() {} | |
18 | |
19 void InputMethodLogCollector::AddString(const char* str_val) { | |
20 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.
| |
21 logs_.erase(logs_.begin()); | |
22 logs_.push_back(str_val); | |
23 } | |
24 | |
25 void InputMethodLogCollector::AddBoolean(bool bool_val) { | |
26 AddString(bool_val ? "true" : "false"); | |
27 } | |
28 | |
29 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.
| |
30 number_strings_.push_back(base::IntToString(num_val)); | |
31 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.
| |
32 } | |
33 | |
34 void InputMethodLogCollector::DumpLogs() { | |
35 static int dump_times = 0; | |
36 if (dump_times > 5) { | |
37 ClearLogs(); | |
38 return; | |
39 } | |
40 const char* logs_copy[50]; | |
41 size_t log_count = logs_.size(); | |
42 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.
| |
43 logs_copy[i] = logs_[i]; | |
44 base::debug::Alias(&log_count); | |
45 base::debug::Alias(&logs_copy); | |
46 base::debug::DumpWithoutCrashing(); | |
47 dump_times++; | |
48 ClearLogs(); | |
49 } | |
50 | |
51 void InputMethodLogCollector::ClearLogs() { | |
52 number_strings_.clear(); | |
53 logs_.clear(); | |
54 } | |
55 | |
56 } // namespace ui | |
OLD | NEW |