Chromium Code Reviews| OLD | NEW |
|---|---|
| 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, &CrashUploadList::LoadUploadLog)); |
| 27 } | 37 } |
| 28 | 38 |
| 29 void CrashUploadList::ClearDelegate() { | 39 void CrashUploadList::ClearDelegate() { |
| 30 delegate_ = NULL; | 40 delegate_ = NULL; |
| 31 } | 41 } |
| 32 | 42 |
| 33 void CrashUploadList::LoadUploadLog() { | 43 void CrashUploadList::LoadUploadLog() { |
| 34 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 35 FilePath crash_dir_path; | 45 FilePath crash_dir_path; |
| 36 PathService::Get(chrome::DIR_CRASH_DUMPS, &crash_dir_path); | 46 PathService::Get(chrome::DIR_CRASH_DUMPS, &crash_dir_path); |
| 37 FilePath upload_log_path = crash_dir_path.AppendASCII("uploads.log"); | 47 FilePath upload_log_path = crash_dir_path.AppendASCII("uploads.log"); |
| 38 if (file_util::PathExists(upload_log_path)) { | 48 if (file_util::PathExists(upload_log_path)) { |
| 39 std::string contents; | 49 std::string contents; |
| 40 file_util::ReadFileToString(upload_log_path, &contents); | 50 file_util::ReadFileToString(upload_log_path, &contents); |
| 41 base::SplitStringAlongWhitespace(contents, &log_entries_); | 51 base::SplitStringAlongWhitespace(contents, &log_entries_); |
| 42 } | 52 } |
| 53 InformDelegateOfCompletionAsynchronously(); | |
|
stuartmorgan
2011/03/29 21:19:57
It would be cleaner for the subclass to make a new
Alexei Svitkine (slow)
2011/03/30 15:36:40
Done.
| |
| 54 } | |
| 55 | |
| 56 void CrashUploadList::InformDelegateOfCompletionAsynchronously() { | |
| 43 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 57 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 44 NewRunnableMethod(this, &CrashUploadList::InformDelegateOfCompletion)); | 58 NewRunnableMethod(this, &CrashUploadList::InformDelegateOfCompletion)); |
| 45 } | 59 } |
| 46 | 60 |
| 47 void CrashUploadList::InformDelegateOfCompletion() { | 61 void CrashUploadList::InformDelegateOfCompletion() { |
| 48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 62 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 49 if (delegate_) | 63 if (delegate_) |
| 50 delegate_->OnCrashListAvailable(); | 64 delegate_->OnCrashListAvailable(); |
| 51 } | 65 } |
| 52 | 66 |
| 53 void CrashUploadList::GetUploadedCrashes(unsigned int max_count, | 67 void CrashUploadList::GetUploadedCrashes(unsigned int max_count, |
| 54 std::vector<CrashInfo>* crashes) { | 68 std::vector<CrashInfo>* crashes) { |
| 69 unsigned int count = 0; | |
| 55 std::vector<std::string>::reverse_iterator i; | 70 std::vector<std::string>::reverse_iterator i; |
| 56 for (i = log_entries_.rbegin(); i != log_entries_.rend(); ++i) { | 71 for (i = log_entries_.rbegin(); i != log_entries_.rend() && |
| 72 count != max_count; ++i) { | |
|
stuartmorgan
2011/03/29 21:19:57
Whoops :( Good catch.
| |
| 57 std::vector<std::string> components; | 73 std::vector<std::string> components; |
| 58 base::SplitString(*i, ',', &components); | 74 base::SplitString(*i, ',', &components); |
| 59 // Skip any blank (or corrupted) lines. | 75 // Skip any blank (or corrupted) lines. |
| 60 if (components.size() != 2) | 76 if (components.size() != 2) |
| 61 continue; | 77 continue; |
| 62 double seconds_since_epoch; | 78 double seconds_since_epoch; |
| 63 if (!base::StringToDouble(components[0], &seconds_since_epoch)) | 79 if (!base::StringToDouble(components[0], &seconds_since_epoch)) |
| 64 continue; | 80 continue; |
| 65 CrashInfo info(components[1], base::Time::FromDoubleT(seconds_since_epoch)); | 81 CrashInfo info(components[1], base::Time::FromDoubleT(seconds_since_epoch)); |
| 66 crashes->push_back(info); | 82 crashes->push_back(info); |
| 83 ++count; | |
| 67 } | 84 } |
| 68 } | 85 } |
| 86 | |
| 87 std::vector<std::string>& CrashUploadList::log_entries() { | |
| 88 return log_entries_; | |
| 89 } | |
| OLD | NEW |