Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(609)

Side by Side Diff: chrome/browser/crash_upload_list.cc

Issue 6771021: Implement CrashUploadListWin to enable chrome://crashes on Windows. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Add class-level comment. Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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 #include "chrome/browser/crash_upload_list.h" 5 #include "chrome/browser/crash_upload_list.h"
6 6
7 #include "base/path_service.h" 7 #include "base/path_service.h"
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
11 #include "base/string_split.h" 11 #include "base/string_split.h"
12 #include "chrome/browser/crash_upload_list_win.h"
12 #include "chrome/common/chrome_paths.h" 13 #include "chrome/common/chrome_paths.h"
13 #include "content/browser/browser_thread.h" 14 #include "content/browser/browser_thread.h"
14 15
15 CrashUploadList::CrashInfo::CrashInfo(const std::string& c, const base::Time& t) 16 CrashUploadList::CrashInfo::CrashInfo(const std::string& c, const base::Time& t)
16 : crash_id(c), crash_time(t) {} 17 : crash_id(c), crash_time(t) {}
17 18
18 CrashUploadList::CrashInfo::~CrashInfo() {} 19 CrashUploadList::CrashInfo::~CrashInfo() {}
19 20
21 // static
22 CrashUploadList* CrashUploadList::Create(Delegate* delegate) {
23 #if defined(OS_WIN)
24 return new CrashUploadListWin(delegate);
25 #else
26 return new CrashUploadList(delegate);
27 #endif
28 }
29
20 CrashUploadList::CrashUploadList(Delegate* delegate) : delegate_(delegate) {} 30 CrashUploadList::CrashUploadList(Delegate* delegate) : delegate_(delegate) {}
21 31
22 CrashUploadList::~CrashUploadList() {} 32 CrashUploadList::~CrashUploadList() {}
23 33
24 void CrashUploadList::LoadCrashListAsynchronously() { 34 void CrashUploadList::LoadCrashListAsynchronously() {
25 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 35 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
26 NewRunnableMethod(this, &CrashUploadList::LoadUploadLog)); 36 NewRunnableMethod(this,
37 &CrashUploadList::LoadCrashListAndInformDelegateOfCompletion));
27 } 38 }
28 39
29 void CrashUploadList::ClearDelegate() { 40 void CrashUploadList::ClearDelegate() {
30 delegate_ = NULL; 41 delegate_ = NULL;
31 } 42 }
32 43
33 void CrashUploadList::LoadUploadLog() { 44
45 void CrashUploadList::LoadCrashListAndInformDelegateOfCompletion() {
46 LoadCrashList();
47 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
48 NewRunnableMethod(this, &CrashUploadList::InformDelegateOfCompletion));
49 }
50
51 void CrashUploadList::LoadCrashList() {
stuartmorgan 2011/03/30 16:28:10 This function is doing a couple of things now; you
34 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 52 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
35 FilePath crash_dir_path; 53 FilePath crash_dir_path;
36 PathService::Get(chrome::DIR_CRASH_DUMPS, &crash_dir_path); 54 PathService::Get(chrome::DIR_CRASH_DUMPS, &crash_dir_path);
37 FilePath upload_log_path = crash_dir_path.AppendASCII("uploads.log"); 55 FilePath upload_log_path = crash_dir_path.AppendASCII("uploads.log");
38 if (file_util::PathExists(upload_log_path)) { 56 if (file_util::PathExists(upload_log_path)) {
39 std::string contents; 57 std::string contents;
58 std::vector<std::string> log_entries;
40 file_util::ReadFileToString(upload_log_path, &contents); 59 file_util::ReadFileToString(upload_log_path, &contents);
41 base::SplitStringAlongWhitespace(contents, &log_entries_); 60 base::SplitStringAlongWhitespace(contents, &log_entries);
61
62 std::vector<std::string>::reverse_iterator i;
63 for (i = log_entries.rbegin(); i != log_entries.rend(); ++i) {
64 std::vector<std::string> components;
65 base::SplitString(*i, ',', &components);
66 // Skip any blank (or corrupted) lines.
67 if (components.size() != 2)
68 continue;
69 double seconds_since_epoch;
70 if (!base::StringToDouble(components[0], &seconds_since_epoch))
71 continue;
72 CrashInfo info(components[1],
73 base::Time::FromDoubleT(seconds_since_epoch));
74 crashes_.push_back(info);
75 }
42 } 76 }
43 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
44 NewRunnableMethod(this, &CrashUploadList::InformDelegateOfCompletion));
45 } 77 }
46 78
47 void CrashUploadList::InformDelegateOfCompletion() { 79 void CrashUploadList::InformDelegateOfCompletion() {
48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 80 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
49 if (delegate_) 81 if (delegate_)
50 delegate_->OnCrashListAvailable(); 82 delegate_->OnCrashListAvailable();
51 } 83 }
52 84
53 void CrashUploadList::GetUploadedCrashes(unsigned int max_count, 85 void CrashUploadList::GetUploadedCrashes(unsigned int max_count,
54 std::vector<CrashInfo>* crashes) { 86 std::vector<CrashInfo>* crashes) {
55 std::vector<std::string>::reverse_iterator i; 87 std::copy(crashes_.begin(),
56 for (i = log_entries_.rbegin(); i != log_entries_.rend(); ++i) { 88 crashes_.begin() + std::min(crashes_.size(), max_count),
57 std::vector<std::string> components; 89 std::back_inserter(*crashes));
58 base::SplitString(*i, ',', &components);
59 // Skip any blank (or corrupted) lines.
60 if (components.size() != 2)
61 continue;
62 double seconds_since_epoch;
63 if (!base::StringToDouble(components[0], &seconds_since_epoch))
64 continue;
65 CrashInfo info(components[1], base::Time::FromDoubleT(seconds_since_epoch));
66 crashes->push_back(info);
67 }
68 } 90 }
91
92 std::vector<CrashUploadList::CrashInfo>& CrashUploadList::crashes() {
93 return crashes_;
94 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698