Home | History | Annotate | Download | only in common
      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
      3 // found in the LICENSE file.
      4 
      5 #include "chrome/common/child_process_logging.h"
      6 
      7 #include "base/string_number_conversions.h"
      8 #include "base/string_util.h"
      9 #include "base/utf_string_conversions.h"
     10 #include "chrome/installer/util/google_update_settings.h"
     11 #include "content/common/gpu/gpu_info.h"
     12 #include "googleurl/src/gurl.h"
     13 
     14 namespace child_process_logging {
     15 
     16 // Account for the terminating null character.
     17 static const size_t kMaxActiveURLSize = 1024 + 1;
     18 static const size_t kClientIdSize = 32 + 1;
     19 
     20 // We use static strings to hold the most recent active url and the client
     21 // identifier. If we crash, the crash handler code will send the contents of
     22 // these strings to the browser.
     23 char g_active_url[kMaxActiveURLSize];
     24 char g_client_id[kClientIdSize];
     25 
     26 static const size_t kGpuStringSize = 32;
     27 
     28 char g_gpu_vendor_id[kGpuStringSize] = "";
     29 char g_gpu_device_id[kGpuStringSize] = "";
     30 char g_gpu_driver_ver[kGpuStringSize] = "";
     31 char g_gpu_ps_ver[kGpuStringSize] = "";
     32 char g_gpu_vs_ver[kGpuStringSize] = "";
     33 
     34 void SetActiveURL(const GURL& url) {
     35   base::strlcpy(g_active_url,
     36                 url.possibly_invalid_spec().c_str(),
     37                 kMaxActiveURLSize);
     38 }
     39 
     40 void SetClientId(const std::string& client_id) {
     41   std::string str(client_id);
     42   ReplaceSubstringsAfterOffset(&str, 0, "-", "");
     43 
     44   if (str.empty())
     45     return;
     46 
     47   base::strlcpy(g_client_id, str.c_str(), kClientIdSize);
     48   std::wstring wstr = ASCIIToWide(str);
     49   GoogleUpdateSettings::SetMetricsId(wstr);
     50 }
     51 
     52 std::string GetClientId() {
     53   return std::string(g_client_id);
     54 }
     55 
     56 void SetActiveExtensions(const std::set<std::string>& extension_ids) {
     57   // TODO(port)
     58 }
     59 
     60 void SetGpuInfo(const GPUInfo& gpu_info) {
     61   snprintf(g_gpu_vendor_id, kGpuStringSize, "0x%04x", gpu_info.vendor_id);
     62   snprintf(g_gpu_device_id, kGpuStringSize, "0x%04x", gpu_info.device_id);
     63   strncpy(g_gpu_driver_ver,
     64           gpu_info.driver_version.c_str(),
     65           kGpuStringSize - 1);
     66   g_gpu_driver_ver[kGpuStringSize - 1] = '\0';
     67   strncpy(g_gpu_ps_ver,
     68           gpu_info.pixel_shader_version.c_str(),
     69           kGpuStringSize - 1);
     70   g_gpu_ps_ver[kGpuStringSize - 1] = '\0';
     71   strncpy(g_gpu_vs_ver,
     72           gpu_info.vertex_shader_version.c_str(),
     73           kGpuStringSize - 1);
     74   g_gpu_vs_ver[kGpuStringSize - 1] = '\0';
     75 }
     76 
     77 void SetNumberOfViews(int number_of_views) {
     78   // TODO(port)
     79 }
     80 
     81 }  // namespace child_process_logging
     82