Chromium Code Reviews| 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 CrashUploadList::CrashUploadList(Delegate* delegate) : delegate_(delegate) {} | |
| 16 | |
| 17 CrashUploadList::~CrashUploadList() {} | |
| 18 | |
| 19 void CrashUploadList::LoadCrashListAsynchronously() { | |
| 20 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | |
| 21 NewRunnableMethod(this, &CrashUploadList::LoadUploadLog)); | |
| 22 } | |
| 23 | |
| 24 void CrashUploadList::ClearDelegate() { | |
| 25 delegate_ = NULL; | |
| 26 } | |
| 27 | |
| 28 void CrashUploadList::LoadUploadLog() { | |
| 29 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | |
| 30 FilePath crash_dir_path; | |
| 31 PathService::Get(chrome::DIR_CRASH_DUMPS, &crash_dir_path); | |
| 32 FilePath upload_log_path = crash_dir_path.AppendASCII("uploads.log"); | |
| 33 if (file_util::PathExists(upload_log_path)) { | |
| 34 std::string contents; | |
| 35 file_util::ReadFileToString(upload_log_path, &contents); | |
| 36 base::SplitStringAlongWhitespace(contents, &log_entries_); | |
| 37 } | |
| 38 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
| 39 NewRunnableMethod(this, &CrashUploadList::InformDelegateOfCompletion)); | |
| 40 } | |
| 41 | |
| 42 void CrashUploadList::InformDelegateOfCompletion() { | |
| 43 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 44 if (delegate_) | |
| 45 delegate_->OnCrashListAvailable(); | |
| 46 } | |
| 47 | |
| 48 void CrashUploadList::GetUploadedCrashes(unsigned int max_count, | |
| 49 std::vector<CrashInfo>* crashes) { | |
| 50 std::vector<std::string>::reverse_iterator i; | |
| 51 for (i = log_entries_.rbegin(); i != log_entries_.rend(); ++i) { | |
| 52 std::vector<std::string> components; | |
| 53 base::SplitString(*i, ',', &components); | |
| 54 if (components.size() != 2) | |
|
Nico
2011/02/18 18:16:01
If this happens in practice, add a comment about w
stuartmorgan
2011/02/18 19:41:21
Done.
| |
| 55 continue; | |
| 56 double seconds_since_epoch; | |
| 57 if (!base::StringToDouble(components[0], &seconds_since_epoch)) | |
| 58 continue; | |
| 59 CrashInfo info; | |
| 60 info.crash_id = components[1]; | |
| 61 info.crash_time = base::Time::FromDoubleT(seconds_since_epoch); | |
| 62 crashes->push_back(info); | |
| 63 } | |
| 64 } | |
| OLD | NEW |