• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // 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 
9 #include "base/memory/ref_counted.h"
10 #include "base/time.h"
11 
12 #include <string>
13 #include <vector>
14 
15 class 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:
~Delegate()32     virtual ~Delegate() {}
33   };
34 
35   // 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 
39   // Creates a new crash upload list with the given callback delegate.
40   explicit CrashUploadList(Delegate* delegate);
41 
42   // Starts loading the crash list. OnCrashListAvailable will be called when
43   // loading is complete.
44   void LoadCrashListAsynchronously();
45 
46   // Clears the delegate, so that any outstanding asynchronous load will not
47   // call the delegate on completion.
48   void ClearDelegate();
49 
50   // Populates |crashes| with the |max_count| most recent uploaded crashes,
51   // in reverse chronological order.
52   // Must be called only after OnCrashListAvailable has been called.
53   void GetUploadedCrashes(unsigned int max_count,
54                           std::vector<CrashInfo>* crashes);
55 
56  protected:
57   virtual ~CrashUploadList();
58 
59   // Reads the upload log and stores the entries in crashes_.
60   virtual void LoadCrashList();
61 
62   // Returns a reference to the list of crashes.
63   std::vector<CrashInfo>& crashes();
64 
65  private:
66   friend class base::RefCountedThreadSafe<CrashUploadList>;
67 
68   // Manages the background thread work for LoadCrashListAsynchronously().
69   void LoadCrashListAndInformDelegateOfCompletion();
70 
71   // Calls the delegate's callback method, if there is a delegate.
72   void InformDelegateOfCompletion();
73 
74   // Parses crash log lines, converting them to CrashInfo entries.
75   void ParseLogEntries(const std::vector<std::string>& log_entries);
76 
77   std::vector<CrashInfo> crashes_;
78   Delegate* delegate_;
79 
80   DISALLOW_COPY_AND_ASSIGN(CrashUploadList);
81 };
82 
83 #endif  // CHROME_BROWSER_CRASH_UPLOAD_LIST_H_
84