1// Copyright (c) 2010 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#ifndef CHROME_COMMON_CHILD_PROCESS_LOGGING_H_
6#define CHROME_COMMON_CHILD_PROCESS_LOGGING_H_
7#pragma once
8
9#include <set>
10#include <string>
11
12#include "base/basictypes.h"
13#include "googleurl/src/gurl.h"
14
15struct GPUInfo;
16
17#if defined(OS_WIN) || defined(OS_MACOSX)
18// The maximum number of active extensions we will report.
19// Also used in chrome/app, but we define it here to avoid a common->app
20// dependency.
21static const int kMaxReportedActiveExtensions = 10;
22#endif
23
24namespace child_process_logging {
25
26#if defined(OS_LINUX)
27// These are declared here so the crash reporter can access them directly in
28// compromised context without going through the standard library.
29extern char g_active_url[];
30extern char g_client_id[];
31extern char g_gpu_vendor_id[];
32extern char g_gpu_device_id[];
33extern char g_gpu_driver_ver[];
34extern char g_gpu_ps_ver[];
35extern char g_gpu_vs_ver[];
36#endif
37
38// Sets the URL that is logged if the child process crashes. Use GURL() to clear
39// the URL.
40void SetActiveURL(const GURL& url);
41
42// Sets the Client ID that is used as GUID if a Chrome process crashes.
43void SetClientId(const std::string& client_id);
44
45// Gets the Client ID to be used as GUID for crash reporting. Returns the client
46// id in |client_id| if it's known, an empty string otherwise.
47std::string GetClientId();
48
49// Sets the list of "active" extensions in this process. We overload "active" to
50// mean different things depending on the process type:
51// - browser: all enabled extensions
52// - renderer: the unique set of extension ids from all content scripts
53// - extension: the id of each extension running in this process (there can be
54//   multiple because of process collapsing).
55void SetActiveExtensions(const std::set<std::string>& extension_ids);
56
57// Sets a number of views/tabs opened in this process.
58void SetNumberOfViews(int number_of_views);
59
60// Sets the data on the gpu to send along with crash reports.
61void SetGpuInfo(const GPUInfo& gpu_info);
62
63// Simple wrapper class that sets the active URL in it's constructor and clears
64// the active URL in the destructor.
65class ScopedActiveURLSetter {
66 public:
67  explicit ScopedActiveURLSetter(const GURL& url)  {
68    SetActiveURL(url);
69  }
70
71  ~ScopedActiveURLSetter()  {
72    SetActiveURL(GURL());
73  }
74
75 private:
76  DISALLOW_COPY_AND_ASSIGN(ScopedActiveURLSetter);
77};
78
79}  // namespace child_process_logging
80
81#if defined(OS_MACOSX) && __OBJC__
82
83@class NSString;
84
85typedef void (*SetCrashKeyValueFuncPtr)(NSString*, NSString*);
86typedef void (*ClearCrashKeyValueFuncPtr)(NSString*);
87
88namespace child_process_logging {
89void SetCrashKeyFunctions(SetCrashKeyValueFuncPtr set_key_func,
90                          ClearCrashKeyValueFuncPtr clear_key_func);
91void SetActiveURLImpl(const GURL& url,
92                      SetCrashKeyValueFuncPtr set_key_func,
93                      ClearCrashKeyValueFuncPtr clear_key_func);
94
95extern const int kMaxNumCrashURLChunks;
96extern const int kMaxNumURLChunkValueLength;
97extern const char *kUrlChunkFormatStr;
98}  // namespace child_process_logging
99
100#endif  // defined(OS_MACOSX) && __OBJC__
101
102#endif  // CHROME_COMMON_CHILD_PROCESS_LOGGING_H_
103