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 3 // found in the LICENSE file. 4 5 #include "chrome/app/breakpad_field_trial_win.h" 6 7 #include "base/lazy_instance.h" 8 #include "base/strings/string16.h" 9 #include "base/strings/string_util.h" 10 #include "base/strings/stringprintf.h" 11 #include "breakpad/src/client/windows/common/ipc_protocol.h" 12 #include "chrome/app/breakpad_win.h" 13 #include "chrome/common/child_process_logging.h" 14 15 // Sets the breakpad experiment chunks for crash reporting. |chunks| is an 16 // array of C strings of size |chunk_size| containing the values to set, where 17 // each entry may contain multiple experiment tuples, with the total number of 18 // experiments indicated by |experiments_chunks|. 19 // Note that this is suffixed with "3" due to parameter changes that were made 20 // to the predecessor functions. If the signature changes again, use a new name. 21 extern "C" void __declspec(dllexport) __cdecl SetExperimentList3( 22 const wchar_t** chunks, 23 size_t chunks_size, 24 size_t experiments_count) { 25 // Make sure the offset was initialized before storing the data. 26 if (breakpad_win::g_experiment_chunks_offset == 0) 27 return; 28 29 // Store up to |kMaxReportedVariationChunks| chunks. 30 const size_t number_of_chunks_to_report = 31 std::min(chunks_size, kMaxReportedVariationChunks); 32 for (size_t i = 0; i < number_of_chunks_to_report; ++i) { 33 const size_t entry_index = breakpad_win::g_experiment_chunks_offset + i; 34 (*breakpad_win::g_custom_entries)[entry_index].set_value(chunks[i]); 35 } 36 37 // Make note of the total number of experiments, which may be greater than 38 // what was able to fit in |kMaxReportedVariationChunks|. This is useful when 39 // correlating stability with the number of experiments running 40 // simultaneously. 41 base::wcslcpy( 42 (*breakpad_win::g_custom_entries)[ 43 breakpad_win::g_num_of_experiments_offset].value, 44 base::StringPrintf( 45 L"%d", static_cast<int>(experiments_count)).c_str(), 46 google_breakpad::CustomInfoEntry::kValueMaxLength); 47 } 48 49 namespace testing { 50 51 void SetExperimentChunks(const std::vector<string16>& chunks, 52 size_t experiments_count) { 53 std::vector<const wchar_t*> cstrings; 54 StringVectorToCStringVector(chunks, &cstrings); 55 ::SetExperimentList3(&cstrings[0], cstrings.size(), experiments_count); 56 } 57 58 } // namespace testing 59