[email protected] | fcf1954 | 2009-03-30 21:24:07 | [diff] [blame] | 1 | // Copyright (c) 2009 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 | |
[email protected] | ef91627 | 2009-07-08 21:40:55 | [diff] [blame] | 5 | #include "chrome/common/child_process_logging.h" |
[email protected] | fcf1954 | 2009-03-30 21:24:07 | [diff] [blame] | 6 | |
| 7 | #import <Foundation/Foundation.h> |
| 8 | |
[email protected] | 528c56d | 2010-07-30 19:28:44 | [diff] [blame^] | 9 | #include "base/string_number_conversions.h" |
[email protected] | fcf1954 | 2009-03-30 21:24:07 | [diff] [blame] | 10 | #include "base/string_util.h" |
[email protected] | 528c56d | 2010-07-30 19:28:44 | [diff] [blame^] | 11 | #include "base/utf_string_conversions.h" |
[email protected] | a110dd1 | 2010-07-19 07:51:33 | [diff] [blame] | 12 | #include "chrome/common/gpu_info.h" |
[email protected] | 157d547 | 2009-11-05 22:31:03 | [diff] [blame] | 13 | #include "chrome/installer/util/google_update_settings.h" |
[email protected] | fcf1954 | 2009-03-30 21:24:07 | [diff] [blame] | 14 | #include "googleurl/src/gurl.h" |
[email protected] | fcf1954 | 2009-03-30 21:24:07 | [diff] [blame] | 15 | |
[email protected] | ef91627 | 2009-07-08 21:40:55 | [diff] [blame] | 16 | namespace child_process_logging { |
[email protected] | fcf1954 | 2009-03-30 21:24:07 | [diff] [blame] | 17 | |
| 18 | const int kMaxNumCrashURLChunks = 8; |
| 19 | const int kMaxNumURLChunkValueLength = 255; |
| 20 | const char *kUrlChunkFormatStr = "url-chunk-%d"; |
[email protected] | 157d547 | 2009-11-05 22:31:03 | [diff] [blame] | 21 | const char *kGuidParamName = "guid"; |
[email protected] | a110dd1 | 2010-07-19 07:51:33 | [diff] [blame] | 22 | const char *kGPUVendorIdParamName = "vendid"; |
| 23 | const char *kGPUDeviceIdParamName = "devid"; |
| 24 | const char *kGPUDriverVersionParamName = "driver"; |
| 25 | const char *kGPUPixelShaderVersionParamName = "psver"; |
| 26 | const char *kGPUVertexShaderVersionParamName = "vsver"; |
[email protected] | fcf1954 | 2009-03-30 21:24:07 | [diff] [blame] | 27 | |
[email protected] | 35941fd | 2009-07-09 01:55:43 | [diff] [blame] | 28 | static SetCrashKeyValueFuncPtr g_set_key_func; |
| 29 | static ClearCrashKeyValueFuncPtr g_clear_key_func; |
| 30 | |
| 31 | void SetCrashKeyFunctions(SetCrashKeyValueFuncPtr set_key_func, |
| 32 | ClearCrashKeyValueFuncPtr clear_key_func) { |
| 33 | g_set_key_func = set_key_func; |
| 34 | g_clear_key_func = clear_key_func; |
| 35 | } |
| 36 | |
[email protected] | ef91627 | 2009-07-08 21:40:55 | [diff] [blame] | 37 | void SetActiveURLImpl(const GURL& url, |
| 38 | SetCrashKeyValueFuncPtr set_key_func, |
| 39 | ClearCrashKeyValueFuncPtr clear_key_func) { |
[email protected] | fcf1954 | 2009-03-30 21:24:07 | [diff] [blame] | 40 | |
| 41 | NSString *kUrlChunkFormatStr_utf8 = [NSString |
| 42 | stringWithUTF8String:kUrlChunkFormatStr]; |
| 43 | |
| 44 | // First remove any old url chunks we might have lying around. |
| 45 | for (int i = 0; i < kMaxNumCrashURLChunks; i++) { |
| 46 | // On Windows the url-chunk items are 1-based, so match that. |
| 47 | NSString *key = [NSString stringWithFormat:kUrlChunkFormatStr_utf8, i+1]; |
| 48 | clear_key_func(key); |
| 49 | } |
| 50 | |
| 51 | const std::string& raw_url_utf8 = url.possibly_invalid_spec(); |
| 52 | NSString *raw_url = [NSString stringWithUTF8String:raw_url_utf8.c_str()]; |
| 53 | size_t raw_url_length = [raw_url length]; |
| 54 | |
| 55 | // Bail on zero-length URLs. |
| 56 | if (raw_url_length == 0) { |
| 57 | return; |
| 58 | } |
| 59 | |
| 60 | // Parcel the URL up into up to 8, 255 byte segments. |
| 61 | size_t start_ofs = 0; |
| 62 | for (int i = 0; |
| 63 | i < kMaxNumCrashURLChunks && start_ofs < raw_url_length; |
| 64 | ++i) { |
| 65 | |
| 66 | // On Windows the url-chunk items are 1-based, so match that. |
| 67 | NSString *key = [NSString stringWithFormat:kUrlChunkFormatStr_utf8, i+1]; |
| 68 | NSRange range; |
| 69 | range.location = start_ofs; |
| 70 | range.length = std::min((size_t)kMaxNumURLChunkValueLength, |
| 71 | raw_url_length - start_ofs); |
| 72 | NSString *value = [raw_url substringWithRange:range]; |
| 73 | set_key_func(key, value); |
| 74 | |
| 75 | // Next chunk. |
| 76 | start_ofs += kMaxNumURLChunkValueLength; |
| 77 | } |
| 78 | } |
| 79 | |
[email protected] | 157d547 | 2009-11-05 22:31:03 | [diff] [blame] | 80 | void SetClientIdImpl(const std::string& client_id, |
| 81 | SetCrashKeyValueFuncPtr set_key_func) { |
| 82 | NSString *key = [NSString stringWithUTF8String:kGuidParamName]; |
| 83 | NSString *value = [NSString stringWithUTF8String:client_id.c_str()]; |
| 84 | set_key_func(key, value); |
| 85 | } |
| 86 | |
[email protected] | ef91627 | 2009-07-08 21:40:55 | [diff] [blame] | 87 | void SetActiveURL(const GURL& url) { |
[email protected] | 35941fd | 2009-07-09 01:55:43 | [diff] [blame] | 88 | if (g_set_key_func && g_clear_key_func) |
| 89 | SetActiveURLImpl(url, g_set_key_func, g_clear_key_func); |
[email protected] | fcf1954 | 2009-03-30 21:24:07 | [diff] [blame] | 90 | } |
| 91 | |
[email protected] | 157d547 | 2009-11-05 22:31:03 | [diff] [blame] | 92 | void SetClientId(const std::string& client_id) { |
| 93 | std::string str(client_id); |
| 94 | ReplaceSubstringsAfterOffset(&str, 0, "-", ""); |
| 95 | |
| 96 | if (g_set_key_func) |
| 97 | SetClientIdImpl(str, g_set_key_func); |
| 98 | |
| 99 | std::wstring wstr = ASCIIToWide(str); |
| 100 | GoogleUpdateSettings::SetMetricsId(wstr); |
| 101 | } |
[email protected] | aab98a5 | 2009-12-02 03:22:35 | [diff] [blame] | 102 | |
[email protected] | c886596 | 2009-12-16 07:47:39 | [diff] [blame] | 103 | void SetActiveExtensions(const std::set<std::string>& extension_ids) { |
[email protected] | aab98a5 | 2009-12-02 03:22:35 | [diff] [blame] | 104 | // TODO(port) |
| 105 | } |
| 106 | |
[email protected] | a110dd1 | 2010-07-19 07:51:33 | [diff] [blame] | 107 | void SetGpuKeyValue(const char* param_name, const std::string& value_str, |
| 108 | SetCrashKeyValueFuncPtr set_key_func) { |
| 109 | NSString *key = [NSString stringWithUTF8String:param_name]; |
| 110 | NSString *value = [NSString stringWithUTF8String:value_str.c_str()]; |
| 111 | set_key_func(key, value); |
| 112 | } |
| 113 | |
| 114 | void SetGpuInfoImpl(const GPUInfo& gpu_info, |
| 115 | SetCrashKeyValueFuncPtr set_key_func) { |
| 116 | SetGpuKeyValue(kGPUVendorIdParamName, |
[email protected] | 528c56d | 2010-07-30 19:28:44 | [diff] [blame^] | 117 | base::UintToString(gpu_info.vendor_id()), |
[email protected] | a110dd1 | 2010-07-19 07:51:33 | [diff] [blame] | 118 | set_key_func); |
| 119 | SetGpuKeyValue(kGPUDeviceIdParamName, |
[email protected] | 528c56d | 2010-07-30 19:28:44 | [diff] [blame^] | 120 | base::UintToString(gpu_info.device_id()), |
[email protected] | a110dd1 | 2010-07-19 07:51:33 | [diff] [blame] | 121 | set_key_func); |
| 122 | SetGpuKeyValue(kGPUDriverVersionParamName, |
[email protected] | 528c56d | 2010-07-30 19:28:44 | [diff] [blame^] | 123 | WideToUTF8(gpu_info.driver_version()), |
[email protected] | a110dd1 | 2010-07-19 07:51:33 | [diff] [blame] | 124 | set_key_func); |
| 125 | SetGpuKeyValue(kGPUPixelShaderVersionParamName, |
[email protected] | 528c56d | 2010-07-30 19:28:44 | [diff] [blame^] | 126 | base::UintToString(gpu_info.pixel_shader_version()), |
[email protected] | a110dd1 | 2010-07-19 07:51:33 | [diff] [blame] | 127 | set_key_func); |
| 128 | SetGpuKeyValue(kGPUVertexShaderVersionParamName, |
[email protected] | 528c56d | 2010-07-30 19:28:44 | [diff] [blame^] | 129 | base::UintToString(gpu_info.vertex_shader_version()), |
[email protected] | a110dd1 | 2010-07-19 07:51:33 | [diff] [blame] | 130 | set_key_func); |
| 131 | } |
| 132 | |
| 133 | void SetGpuInfo(const GPUInfo& gpu_info) { |
| 134 | if (g_set_key_func) |
| 135 | SetGpuInfoImpl(gpu_info, g_set_key_func); |
| 136 | } |
| 137 | |
[email protected] | ef91627 | 2009-07-08 21:40:55 | [diff] [blame] | 138 | } // namespace child_process_logging |