OLD | NEW |
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/app/breakpad_field_trial_win.h" | 5 #include "chrome/app/breakpad_field_trial_win.h" |
6 | 6 |
7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/string16.h" | 9 #include "base/string16.h" |
10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
11 #include "breakpad/src/client/windows/common/ipc_protocol.h" | 11 #include "breakpad/src/client/windows/common/ipc_protocol.h" |
12 #include "chrome/app/breakpad_win.h" | 12 #include "chrome/app/breakpad_win.h" |
13 #include "chrome/common/child_process_logging.h" | 13 #include "chrome/common/child_process_logging.h" |
14 | 14 |
15 // Note that this is suffixed with "2" due to a parameter change that was made | 15 // Note that this is suffixed with "2" due to a parameter change that was made |
16 // to the predecessor "SetExperimentList()". If the signature changes again, use | 16 // to the predecessor "SetExperimentList()". If the signature changes again, use |
17 // a new name. | 17 // a new name. |
18 extern "C" void __declspec(dllexport) __cdecl SetExperimentList2( | 18 extern "C" void __declspec(dllexport) __cdecl SetExperimentList2( |
19 const wchar_t** experiment_strings, size_t experiment_strings_size) { | 19 const wchar_t** experiment_strings, size_t experiment_strings_size) { |
20 // Make sure we were initialized before we start writing data | 20 // Make sure we were initialized before we start writing data |
21 if (breakpad_win::g_experiment_chunks_offset == 0) | 21 if (breakpad_win::g_experiment_chunks_offset == 0) |
22 return; | 22 return; |
23 | 23 |
24 size_t num_chunks = 0; | 24 size_t num_chunks = 0; |
25 size_t current_experiment = 0; | 25 size_t current_experiment = 0; |
26 string16 current_chunk(google_breakpad::CustomInfoEntry::kValueMaxLength, 0); | 26 string16 current_chunk(google_breakpad::CustomInfoEntry::kValueMaxLength, 0); |
27 while (current_experiment < experiment_strings_size && | 27 while (current_experiment < experiment_strings_size && |
28 num_chunks < kMaxReportedExperimentChunks) { | 28 num_chunks < kMaxReportedVariationChunks) { |
29 // Check if we have enough room to add another experiment to the current | 29 // Check if we have enough room to add another experiment to the current |
30 // chunk string. If not, we commit the current chunk string and start over. | 30 // chunk string. If not, we commit the current chunk string and start over. |
31 if (current_chunk.size() + wcslen(experiment_strings[current_experiment]) > | 31 if (current_chunk.size() + wcslen(experiment_strings[current_experiment]) > |
32 google_breakpad::CustomInfoEntry::kValueMaxLength) { | 32 google_breakpad::CustomInfoEntry::kValueMaxLength) { |
33 base::wcslcpy( | 33 base::wcslcpy( |
34 (*breakpad_win::g_custom_entries)[ | 34 (*breakpad_win::g_custom_entries)[ |
35 breakpad_win::g_experiment_chunks_offset + num_chunks].value, | 35 breakpad_win::g_experiment_chunks_offset + num_chunks].value, |
36 current_chunk.c_str(), | 36 current_chunk.c_str(), |
37 current_chunk.size() + 1); // This must include the NULL termination. | 37 current_chunk.size() + 1); // This must include the NULL termination. |
38 ++num_chunks; | 38 ++num_chunks; |
39 current_chunk = experiment_strings[current_experiment]; | 39 current_chunk = experiment_strings[current_experiment]; |
40 } else { | 40 } else { |
41 if (!current_chunk.empty()) | 41 if (!current_chunk.empty()) |
42 current_chunk += L","; | 42 current_chunk += L","; |
43 current_chunk += experiment_strings[current_experiment]; | 43 current_chunk += experiment_strings[current_experiment]; |
44 } | 44 } |
45 ++current_experiment; | 45 ++current_experiment; |
46 } | 46 } |
47 | 47 |
48 // Commit the last chunk that didn't get big enough yet. | 48 // Commit the last chunk that didn't get big enough yet. |
49 if (!current_chunk.empty() && num_chunks < kMaxReportedExperimentChunks) { | 49 if (!current_chunk.empty() && num_chunks < kMaxReportedVariationChunks) { |
50 base::wcslcpy( | 50 base::wcslcpy( |
51 (*breakpad_win::g_custom_entries)[ | 51 (*breakpad_win::g_custom_entries)[ |
52 breakpad_win::g_experiment_chunks_offset + num_chunks].value, | 52 breakpad_win::g_experiment_chunks_offset + num_chunks].value, |
53 current_chunk.c_str(), | 53 current_chunk.c_str(), |
54 current_chunk.size() + 1); // This must include the NULL termination. | 54 current_chunk.size() + 1); // This must include the NULL termination. |
55 } | 55 } |
56 | 56 |
57 // Make note of the total number of experiments, | 57 // Make note of the total number of experiments, |
58 // even if it's > kMaxReportedExperimentChunks. This is useful when | 58 // even if it's > kMaxReportedVariationChunks. This is useful when |
59 // correlating stability with the number of experiments running | 59 // correlating stability with the number of experiments running |
60 // simultaneously. | 60 // simultaneously. |
61 base::wcslcpy( | 61 base::wcslcpy( |
62 (*breakpad_win::g_custom_entries)[ | 62 (*breakpad_win::g_custom_entries)[ |
63 breakpad_win::g_num_of_experiments_offset].value, | 63 breakpad_win::g_num_of_experiments_offset].value, |
64 base::StringPrintf( | 64 base::StringPrintf( |
65 L"%d", static_cast<int>(experiment_strings_size)).c_str(), | 65 L"%d", static_cast<int>(experiment_strings_size)).c_str(), |
66 google_breakpad::CustomInfoEntry::kValueMaxLength); | 66 google_breakpad::CustomInfoEntry::kValueMaxLength); |
67 } | 67 } |
68 | 68 |
69 namespace testing { | 69 namespace testing { |
70 | 70 |
71 void SetExperimentList(const std::vector<string16>& experiment_strings) { | 71 void SetExperimentList(const std::vector<string16>& experiment_strings) { |
72 std::vector<const wchar_t*> cstrings; | 72 std::vector<const wchar_t*> cstrings; |
73 StringVectorToCStringVector(experiment_strings, &cstrings); | 73 StringVectorToCStringVector(experiment_strings, &cstrings); |
74 ::SetExperimentList2(&cstrings[0], cstrings.size()); | 74 ::SetExperimentList2(&cstrings[0], cstrings.size()); |
75 } | 75 } |
76 | 76 |
77 } // namespace testing | 77 } // namespace testing |
OLD | NEW |