OLD | NEW |
(Empty) | |
| 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 #include "chrome/browser/crash_upload_list.h" |
| 6 |
| 7 #include "base/path_service.h" |
| 8 #include "base/file_path.h" |
| 9 #include "base/file_util.h" |
| 10 #include "base/string_number_conversions.h" |
| 11 #include "base/string_split.h" |
| 12 #include "chrome/browser/browser_thread.h" |
| 13 #include "chrome/common/chrome_paths.h" |
| 14 |
| 15 |
| 16 CrashUploadList::CrashInfo::CrashInfo(const std::string& c, const base::Time& t) |
| 17 : crash_id(c), crash_time(t) {} |
| 18 |
| 19 CrashUploadList::CrashInfo::~CrashInfo() {} |
| 20 |
| 21 CrashUploadList::CrashUploadList(Delegate* delegate) : delegate_(delegate) {} |
| 22 |
| 23 CrashUploadList::~CrashUploadList() {} |
| 24 |
| 25 void CrashUploadList::LoadCrashListAsynchronously() { |
| 26 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 27 NewRunnableMethod(this, &CrashUploadList::LoadUploadLog)); |
| 28 } |
| 29 |
| 30 void CrashUploadList::ClearDelegate() { |
| 31 delegate_ = NULL; |
| 32 } |
| 33 |
| 34 void CrashUploadList::LoadUploadLog() { |
| 35 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 36 FilePath crash_dir_path; |
| 37 PathService::Get(chrome::DIR_CRASH_DUMPS, &crash_dir_path); |
| 38 FilePath upload_log_path = crash_dir_path.AppendASCII("uploads.log"); |
| 39 if (file_util::PathExists(upload_log_path)) { |
| 40 std::string contents; |
| 41 file_util::ReadFileToString(upload_log_path, &contents); |
| 42 base::SplitStringAlongWhitespace(contents, &log_entries_); |
| 43 } |
| 44 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 45 NewRunnableMethod(this, &CrashUploadList::InformDelegateOfCompletion)); |
| 46 } |
| 47 |
| 48 void CrashUploadList::InformDelegateOfCompletion() { |
| 49 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 50 if (delegate_) |
| 51 delegate_->OnCrashListAvailable(); |
| 52 } |
| 53 |
| 54 void CrashUploadList::GetUploadedCrashes(unsigned int max_count, |
| 55 std::vector<CrashInfo>* crashes) { |
| 56 std::vector<std::string>::reverse_iterator i; |
| 57 for (i = log_entries_.rbegin(); i != log_entries_.rend(); ++i) { |
| 58 std::vector<std::string> components; |
| 59 base::SplitString(*i, ',', &components); |
| 60 // Skip any blank (or corrupted) lines. |
| 61 if (components.size() != 2) |
| 62 continue; |
| 63 double seconds_since_epoch; |
| 64 if (!base::StringToDouble(components[0], &seconds_since_epoch)) |
| 65 continue; |
| 66 CrashInfo info(components[1], base::Time::FromDoubleT(seconds_since_epoch)); |
| 67 crashes->push_back(info); |
| 68 } |
| 69 } |
OLD | NEW |