Chromium Code Reviews| Index: chrome/browser/crash_upload_list.cc |
| diff --git a/chrome/browser/crash_upload_list.cc b/chrome/browser/crash_upload_list.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..353e0536b7da40180226b4769ccfc3c46e7fcb1c |
| --- /dev/null |
| +++ b/chrome/browser/crash_upload_list.cc |
| @@ -0,0 +1,64 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/crash_upload_list.h" |
| + |
| +#include "base/path_service.h" |
| +#include "base/file_path.h" |
| +#include "base/file_util.h" |
| +#include "base/string_number_conversions.h" |
| +#include "base/string_split.h" |
| +#include "chrome/browser/browser_thread.h" |
| +#include "chrome/common/chrome_paths.h" |
| + |
| +CrashUploadList::CrashUploadList(Delegate* delegate) : delegate_(delegate) {} |
| + |
| +CrashUploadList::~CrashUploadList() {} |
| + |
| +void CrashUploadList::LoadCrashListAsynchronously() { |
| + BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| + NewRunnableMethod(this, &CrashUploadList::LoadUploadLog)); |
| +} |
| + |
| +void CrashUploadList::ClearDelegate() { |
| + delegate_ = NULL; |
| +} |
| + |
| +void CrashUploadList::LoadUploadLog() { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| + FilePath crash_dir_path; |
| + PathService::Get(chrome::DIR_CRASH_DUMPS, &crash_dir_path); |
| + FilePath upload_log_path = crash_dir_path.AppendASCII("uploads.log"); |
| + if (file_util::PathExists(upload_log_path)) { |
| + std::string contents; |
| + file_util::ReadFileToString(upload_log_path, &contents); |
| + base::SplitStringAlongWhitespace(contents, &log_entries_); |
| + } |
| + BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| + NewRunnableMethod(this, &CrashUploadList::InformDelegateOfCompletion)); |
| +} |
| + |
| +void CrashUploadList::InformDelegateOfCompletion() { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + if (delegate_) |
| + delegate_->OnCrashListAvailable(); |
| +} |
| + |
| +void CrashUploadList::GetUploadedCrashes(unsigned int max_count, |
| + std::vector<CrashInfo>* crashes) { |
| + std::vector<std::string>::reverse_iterator i; |
| + for (i = log_entries_.rbegin(); i != log_entries_.rend(); ++i) { |
| + std::vector<std::string> components; |
| + base::SplitString(*i, ',', &components); |
| + 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.
|
| + continue; |
| + double seconds_since_epoch; |
| + if (!base::StringToDouble(components[0], &seconds_since_epoch)) |
| + continue; |
| + CrashInfo info; |
| + info.crash_id = components[1]; |
| + info.crash_time = base::Time::FromDoubleT(seconds_since_epoch); |
| + crashes->push_back(info); |
| + } |
| +} |