OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef CHROMECAST_CRASH_LINUX_DUMMY_MINIDUMP_GENERATOR_H_ | 5 #ifndef CHROMECAST_CRASH_LINUX_DUMMY_MINIDUMP_GENERATOR_H_ |
6 #define CHROMECAST_CRASH_LINUX_DUMMY_MINIDUMP_GENERATOR_H_ | 6 #define CHROMECAST_CRASH_LINUX_DUMMY_MINIDUMP_GENERATOR_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "chromecast/crash/linux/minidump_generator.h" | 11 #include "chromecast/crash/linux/minidump_generator.h" |
12 | 12 |
13 namespace chromecast { | 13 namespace chromecast { |
14 | 14 |
15 class DummyMinidumpGenerator : public MinidumpGenerator { | 15 class DummyMinidumpGenerator : public MinidumpGenerator { |
16 public: | 16 public: |
17 // A dummy minidump generator to move an existing minidump into | 17 // A dummy minidump generator to move an existing minidump into |
18 // crash_uploader's monitoring path ($HOME/minidumps). The path is monitored | 18 // crash_uploader's monitoring path ($HOME/minidumps). The path is monitored |
19 // with file lock-control, so that third process should not write to it | 19 // with file lock-control, so that third process should not write to it |
20 // directly. | 20 // directly. |
21 explicit DummyMinidumpGenerator(const std::string& existing_minidump_path); | 21 explicit DummyMinidumpGenerator(const std::string& existing_minidump_path); |
22 | 22 |
23 // MinidumpGenerator implementation: | 23 // MinidumpGenerator implementation: |
24 // Moves the minidump located at |existing_minidump_path_| to |minidump_path|. | |
25 // Returns true if successful, false otherwise. Note that this function MUST | |
26 // be called on a thread without IO restrictions, or it will fail fatally. | |
27 bool Generate(const std::string& minidump_path) override; | 24 bool Generate(const std::string& minidump_path) override; |
28 | 25 |
| 26 // Provide access to internal utility for testing. |
| 27 bool CopyAndDeleteForTest(const std::string& dest_path) { |
| 28 return CopyAndDelete(dest_path); |
| 29 } |
| 30 |
29 private: | 31 private: |
| 32 // Copies the contents of the file at |existing_minidump_path_| to the file at |
| 33 // |dest_path|. If the copy operation succeeds, delete the file at |
| 34 // |existing_minidump_path_|. Returns false if |existing_minidump_path_| can't |
| 35 // be opened, or if the copy operation fails. Ideally, we would use Chrome |
| 36 // utilities for a task like this, but we must ensure that this operation can |
| 37 // occur on any thread (regardless of IO restrictions). |
| 38 bool CopyAndDelete(const std::string& dest_path); |
| 39 |
30 const std::string existing_minidump_path_; | 40 const std::string existing_minidump_path_; |
31 | 41 |
32 DISALLOW_COPY_AND_ASSIGN(DummyMinidumpGenerator); | 42 DISALLOW_COPY_AND_ASSIGN(DummyMinidumpGenerator); |
33 }; | 43 }; |
34 | 44 |
35 } // namespace chromecast | 45 } // namespace chromecast |
36 | 46 |
37 #endif // CHROMECAST_CRASH_LINUX_DUMMY_MINIDUMP_GENERATOR_H_ | 47 #endif // CHROMECAST_CRASH_LINUX_DUMMY_MINIDUMP_GENERATOR_H_ |
OLD | NEW |