Coverage for /Syzygy/kasko/api/reporter.cc

CoverageLines executed / instrumented / missingexe / inst / missLanguageGroup
85.4%35410.C++source

Line-by-line coverage:

   1    :  // Copyright 2014 Google Inc. All Rights Reserved.
   2    :  //
   3    :  // Licensed under the Apache License, Version 2.0 (the "License");
   4    :  // you may not use this file except in compliance with the License.
   5    :  // You may obtain a copy of the License at
   6    :  //
   7    :  //     http://www.apache.org/licenses/LICENSE-2.0
   8    :  //
   9    :  // Unless required by applicable law or agreed to in writing, software
  10    :  // distributed under the License is distributed on an "AS IS" BASIS,
  11    :  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12    :  // See the License for the specific language governing permissions and
  13    :  // limitations under the License.
  14    :  
  15    :  #include "syzygy/kasko/api/reporter.h"
  16    :  
  17    :  #include <stdint.h>
  18    :  
  19    :  #include "base/logging.h"
  20    :  #include "base/files/file_path.h"
  21    :  #include "base/memory/scoped_ptr.h"
  22    :  #include "base/time/time.h"
  23    :  #include "syzygy/kasko/dll_lifetime.h"
  24    :  #include "syzygy/kasko/reporter.h"
  25    :  
  26    :  namespace kasko {
  27    :  namespace api {
  28    :  namespace {
  29    :  
  30    :  const uint16_t kUploadDelayInSeconds = 180;
  31    :  const uint16_t kRetryIntevalInMinutes = 180;
  32    :  
  33    :  const DllLifetime* g_dll_lifetime;
  34    :  Reporter* g_reporter;
  35    :  
  36    :  }  // namespace
  37    :  
  38    :  const base::char16* const kPermanentFailureCrashKeysExtension =
  39  E :      Reporter::kPermanentFailureCrashKeysExtension;
  40    :  const base::char16* const kPermanentFailureMinidumpExtension =
  41  E :      Reporter::kPermanentFailureMinidumpExtension;
  42    :  
  43    :  bool InitializeReporter(
  44    :      const base::char16* endpoint_name,
  45    :      const base::char16* url,
  46    :      const base::char16* data_directory,
  47  E :      const base::char16* permanent_failure_directory) {
  48  E :    DCHECK(!g_dll_lifetime);
  49  E :    g_dll_lifetime = new DllLifetime;
  50    :  
  51  E :    DCHECK(!g_reporter);
  52    :    g_reporter =
  53    :        Reporter::Create(endpoint_name, url, base::FilePath(data_directory),
  54    :                         base::FilePath(permanent_failure_directory),
  55    :                         base::TimeDelta::FromSeconds(kUploadDelayInSeconds),
  56    :                         base::TimeDelta::FromMinutes(kRetryIntevalInMinutes))
  57  E :            .release();
  58  E :    return g_reporter != nullptr;
  59  E :  }
  60    :  
  61    :  void SendReportForProcess(base::ProcessHandle process_handle,
  62    :                            MinidumpType minidump_type,
  63    :                            const base::char16* const* keys,
  64  E :                            const base::char16* const* values) {
  65  E :    DCHECK(g_reporter);
  66  E :    if (!g_reporter)
  67  i :      return;
  68  E :    DCHECK_EQ(keys == nullptr, values == nullptr);
  69    :  
  70  E :    std::map<base::string16, base::string16> crash_keys;
  71  E :    if (keys != nullptr && values != nullptr) {
  72  E :      size_t i = 0;
  73  E :      for (; keys[i] && values[i]; ++i) {
  74  E :        crash_keys[keys[i]] = values[i];
  75  E :      }
  76  E :      DCHECK(!keys[i]);
  77  E :      DCHECK(!values[i]);
  78    :    }
  79    :  
  80  E :    kasko::MinidumpType internal_minidump_type = kasko::SMALL_DUMP_TYPE;
  81  E :    switch (minidump_type) {
  82    :      case SMALL_DUMP_TYPE:
  83  E :        internal_minidump_type = kasko::SMALL_DUMP_TYPE;
  84  E :        break;
  85    :      case LARGER_DUMP_TYPE:
  86  i :        internal_minidump_type = kasko::LARGER_DUMP_TYPE;
  87  i :        break;
  88    :      case FULL_DUMP_TYPE:
  89  i :        internal_minidump_type = kasko::FULL_DUMP_TYPE;
  90  i :        break;
  91    :      default:
  92  i :        NOTREACHED();
  93    :        break;
  94    :    }
  95    :  
  96    :    g_reporter->SendReportForProcess(process_handle, internal_minidump_type,
  97  E :                                     crash_keys);
  98  E :  }
  99    :  
 100  E :  void ShutdownReporter() {
 101  E :    scoped_ptr<Reporter> reporter(g_reporter);
 102  E :    g_reporter = nullptr;
 103  E :    Reporter::Shutdown(reporter.Pass());
 104    :  
 105  E :    DCHECK(g_dll_lifetime);
 106  E :    delete g_dll_lifetime;
 107  E :    g_dll_lifetime = nullptr;
 108  E :  }
 109    :  
 110    :  }  // namespace api
 111    :  }  // namespace kasko

Coverage information generated Thu Mar 26 16:15:41 2015.