Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: chrome/common/child_process_logging_mac.mm

Issue 7849011: Refactor Mac crash key reporting - move to base/mac/crash_logging.{h,mm} (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix review comments Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/string_number_conversions.h" 9 #include "base/string_number_conversions.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
11 #include "base/stringprintf.h" 11 #include "base/stringprintf.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "chrome/installer/util/google_update_settings.h" 13 #include "chrome/installer/util/google_update_settings.h"
14 #include "content/common/gpu/gpu_info.h" 14 #include "content/common/gpu/gpu_info.h"
15 #include "googleurl/src/gurl.h" 15 #include "googleurl/src/gurl.h"
16 16
17 namespace child_process_logging { 17 namespace child_process_logging {
18 18
19 using base::mac::SetCrashKeyValueFuncPtr;
20 using base::mac::ClearCrashKeyValueFuncPtr;
21 using base::mac::SetCrashKeyValue;
22 using base::mac::ClearCrashKey;
23
19 const int kMaxNumCrashURLChunks = 8; 24 const int kMaxNumCrashURLChunks = 8;
20 const int kMaxNumURLChunkValueLength = 255; 25 const int kMaxNumURLChunkValueLength = 255;
21 const char *kUrlChunkFormatStr = "url-chunk-%d"; 26 const char *kUrlChunkFormatStr = "url-chunk-%d";
22 const char *kGuidParamName = "guid"; 27 const char *kGuidParamName = "guid";
23 const char *kGPUVendorIdParamName = "gpu-vendid"; 28 const char *kGPUVendorIdParamName = "gpu-vendid";
24 const char *kGPUDeviceIdParamName = "gpu-devid"; 29 const char *kGPUDeviceIdParamName = "gpu-devid";
25 const char *kGPUDriverVersionParamName = "gpu-driver"; 30 const char *kGPUDriverVersionParamName = "gpu-driver";
26 const char *kGPUPixelShaderVersionParamName = "gpu-psver"; 31 const char *kGPUPixelShaderVersionParamName = "gpu-psver";
27 const char *kGPUVertexShaderVersionParamName = "gpu-vsver"; 32 const char *kGPUVertexShaderVersionParamName = "gpu-vsver";
28 const char *kGPUGLVersionParamName = "gpu-glver"; 33 const char *kGPUGLVersionParamName = "gpu-glver";
29 const char *kNumberOfViews = "num-views"; 34 const char *kNumberOfViews = "num-views";
30 NSString* const kNumExtensionsName = @"num-extensions"; 35 NSString* const kNumExtensionsName = @"num-extensions";
31 NSString* const kExtensionNameFormat = @"extension-%d"; 36 NSString* const kExtensionNameFormat = @"extension-%d";
32 37
33 static SetCrashKeyValueFuncPtr g_set_key_func;
34 static ClearCrashKeyValueFuncPtr g_clear_key_func;
35
36 // Account for the terminating null character. 38 // Account for the terminating null character.
37 static const size_t kClientIdSize = 32 + 1; 39 static const size_t kClientIdSize = 32 + 1;
38 static char g_client_id[kClientIdSize]; 40 static char g_client_id[kClientIdSize];
39 41
40 void SetCrashKeyFunctions(SetCrashKeyValueFuncPtr set_key_func,
41 ClearCrashKeyValueFuncPtr clear_key_func) {
42 g_set_key_func = set_key_func;
43 g_clear_key_func = clear_key_func;
44 }
45
46 void SetActiveURLImpl(const GURL& url, 42 void SetActiveURLImpl(const GURL& url,
47 SetCrashKeyValueFuncPtr set_key_func, 43 SetCrashKeyValueFuncPtr set_key_func,
48 ClearCrashKeyValueFuncPtr clear_key_func) { 44 ClearCrashKeyValueFuncPtr clear_key_func) {
49 45
50 NSString *kUrlChunkFormatStr_utf8 = [NSString 46 NSString *kUrlChunkFormatStr_utf8 = [NSString
51 stringWithUTF8String:kUrlChunkFormatStr]; 47 stringWithUTF8String:kUrlChunkFormatStr];
52 48
53 // First remove any old url chunks we might have lying around. 49 // First remove any old url chunks we might have lying around.
54 for (int i = 0; i < kMaxNumCrashURLChunks; i++) { 50 for (int i = 0; i < kMaxNumCrashURLChunks; i++) {
55 // On Windows the url-chunk items are 1-based, so match that. 51 // On Windows the url-chunk items are 1-based, so match that.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 } 83 }
88 84
89 void SetClientIdImpl(const std::string& client_id, 85 void SetClientIdImpl(const std::string& client_id,
90 SetCrashKeyValueFuncPtr set_key_func) { 86 SetCrashKeyValueFuncPtr set_key_func) {
91 NSString *key = [NSString stringWithUTF8String:kGuidParamName]; 87 NSString *key = [NSString stringWithUTF8String:kGuidParamName];
92 NSString *value = [NSString stringWithUTF8String:client_id.c_str()]; 88 NSString *value = [NSString stringWithUTF8String:client_id.c_str()];
93 set_key_func(key, value); 89 set_key_func(key, value);
94 } 90 }
95 91
96 void SetActiveURL(const GURL& url) { 92 void SetActiveURL(const GURL& url) {
97 if (g_set_key_func && g_clear_key_func) 93 SetActiveURLImpl(url, SetCrashKeyValue, ClearCrashKey);
98 SetActiveURLImpl(url, g_set_key_func, g_clear_key_func);
99 } 94 }
100 95
101 void SetClientId(const std::string& client_id) { 96 void SetClientId(const std::string& client_id) {
102 std::string str(client_id); 97 std::string str(client_id);
103 ReplaceSubstringsAfterOffset(&str, 0, "-", ""); 98 ReplaceSubstringsAfterOffset(&str, 0, "-", "");
104 99
105 base::strlcpy(g_client_id, str.c_str(), kClientIdSize); 100 base::strlcpy(g_client_id, str.c_str(), kClientIdSize);
106 if (g_set_key_func) 101 SetClientIdImpl(str, SetCrashKeyValue);
107 SetClientIdImpl(str, g_set_key_func);
108 102
109 std::wstring wstr = ASCIIToWide(str); 103 std::wstring wstr = ASCIIToWide(str);
110 GoogleUpdateSettings::SetMetricsId(wstr); 104 GoogleUpdateSettings::SetMetricsId(wstr);
111 } 105 }
112 106
113 std::string GetClientId() { 107 std::string GetClientId() {
114 return std::string(g_client_id); 108 return std::string(g_client_id);
115 } 109 }
116 110
117 void SetActiveExtensions(const std::set<std::string>& extension_ids) { 111 void SetActiveExtensions(const std::set<std::string>& extension_ids) {
118 if (!g_set_key_func)
119 return;
120
121 // Log the count separately to track heavy users. 112 // Log the count separately to track heavy users.
122 const int count = static_cast<int>(extension_ids.size()); 113 const int count = static_cast<int>(extension_ids.size());
123 g_set_key_func(kNumExtensionsName, [NSString stringWithFormat:@"%i", count]); 114 SetCrashKeyValue(kNumExtensionsName,
115 [NSString stringWithFormat:@"%i", count]);
124 116
125 // Record up to |kMaxReportedActiveExtensions| extensions, clearing 117 // Record up to |kMaxReportedActiveExtensions| extensions, clearing
126 // keys if there aren't that many. 118 // keys if there aren't that many.
127 std::set<std::string>::const_iterator iter = extension_ids.begin(); 119 std::set<std::string>::const_iterator iter = extension_ids.begin();
128 for (int i = 0; i < kMaxReportedActiveExtensions; ++i) { 120 for (int i = 0; i < kMaxReportedActiveExtensions; ++i) {
129 NSString* key = [NSString stringWithFormat:kExtensionNameFormat, i]; 121 NSString* key = [NSString stringWithFormat:kExtensionNameFormat, i];
130 if (iter != extension_ids.end()) { 122 if (iter != extension_ids.end()) {
131 g_set_key_func(key, [NSString stringWithUTF8String:iter->c_str()]); 123 SetCrashKeyValue(key, [NSString stringWithUTF8String:iter->c_str()]);
132 ++iter; 124 ++iter;
133 } else { 125 } else {
134 g_clear_key_func(key); 126 ClearCrashKey(key);
135 } 127 }
136 } 128 }
137 } 129 }
138 130
139 void SetGpuKeyValue(const char* param_name, const std::string& value_str, 131 void SetGpuKeyValue(const char* param_name, const std::string& value_str,
140 SetCrashKeyValueFuncPtr set_key_func) { 132 SetCrashKeyValueFuncPtr set_key_func) {
141 NSString *key = [NSString stringWithUTF8String:param_name]; 133 NSString *key = [NSString stringWithUTF8String:param_name];
142 NSString *value = [NSString stringWithUTF8String:value_str.c_str()]; 134 NSString *value = [NSString stringWithUTF8String:value_str.c_str()];
143 set_key_func(key, value); 135 set_key_func(key, value);
144 } 136 }
(...skipping 14 matching lines...) Expand all
159 set_key_func); 151 set_key_func);
160 SetGpuKeyValue(kGPUVertexShaderVersionParamName, 152 SetGpuKeyValue(kGPUVertexShaderVersionParamName,
161 gpu_info.vertex_shader_version, 153 gpu_info.vertex_shader_version,
162 set_key_func); 154 set_key_func);
163 SetGpuKeyValue(kGPUGLVersionParamName, 155 SetGpuKeyValue(kGPUGLVersionParamName,
164 gpu_info.gl_version, 156 gpu_info.gl_version,
165 set_key_func); 157 set_key_func);
166 } 158 }
167 159
168 void SetGpuInfo(const GPUInfo& gpu_info) { 160 void SetGpuInfo(const GPUInfo& gpu_info) {
169 if (g_set_key_func) 161 SetGpuInfoImpl(gpu_info, SetCrashKeyValue);
170 SetGpuInfoImpl(gpu_info, g_set_key_func);
171 } 162 }
172 163
173 164
174 void SetNumberOfViewsImpl(int number_of_views, 165 void SetNumberOfViewsImpl(int number_of_views,
175 SetCrashKeyValueFuncPtr set_key_func) { 166 SetCrashKeyValueFuncPtr set_key_func) {
176 NSString *key = [NSString stringWithUTF8String:kNumberOfViews]; 167 NSString *key = [NSString stringWithUTF8String:kNumberOfViews];
177 NSString *value = [NSString stringWithFormat:@"%d", number_of_views]; 168 NSString *value = [NSString stringWithFormat:@"%d", number_of_views];
178 set_key_func(key, value); 169 set_key_func(key, value);
179 } 170 }
180 171
181 void SetNumberOfViews(int number_of_views) { 172 void SetNumberOfViews(int number_of_views) {
182 if (g_set_key_func) 173 SetNumberOfViewsImpl(number_of_views, SetCrashKeyValue);
183 SetNumberOfViewsImpl(number_of_views, g_set_key_func);
184 } 174 }
185 175
186 } // namespace child_process_logging 176 } // namespace child_process_logging
OLDNEW
« no previous file with comments | « chrome/common/child_process_logging.h ('k') | chrome/common/child_process_logging_mac_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698