| 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/common/child_process_logging.h" | 5 #include "chrome/common/child_process_logging.h" |
| 6 | 6 |
| 7 #import <Foundation/Foundation.h> | 7 #import <Foundation/Foundation.h> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
| 11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 13 #include "base/strings/sys_string_conversions.h" | 13 #include "base/strings/sys_string_conversions.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "chrome/common/metrics/variations/variations_util.h" | 15 #include "chrome/common/metrics/variations/variations_util.h" |
| 16 #include "chrome/installer/util/google_update_settings.h" | 16 #include "chrome/installer/util/google_update_settings.h" |
| 17 | 17 |
| 18 namespace child_process_logging { | 18 namespace child_process_logging { |
| 19 | 19 |
| 20 using base::debug::SetCrashKeyValueFuncT; | 20 using base::debug::SetCrashKeyValueFuncT; |
| 21 using base::debug::ClearCrashKeyValueFuncT; | 21 using base::debug::ClearCrashKeyValueFuncT; |
| 22 using base::debug::SetCrashKeyValue; | 22 using base::debug::SetCrashKeyValue; |
| 23 using base::debug::ClearCrashKey; | 23 using base::debug::ClearCrashKey; |
| 24 | 24 |
| 25 const char* kGuidParamName = "guid"; | 25 const char* kGuidParamName = "guid"; |
| 26 const char* kPrinterInfoNameFormat = "prn-info-%zu"; | |
| 27 | 26 |
| 28 // Account for the terminating null character. | 27 // Account for the terminating null character. |
| 29 static const size_t kClientIdSize = 32 + 1; | 28 static const size_t kClientIdSize = 32 + 1; |
| 30 static char g_client_id[kClientIdSize]; | 29 static char g_client_id[kClientIdSize]; |
| 31 | 30 |
| 32 void SetClientIdImpl(const std::string& client_id, | 31 void SetClientIdImpl(const std::string& client_id, |
| 33 SetCrashKeyValueFuncT set_key_func) { | 32 SetCrashKeyValueFuncT set_key_func) { |
| 34 set_key_func(kGuidParamName, client_id); | 33 set_key_func(kGuidParamName, client_id); |
| 35 } | 34 } |
| 36 | 35 |
| 37 void SetClientId(const std::string& client_id) { | 36 void SetClientId(const std::string& client_id) { |
| 38 std::string str(client_id); | 37 std::string str(client_id); |
| 39 ReplaceSubstringsAfterOffset(&str, 0, "-", ""); | 38 ReplaceSubstringsAfterOffset(&str, 0, "-", ""); |
| 40 | 39 |
| 41 base::strlcpy(g_client_id, str.c_str(), kClientIdSize); | 40 base::strlcpy(g_client_id, str.c_str(), kClientIdSize); |
| 42 SetClientIdImpl(str, SetCrashKeyValue); | 41 SetClientIdImpl(str, SetCrashKeyValue); |
| 43 | 42 |
| 44 std::wstring wstr = ASCIIToWide(str); | 43 std::wstring wstr = ASCIIToWide(str); |
| 45 GoogleUpdateSettings::SetMetricsId(wstr); | 44 GoogleUpdateSettings::SetMetricsId(wstr); |
| 46 } | 45 } |
| 47 | 46 |
| 48 std::string GetClientId() { | 47 std::string GetClientId() { |
| 49 return std::string(g_client_id); | 48 return std::string(g_client_id); |
| 50 } | 49 } |
| 51 | 50 |
| 52 void SetPrinterInfo(const char* printer_info) { | |
| 53 std::vector<std::string> info; | |
| 54 base::SplitString(printer_info, ';', &info); | |
| 55 info.resize(kMaxReportedPrinterRecords); | |
| 56 for (size_t i = 0; i < info.size(); ++i) { | |
| 57 std::string key = base::StringPrintf(kPrinterInfoNameFormat, i); | |
| 58 if (!info[i].empty()) { | |
| 59 SetCrashKeyValue(key, info[i]); | |
| 60 } else { | |
| 61 ClearCrashKey(key); | |
| 62 } | |
| 63 } | |
| 64 } | |
| 65 | |
| 66 void SetCommandLine(const CommandLine* command_line) { | 51 void SetCommandLine(const CommandLine* command_line) { |
| 67 DCHECK(command_line); | 52 DCHECK(command_line); |
| 68 if (!command_line) | 53 if (!command_line) |
| 69 return; | 54 return; |
| 70 | 55 |
| 71 // These should match the corresponding strings in breakpad_win.cc. | 56 // These should match the corresponding strings in breakpad_win.cc. |
| 72 const char* kNumSwitchesKey = "num-switches"; | 57 const char* kNumSwitchesKey = "num-switches"; |
| 73 const char* kSwitchKeyFormat = "switch-%zu"; // 1-based. | 58 const char* kSwitchKeyFormat = "switch-%zu"; // 1-based. |
| 74 | 59 |
| 75 // Note the total number of switches, not including the exec path. | 60 // Note the total number of switches, not including the exec path. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 | 97 |
| 113 // Make note of the total number of experiments, which may be greater than | 98 // Make note of the total number of experiments, which may be greater than |
| 114 // what was able to fit in |kMaxReportedVariationChunks|. This is useful when | 99 // what was able to fit in |kMaxReportedVariationChunks|. This is useful when |
| 115 // correlating stability with the number of experiments running | 100 // correlating stability with the number of experiments running |
| 116 // simultaneously. | 101 // simultaneously. |
| 117 SetCrashKeyValue(kNumExperimentsKey, | 102 SetCrashKeyValue(kNumExperimentsKey, |
| 118 base::StringPrintf("%zu", experiments.size())); | 103 base::StringPrintf("%zu", experiments.size())); |
| 119 } | 104 } |
| 120 | 105 |
| 121 } // namespace child_process_logging | 106 } // namespace child_process_logging |
| OLD | NEW |