chromeos: bluetooth: tie Proxy lifetime to object, not observer
[chromium-blink-merge.git] / chrome / browser / crash_upload_list.h
blobc8b30d113f422500780c401e7a62525fe9f7e72d
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.
5 #ifndef CHROME_BROWSER_CRASH_UPLOAD_LIST_H_
6 #define CHROME_BROWSER_CRASH_UPLOAD_LIST_H_
7 #pragma once
9 #include "base/memory/ref_counted.h"
10 #include "base/time.h"
12 #include <string>
13 #include <vector>
15 class CrashUploadList : public base::RefCountedThreadSafe<CrashUploadList> {
16 public:
17 struct CrashInfo {
18 CrashInfo(const std::string& c, const base::Time& t);
19 ~CrashInfo();
21 std::string crash_id;
22 base::Time crash_time;
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;
31 protected:
32 virtual ~Delegate() {}
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);
39 // Creates a new crash upload list with the given callback delegate.
40 explicit CrashUploadList(Delegate* delegate);
42 // Starts loading the crash list. OnCrashListAvailable will be called when
43 // loading is complete.
44 void LoadCrashListAsynchronously();
46 // Clears the delegate, so that any outstanding asynchronous load will not
47 // call the delegate on completion.
48 void ClearDelegate();
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);
56 protected:
57 virtual ~CrashUploadList();
59 // Reads the upload log and stores the entries in crashes_.
60 virtual void LoadCrashList();
62 // Returns a reference to the list of crashes.
63 std::vector<CrashInfo>& crashes();
65 private:
66 friend class base::RefCountedThreadSafe<CrashUploadList>;
68 // Manages the background thread work for LoadCrashListAsynchronously().
69 void LoadCrashListAndInformDelegateOfCompletion();
71 // Calls the delegate's callback method, if there is a delegate.
72 void InformDelegateOfCompletion();
74 // Parses crash log lines, converting them to CrashInfo entries.
75 void ParseLogEntries(const std::vector<std::string>& log_entries);
77 std::vector<CrashInfo> crashes_;
78 Delegate* delegate_;
80 DISALLOW_COPY_AND_ASSIGN(CrashUploadList);
83 #endif // CHROME_BROWSER_CRASH_UPLOAD_LIST_H_