blob: a53b4ed032370f87f8638c182f78b1c80c119619 [file] [log] [blame]
[email protected]fcf19542009-03-30 21:24:071// 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]ef916272009-07-08 21:40:555#include "chrome/common/child_process_logging.h"
[email protected]fcf19542009-03-30 21:24:076
7#import <Foundation/Foundation.h>
8
[email protected]528c56d2010-07-30 19:28:449#include "base/string_number_conversions.h"
[email protected]fcf19542009-03-30 21:24:0710#include "base/string_util.h"
[email protected]528c56d2010-07-30 19:28:4411#include "base/utf_string_conversions.h"
[email protected]a110dd12010-07-19 07:51:3312#include "chrome/common/gpu_info.h"
[email protected]157d5472009-11-05 22:31:0313#include "chrome/installer/util/google_update_settings.h"
[email protected]fcf19542009-03-30 21:24:0714#include "googleurl/src/gurl.h"
[email protected]fcf19542009-03-30 21:24:0715
[email protected]ef916272009-07-08 21:40:5516namespace child_process_logging {
[email protected]fcf19542009-03-30 21:24:0717
18const int kMaxNumCrashURLChunks = 8;
19const int kMaxNumURLChunkValueLength = 255;
20const char *kUrlChunkFormatStr = "url-chunk-%d";
[email protected]157d5472009-11-05 22:31:0321const char *kGuidParamName = "guid";
[email protected]a110dd12010-07-19 07:51:3322const char *kGPUVendorIdParamName = "vendid";
23const char *kGPUDeviceIdParamName = "devid";
24const char *kGPUDriverVersionParamName = "driver";
25const char *kGPUPixelShaderVersionParamName = "psver";
26const char *kGPUVertexShaderVersionParamName = "vsver";
[email protected]fcf19542009-03-30 21:24:0727
[email protected]35941fd2009-07-09 01:55:4328static SetCrashKeyValueFuncPtr g_set_key_func;
29static ClearCrashKeyValueFuncPtr g_clear_key_func;
30
31void 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]ef916272009-07-08 21:40:5537void SetActiveURLImpl(const GURL& url,
38 SetCrashKeyValueFuncPtr set_key_func,
39 ClearCrashKeyValueFuncPtr clear_key_func) {
[email protected]fcf19542009-03-30 21:24:0740
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]157d5472009-11-05 22:31:0380void 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]ef916272009-07-08 21:40:5587void SetActiveURL(const GURL& url) {
[email protected]35941fd2009-07-09 01:55:4388 if (g_set_key_func && g_clear_key_func)
89 SetActiveURLImpl(url, g_set_key_func, g_clear_key_func);
[email protected]fcf19542009-03-30 21:24:0790}
91
[email protected]157d5472009-11-05 22:31:0392void 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]aab98a52009-12-02 03:22:35102
[email protected]c8865962009-12-16 07:47:39103void SetActiveExtensions(const std::set<std::string>& extension_ids) {
[email protected]aab98a52009-12-02 03:22:35104 // TODO(port)
105}
106
[email protected]a110dd12010-07-19 07:51:33107void 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
114void SetGpuInfoImpl(const GPUInfo& gpu_info,
115 SetCrashKeyValueFuncPtr set_key_func) {
116 SetGpuKeyValue(kGPUVendorIdParamName,
[email protected]528c56d2010-07-30 19:28:44117 base::UintToString(gpu_info.vendor_id()),
[email protected]a110dd12010-07-19 07:51:33118 set_key_func);
119 SetGpuKeyValue(kGPUDeviceIdParamName,
[email protected]528c56d2010-07-30 19:28:44120 base::UintToString(gpu_info.device_id()),
[email protected]a110dd12010-07-19 07:51:33121 set_key_func);
122 SetGpuKeyValue(kGPUDriverVersionParamName,
[email protected]528c56d2010-07-30 19:28:44123 WideToUTF8(gpu_info.driver_version()),
[email protected]a110dd12010-07-19 07:51:33124 set_key_func);
125 SetGpuKeyValue(kGPUPixelShaderVersionParamName,
[email protected]528c56d2010-07-30 19:28:44126 base::UintToString(gpu_info.pixel_shader_version()),
[email protected]a110dd12010-07-19 07:51:33127 set_key_func);
128 SetGpuKeyValue(kGPUVertexShaderVersionParamName,
[email protected]528c56d2010-07-30 19:28:44129 base::UintToString(gpu_info.vertex_shader_version()),
[email protected]a110dd12010-07-19 07:51:33130 set_key_func);
131}
132
133void SetGpuInfo(const GPUInfo& gpu_info) {
134 if (g_set_key_func)
135 SetGpuInfoImpl(gpu_info, g_set_key_func);
136}
137
[email protected]ef916272009-07-08 21:40:55138} // namespace child_process_logging