Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 // A wrapper around common crash reporting code to manage reporting for Chrome | 5 // A wrapper around common crash reporting code to manage reporting for Chrome |
| 6 // Frame. | 6 // Frame. |
| 7 | 7 |
| 8 #ifndef CHROME_FRAME_CHROME_FRAME_REPORTING_H_ | 8 #ifndef CHROME_FRAME_CHROME_FRAME_REPORTING_H_ |
| 9 #define CHROME_FRAME_CHROME_FRAME_REPORTING_H_ | 9 #define CHROME_FRAME_CHROME_FRAME_REPORTING_H_ |
| 10 | 10 |
| 11 #include "chrome_frame/crash_reporting/crash_report.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/synchronization/lock.h" | |
| 12 | 13 |
| 13 extern const wchar_t kSystemPrincipalSid[]; | 14 namespace base { |
| 15 template<typename Type> struct DefaultLazyInstanceTraits; | |
| 16 } | |
| 14 | 17 |
| 15 // Intialize crash reporting for Chrome Frame. Specific parameters here include | 18 class ScopedCrashReporting; |
| 16 // using the temp directory for dumps, determining if the install is system | |
| 17 // wide or user specific, and customized client info. | |
| 18 bool InitializeCrashReporting(); | |
| 19 | 19 |
| 20 // Shut down crash reporting for Chrome Frame. | 20 // Manages crash reporting for the Chrome Frame dll. Crash reporting cannot be |
| 21 bool ShutdownCrashReporting(); | 21 // reliably started or stopped when the loader lock is held, so DllMain cannot |
| 22 // be used to start/stop reporting. Rather, a global instance of this class is | |
| 23 // used. Each entrypoint into the dll must create a ScopedCrashReporting | |
| 24 // instance on the stack. Crash reporting is automatically started when the | |
| 25 // first such scoper is created and will ordinarily be stopped when the last one | |
| 26 // is destroyed. If any scoper's Commit method is invoked, crash reporting will | |
| 27 // stay running even after all scopers have gone away. This is the case when | |
| 28 // objects have been returned by DllGetClassObject. Crash reporting will | |
| 29 // continue to run until Decommit is called. | |
| 30 class CrashReportingManager { | |
| 31 public: | |
| 32 // Causes crash reporting to be shut down either immediately or when the last | |
| 33 // scoper is destroyed. | |
| 34 static void Decommit(); | |
|
robertshield
2013/03/06 13:50:32
nit: it seems slightly odd to have the public Comm
| |
| 35 | |
| 36 private: | |
| 37 friend class ScopedCrashReporting; | |
| 38 friend struct base::DefaultLazyInstanceTraits<CrashReportingManager>; | |
| 39 | |
| 40 CrashReportingManager(); | |
| 41 ~CrashReportingManager(); | |
| 42 static CrashReportingManager& Get(); | |
| 43 void AddRef(); | |
| 44 void Release(); | |
| 45 void Commit(); | |
| 46 void ShutdownIfNotCommittedAndUnreferenced(); | |
| 47 | |
| 48 base::Lock lock_; | |
| 49 uint32 ref_count_; | |
| 50 bool initialized_; | |
| 51 bool committed_; | |
| 52 DISALLOW_COPY_AND_ASSIGN(CrashReportingManager); | |
| 53 }; | |
| 54 | |
| 55 // A class intended to be instantiated on the stack within entrypoints into the | |
| 56 // Chrome Frame dll. Crash reporting is initialized upon construction if it is | |
| 57 // not already running, and shut down when the last instance is destroyed unless | |
| 58 // any such instance has invoked Commit. | |
| 59 class ScopedCrashReporting { | |
| 60 public: | |
| 61 ScopedCrashReporting() : manager_(CrashReportingManager::Get()) { | |
| 62 manager_.AddRef(); | |
| 63 } | |
| 64 ~ScopedCrashReporting() { | |
| 65 manager_.Release(); | |
| 66 } | |
| 67 | |
| 68 // Causes crash reporting to outlive this and all other instances. | |
| 69 void Commit() { | |
| 70 manager_.Commit(); | |
| 71 } | |
| 72 | |
| 73 private: | |
| 74 CrashReportingManager& manager_; | |
| 75 DISALLOW_COPY_AND_ASSIGN(ScopedCrashReporting); | |
| 76 }; | |
| 22 | 77 |
| 23 #endif // CHROME_FRAME_CHROME_FRAME_REPORTING_H_ | 78 #endif // CHROME_FRAME_CHROME_FRAME_REPORTING_H_ |
| OLD | NEW |