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/macros.h" | |
12 | |
13 namespace { | |
14 | |
15 const size_t kMaxLogCount = 50; | |
16 | |
17 } | |
18 | |
19 namespace ui { | |
20 | |
21 InputMethodLogCollector::InputMethodLogCollector() {} | |
22 | |
23 InputMethodLogCollector::~InputMethodLogCollector() {} | |
24 | |
25 void InputMethodLogCollector::AddString(const char* str_val) { | |
26 if (logs_.size() >= kMaxLogCount) | |
27 logs_.erase(logs_.begin()); | |
28 logs_.push_back(str_val); | |
29 } | |
30 | |
31 void InputMethodLogCollector::AddBoolean(bool bool_val) { | |
32 AddString(bool_val ? "true" : "false"); | |
33 } | |
34 | |
35 void InputMethodLogCollector::DumpLogs() { | |
36 static int dump_times = 0; | |
37 if (dump_times > 5) { | |
38 ClearLogs(); | |
39 return; | |
40 } | |
41 const char* logs_copy[kMaxLogCount]; | |
42 size_t log_count = logs_.size(); | |
43 for (size_t i = 0; i < log_count && i < arraysize(logs_copy); ++i) | |
44 logs_copy[i] = logs_[i]; | |
45 base::debug::Alias(&log_count); | |
46 base::debug::Alias(&logs_copy); | |
47 base::debug::DumpWithoutCrashing(); | |
48 dump_times++; | |
49 ClearLogs(); | |
50 } | |
51 | |
52 void InputMethodLogCollector::ClearLogs() { | |
53 logs_.clear(); | |
54 } | |
55 | |
56 } // namespace ui | |
OLD | NEW |