Home | History | Annotate | Download | only in common
      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
      3 // found in the LICENSE file.
      4 
      5 #ifndef CHROME_COMMON_CHILD_PROCESS_LOGGING_H_
      6 #define CHROME_COMMON_CHILD_PROCESS_LOGGING_H_
      7 
      8 #include <set>
      9 #include <string>
     10 #include <vector>
     11 
     12 #include "base/basictypes.h"
     13 #include "base/debug/crash_logging.h"
     14 #include "base/strings/string16.h"
     15 #include "url/gurl.h"
     16 
     17 class CommandLine;
     18 
     19 namespace gpu {
     20 struct GPUInfo;
     21 }
     22 
     23 // The maximum number of active extensions we will report.
     24 // Also used in chrome/app, but we define it here to avoid a common->app
     25 // dependency.
     26 static const size_t kMaxReportedActiveExtensions = 10;
     27 
     28 // The maximum number of variation chunks we will report.
     29 // Also used in chrome/app, but we define it here to avoid a common->app
     30 // dependency.
     31 static const size_t kMaxReportedVariationChunks = 15;
     32 
     33 // The maximum size of a variation chunk. This size was picked to be
     34 // consistent between platforms and the value was chosen from the Windows
     35 // limit of google_breakpad::CustomInfoEntry::kValueMaxLength.
     36 static const size_t kMaxVariationChunkSize = 64;
     37 
     38 // The maximum number of prn-info-* records.
     39 static const size_t kMaxReportedPrinterRecords = 4;
     40 
     41 // The maximum number of command line switches to include in the crash
     42 // report's metadata. Note that the mini-dump itself will also contain the
     43 // (original) command line arguments within the PEB.
     44 // Also used in chrome/app, but we define it here to avoid a common->app
     45 // dependency.
     46 static const size_t kMaxSwitches = 15;
     47 
     48 namespace child_process_logging {
     49 
     50 #if defined(OS_POSIX) && !defined(OS_MACOSX)
     51 // These are declared here so the crash reporter can access them directly in
     52 // compromised context without going through the standard library.
     53 extern char g_active_url[];
     54 extern char g_channel[];
     55 extern char g_client_id[];
     56 extern char g_extension_ids[];
     57 extern char g_gpu_vendor_id[];
     58 extern char g_gpu_device_id[];
     59 extern char g_gpu_gl_vendor[];
     60 extern char g_gpu_gl_renderer[];
     61 extern char g_gpu_driver_ver[];
     62 extern char g_gpu_ps_ver[];
     63 extern char g_gpu_vs_ver[];
     64 extern char g_num_extensions[];
     65 extern char g_num_switches[];
     66 extern char g_num_variations[];
     67 extern char g_num_views[];
     68 extern char g_printer_info[];
     69 extern char g_switches[];
     70 extern char g_variation_chunks[];
     71 
     72 // Assume IDs are 32 bytes long.
     73 static const size_t kExtensionLen = 32;
     74 
     75 // Assume command line switches are less than 64 chars.
     76 static const size_t kSwitchLen = 64;
     77 
     78 // Assume printer info strings are less than 64 chars.
     79 static const size_t kPrinterInfoStrLen = 64;
     80 #endif
     81 
     82 // Sets the URL that is logged if the child process crashes. Use GURL() to clear
     83 // the URL.
     84 void SetActiveURL(const GURL& url);
     85 
     86 // Sets the Client ID that is used as GUID if a Chrome process crashes.
     87 void SetClientId(const std::string& client_id);
     88 
     89 // Gets the Client ID to be used as GUID for crash reporting. Returns the client
     90 // id in |client_id| if it's known, an empty string otherwise.
     91 std::string GetClientId();
     92 
     93 // Sets the list of "active" extensions in this process. We overload "active" to
     94 // mean different things depending on the process type:
     95 // - browser: all enabled extensions
     96 // - renderer: the unique set of extension ids from all content scripts
     97 // - extension: the id of each extension running in this process (there can be
     98 //   multiple because of process collapsing).
     99 void SetActiveExtensions(const std::set<std::string>& extension_ids);
    100 
    101 // Sets a number of views/tabs opened in this process.
    102 void SetNumberOfViews(int number_of_views);
    103 
    104 // Sets the data on the gpu to send along with crash reports.
    105 void SetGpuInfo(const gpu::GPUInfo& gpu_info);
    106 
    107 // Sets the data on the printer to send along with crash reports. Data may be
    108 // separated by ';' up to kMaxReportedPrinterRecords strings. Each substring
    109 // would be cut to 63 chars.
    110 void SetPrinterInfo(const char* printer_info);
    111 
    112 // Sets the command line arguments to send along with crash reports to the
    113 // values in |command_line|.
    114 void SetCommandLine(const CommandLine* command_line);
    115 
    116 // Initialize the list of experiment info to send along with crash reports.
    117 void SetExperimentList(const std::vector<string16>& state);
    118 
    119 #if defined(OS_LINUX) || defined(OS_OPENBSD) || defined(OS_MACOSX)
    120 // Sets the product channel data to send along with crash reports to |channel|.
    121 void SetChannel(const std::string& channel);
    122 #endif
    123 
    124 // Simple wrapper class that sets the active URL in it's constructor and clears
    125 // the active URL in the destructor.
    126 class ScopedActiveURLSetter {
    127  public:
    128   explicit ScopedActiveURLSetter(const GURL& url)  {
    129     SetActiveURL(url);
    130   }
    131 
    132   ~ScopedActiveURLSetter()  {
    133     SetActiveURL(GURL());
    134   }
    135 
    136  private:
    137   DISALLOW_COPY_AND_ASSIGN(ScopedActiveURLSetter);
    138 };
    139 
    140 // Set/clear information about currently accessed printer.
    141 class ScopedPrinterInfoSetter {
    142  public:
    143   explicit ScopedPrinterInfoSetter(const std::string& printer_info) {
    144     SetPrinterInfo(printer_info.c_str());
    145   }
    146 
    147   ~ScopedPrinterInfoSetter() {
    148     SetPrinterInfo("");
    149   }
    150 
    151  private:
    152   DISALLOW_COPY_AND_ASSIGN(ScopedPrinterInfoSetter);
    153 };
    154 
    155 }  // namespace child_process_logging
    156 
    157 #if defined(OS_MACOSX)
    158 
    159 namespace child_process_logging {
    160 
    161 void SetActiveURLImpl(const GURL& url,
    162                       base::debug::SetCrashKeyValueFuncT set_key_func,
    163                       base::debug::ClearCrashKeyValueFuncT clear_key_func);
    164 
    165 extern const size_t kMaxNumCrashURLChunks;
    166 extern const size_t kMaxNumURLChunkValueLength;
    167 extern const char* kUrlChunkFormatStr;
    168 
    169 }  // namespace child_process_logging
    170 
    171 #endif  // defined(OS_MACOSX)
    172 
    173 #endif  // CHROME_COMMON_CHILD_PROCESS_LOGGING_H_
    174