OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Crashpad Authors. 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 #ifndef CRASHPAD_HANDLER_PRUNE_CRASH_REPORTS_THREAD_H_ |
| 16 #define CRASHPAD_HANDLER_PRUNE_CRASH_REPORTS_THREAD_H_ |
| 17 |
| 18 #include "base/basictypes.h" |
| 19 #include "base/memory/scoped_ptr.h" |
| 20 #include "util/thread/worker_thread.h" |
| 21 |
| 22 namespace crashpad { |
| 23 |
| 24 class CrashReportDatabase; |
| 25 class PruneCondition; |
| 26 |
| 27 //! \brief A thread that periodically prunes crash reports from the database |
| 28 //! using the specified condition. |
| 29 //! |
| 30 //! After the thread is started, the database is pruned using the condition |
| 31 //! every 24 hours. Upon calling Start(), the thread waits 10 minutes before |
| 32 //! performing the initial prune operation. |
| 33 class PruneCrashReportThread : public WorkerThread::Delegate { |
| 34 public: |
| 35 //! \brief Constructs a new object. |
| 36 //! |
| 37 //! \param[in] database The database to prune crash reports from. |
| 38 //! \param[in] condition The condition used to evaluate crash reports for |
| 39 //! pruning. |
| 40 PruneCrashReportThread(CrashReportDatabase* database, |
| 41 scoped_ptr<PruneCondition> condition); |
| 42 ~PruneCrashReportThread(); |
| 43 |
| 44 //! \brief Starts a dedicated pruning thread. |
| 45 //! |
| 46 //! The thread waits before running the initial prune, so as to not interfere |
| 47 //! with any startup-related IO performed by the client. |
| 48 //! |
| 49 //! This method may only be be called on a newly-constructed object or after |
| 50 //! a call to Stop(). |
| 51 void Start(); |
| 52 |
| 53 //! \brief Stops the pruning thread. |
| 54 //! |
| 55 //! This method must only be called after Start(). If Start() has been called, |
| 56 //! this method must be called before destroying an object of this class. |
| 57 //! |
| 58 //! This method may be called from any thread other than the pruning thread. |
| 59 //! It is expected to only be called from the same thread that called Start(). |
| 60 void Stop(); |
| 61 |
| 62 private: |
| 63 // WorkerThread::Delegate: |
| 64 void DoWork(const WorkerThread* thread) override; |
| 65 |
| 66 WorkerThread thread_; |
| 67 scoped_ptr<PruneCondition> condition_; |
| 68 CrashReportDatabase* database_; // weak |
| 69 |
| 70 DISALLOW_COPY_AND_ASSIGN(PruneCrashReportThread); |
| 71 }; |
| 72 |
| 73 } // namespace crashpad |
| 74 |
| 75 #endif // CRASHPAD_HANDLER_PRUNE_CRASH_REPORTS_THREAD_H_ |
OLD | NEW |