blob: 9446f8f8318cf9b8d31b35155f19464d2a286cd5 [file] [log] [blame]
[email protected]234e8262012-02-22 21:05:541// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]c8717adf72011-02-18 21:07:162// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CHROME_BROWSER_CRASH_UPLOAD_LIST_H_
6#define CHROME_BROWSER_CRASH_UPLOAD_LIST_H_
7#pragma once
8
[email protected]c8717adf72011-02-18 21:07:169#include <string>
10#include <vector>
11
[email protected]234e8262012-02-22 21:05:5412#include "base/memory/ref_counted.h"
13#include "base/time.h"
14
[email protected]c8717adf72011-02-18 21:07:1615class CrashUploadList : public base::RefCountedThreadSafe<CrashUploadList> {
16 public:
17 struct CrashInfo {
18 CrashInfo(const std::string& c, const base::Time& t);
19 ~CrashInfo();
20
21 std::string crash_id;
22 base::Time crash_time;
23 };
24
25 class Delegate {
26 public:
27 // Invoked when the crash list has been loaded. Will be called on the
28 // UI thread.
29 virtual void OnCrashListAvailable() = 0;
30
31 protected:
32 virtual ~Delegate() {}
33 };
34
[email protected]b35b1dd2011-04-01 15:58:5035 // Static factory method that creates the platform-specific implementation
36 // of the crash upload list with the given callback delegate.
37 static CrashUploadList* Create(Delegate* delegate);
38
[email protected]234e8262012-02-22 21:05:5439 // Should match kReporterLogFilename in
40 // breakpad/src/client/apple/Framework/BreakpadDefines.h.
41 static const char* kReporterLogFilename;
42
[email protected]c8717adf72011-02-18 21:07:1643 // Creates a new crash upload list with the given callback delegate.
44 explicit CrashUploadList(Delegate* delegate);
45
46 // Starts loading the crash list. OnCrashListAvailable will be called when
47 // loading is complete.
48 void LoadCrashListAsynchronously();
49
50 // Clears the delegate, so that any outstanding asynchronous load will not
51 // call the delegate on completion.
52 void ClearDelegate();
53
54 // Populates |crashes| with the |max_count| most recent uploaded crashes,
55 // in reverse chronological order.
56 // Must be called only after OnCrashListAvailable has been called.
57 void GetUploadedCrashes(unsigned int max_count,
58 std::vector<CrashInfo>* crashes);
59
[email protected]b35b1dd2011-04-01 15:58:5060 protected:
[email protected]c8717adf72011-02-18 21:07:1661 virtual ~CrashUploadList();
62
[email protected]b35b1dd2011-04-01 15:58:5063 // Reads the upload log and stores the entries in crashes_.
64 virtual void LoadCrashList();
65
66 // Returns a reference to the list of crashes.
67 std::vector<CrashInfo>& crashes();
68
69 private:
70 friend class base::RefCountedThreadSafe<CrashUploadList>;
71
72 // Manages the background thread work for LoadCrashListAsynchronously().
73 void LoadCrashListAndInformDelegateOfCompletion();
[email protected]c8717adf72011-02-18 21:07:1674
75 // Calls the delegate's callback method, if there is a delegate.
76 void InformDelegateOfCompletion();
77
[email protected]b35b1dd2011-04-01 15:58:5078 // Parses crash log lines, converting them to CrashInfo entries.
79 void ParseLogEntries(const std::vector<std::string>& log_entries);
80
81 std::vector<CrashInfo> crashes_;
[email protected]c8717adf72011-02-18 21:07:1682 Delegate* delegate_;
83
84 DISALLOW_COPY_AND_ASSIGN(CrashUploadList);
85};
86
87#endif // CHROME_BROWSER_CRASH_UPLOAD_LIST_H_