summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorzelidrag@chromium.org <zelidrag@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-09 00:17:57 +0000
committerzelidrag@chromium.org <zelidrag@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-09 00:17:57 +0000
commit900fc625b6cd3c516bb2c7d2dccd44f7b27642a8 (patch)
treeda98bdf6f906b93c101391359a4c6aa8418541f2 /chrome
parente986022b3dde48b58f75ed80f1171c55bb34ed3f (diff)
downloadchromium_src-900fc625b6cd3c516bb2c7d2dccd44f7b27642a8.zip
chromium_src-900fc625b6cd3c516bb2c7d2dccd44f7b27642a8.tar.gz
chromium_src-900fc625b6cd3c516bb2c7d2dccd44f7b27642a8.tar.bz2
Prepared code for system logs split in ChromeOS feedback reports. We are still missing sever-side changes, so
part of this code is commented out until we get at least proto buffers defined. BUG=chromium-os:7344 TEST=none Review URL: http://codereview.chromium.org/3563011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@62046 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/bug_report_util.cc51
-rw-r--r--chrome/browser/bug_report_util.h6
-rw-r--r--chrome/browser/chromeos/cros/syslogs_library.cc113
-rw-r--r--chrome/browser/chromeos/cros/syslogs_library.h10
-rw-r--r--chrome/browser/chromeos/dom_ui/system_info_ui.cc11
-rw-r--r--chrome/browser/dom_ui/bug_report_ui.cc41
-rw-r--r--chrome/common/chrome_switches.cc3
-rw-r--r--chrome/common/chrome_switches.h1
8 files changed, 187 insertions, 49 deletions
diff --git a/chrome/browser/bug_report_util.cc b/chrome/browser/bug_report_util.cc
index 6571d95..adf2637 100644
--- a/chrome/browser/bug_report_util.cc
+++ b/chrome/browser/bug_report_util.cc
@@ -61,6 +61,17 @@ static int const kHttpPostFailNoConnection = -1;
static int const kHttpPostFailClientError = 400;
static int const kHttpPostFailServerError = 500;
+#if defined(OS_CHROMEOS)
+static char const kBZip2MimeType[] = "application/x-bzip2";
+static char const kLogsAttachmentName[] = "system_logs.bz2";
+// Maximum number of lines in system info log chunk to be still included
+// in product specific data.
+const size_t kMaxLineCount = 10;
+// Maximum number of bytes in system info log chunk to be still included
+// in product specific data.
+const size_t kMaxSystemLogLength = 1024;
+#endif
+
} // namespace
@@ -215,6 +226,23 @@ void BugReportUtil::AddFeedbackData(
*(web_data->add_product_specific_data()) = log_value;
}
+#if defined(OS_CHROMEOS)
+bool BugReportUtil::ValidFeedbackSize(const std::string& content) {
+ if (content.length() > kMaxSystemLogLength)
+ return false;
+ size_t line_count = 0;
+ const char* text = content.c_str();
+ for (size_t i = 0; i < content.length(); i++) {
+ if (*(text + i) == '\n') {
+ line_count++;
+ if (line_count > kMaxLineCount)
+ return false;
+ }
+ }
+ return true;
+}
+#endif
+
// static
void BugReportUtil::SendReport(Profile* profile,
const std::string& page_title_text,
@@ -227,6 +255,8 @@ void BugReportUtil::SendReport(Profile* profile,
#if defined(OS_CHROMEOS)
int png_height,
const std::string& user_email_text,
+ const char* zipped_logs_data,
+ int zipped_logs_length,
const chromeos::LogDictionaryType* const sys_info) {
#else
int png_height) {
@@ -292,7 +322,10 @@ void BugReportUtil::SendReport(Profile* profile,
if (sys_info) {
for (chromeos::LogDictionaryType::const_iterator i = sys_info->begin();
i != sys_info->end(); ++i)
- AddFeedbackData(&feedback_data, i->first, i->second);
+ if (!CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kCompressSystemFeedback) || ValidFeedbackSize(i->second)) {
+ AddFeedbackData(&feedback_data, i->first, i->second);
+ }
}
#endif
@@ -311,6 +344,22 @@ void BugReportUtil::SendReport(Profile* profile,
*(feedback_data.mutable_screenshot()) = screenshot;
}
+#if defined(OS_CHROMEOS)
+ // Include the page image if we have one.
+ if (zipped_logs_data && CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kCompressSystemFeedback)) {
+/* TODO(zelidrag): http://crosbug.com/7344 - Uncomment this block once proto
+// buffer for ProductSpecificBinaryData gets defined by Feedback team.
+ userfeedback::ProductSpecificBinaryData attachment;
+ attachment.set_mime_type(kBZip2MimeType);
+ attachment.set_name(kLogsAttachmentName);
+ attachment.set_binary_content(std::string(zipped_logs_data,
+ zipped_logs_length));
+ *(feedback_data.mutable_productSpecificBinaryData()) = attachment;
+*/
+ }
+#endif
+
// Set our Chrome specific data
userfeedback::ChromeData chrome_data;
#if defined(OS_CHROMEOS)
diff --git a/chrome/browser/bug_report_util.h b/chrome/browser/bug_report_util.h
index e11a22c..c01acc04 100644
--- a/chrome/browser/bug_report_util.h
+++ b/chrome/browser/bug_report_util.h
@@ -78,6 +78,8 @@ class BugReportUtil {
#if defined(OS_CHROMEOS)
int png_height,
const std::string& user_email_text,
+ const char* zipped_logs_data,
+ int zipped_logs_length,
const chromeos::LogDictionaryType* const sys_info);
#else
int png_height);
@@ -95,6 +97,10 @@ class BugReportUtil {
userfeedback::ExternalExtensionSubmit* feedback_data,
const std::string& key, const std::string& value);
+#if defined(OS_CHROMEOS)
+ static bool ValidFeedbackSize(const std::string& content);
+#endif
+
static std::string feedback_server_;
DISALLOW_IMPLICIT_CONSTRUCTORS(BugReportUtil);
diff --git a/chrome/browser/chromeos/cros/syslogs_library.cc b/chrome/browser/chromeos/cros/syslogs_library.cc
index ed31800..dc95f69 100644
--- a/chrome/browser/chromeos/cros/syslogs_library.cc
+++ b/chrome/browser/chromeos/cros/syslogs_library.cc
@@ -4,9 +4,12 @@
#include "chrome/browser/chromeos/cros/syslogs_library.h"
+#include "base/command_line.h"
+#include "base/file_util.h"
#include "base/string_util.h"
#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/chromeos/cros/cros_library.h"
+#include "chrome/common/chrome_switches.h"
namespace chromeos {
@@ -15,40 +18,19 @@ class SyslogsLibraryImpl : public SyslogsLibrary {
SyslogsLibraryImpl() {}
virtual ~SyslogsLibraryImpl() {}
- virtual Handle RequestSyslogs(FilePath* tmpfilename,
- CancelableRequestConsumerBase* consumer,
- ReadCompleteCallback* callback) {
- // Register the callback request.
- scoped_refptr<CancelableRequest<ReadCompleteCallback> > request(
- new CancelableRequest<ReadCompleteCallback>(callback));
- AddRequest(request, consumer);
-
- // Schedule a task on the FILE thread which will then trigger a request
- // callback on the calling thread (e.g. UI) when complete.
- BrowserThread::PostTask(
- BrowserThread::FILE, FROM_HERE,
- NewRunnableMethod(
- this, &SyslogsLibraryImpl::ReadSyslogs, request, tmpfilename));
-
- return request->handle();
- }
+ virtual Handle RequestSyslogs(
+ bool compress_logs,
+ CancelableRequestConsumerBase* consumer,
+ ReadCompleteCallback* callback);
- private:
+ // Reads system logs, compresses content if requested.
// Called from FILE thread.
void ReadSyslogs(
scoped_refptr<CancelableRequest<ReadCompleteCallback> > request,
- FilePath* tmpfilename) {
- if (request->canceled())
- return;
+ bool compress_logs);
- LogDictionaryType* logs = NULL;
- if (CrosLibrary::Get()->EnsureLoaded()) {
- logs = chromeos::GetSystemLogs(tmpfilename);
- }
-
- // Will call the callback on the calling thread.
- request->ForwardResult(Tuple1<LogDictionaryType*>(logs));
- }
+ void LoadCompressedLogs(const FilePath& zip_file,
+ std::string* zip_content);
DISALLOW_COPY_AND_ASSIGN(SyslogsLibraryImpl);
};
@@ -58,11 +40,11 @@ class SyslogsLibraryStubImpl : public SyslogsLibrary {
SyslogsLibraryStubImpl() {}
virtual ~SyslogsLibraryStubImpl() {}
- virtual Handle RequestSyslogs(FilePath* tmpfilename,
+ virtual Handle RequestSyslogs(bool compress_logs,
CancelableRequestConsumerBase* consumer,
ReadCompleteCallback* callback) {
if (callback)
- callback->Run(Tuple1<LogDictionaryType*>(NULL));
+ callback->Run(Tuple2<LogDictionaryType*, std::string*>(NULL , NULL));
return 0;
}
@@ -76,8 +58,77 @@ SyslogsLibrary* SyslogsLibrary::GetImpl(bool stub) {
return new SyslogsLibraryImpl();
}
+
+CancelableRequestProvider::Handle SyslogsLibraryImpl::RequestSyslogs(
+ bool compress_logs,
+ CancelableRequestConsumerBase* consumer,
+ ReadCompleteCallback* callback) {
+ // Register the callback request.
+ scoped_refptr<CancelableRequest<ReadCompleteCallback> > request(
+ new CancelableRequest<ReadCompleteCallback>(callback));
+ AddRequest(request, consumer);
+
+ // Schedule a task on the FILE thread which will then trigger a request
+ // callback on the calling thread (e.g. UI) when complete.
+ BrowserThread::PostTask(
+ BrowserThread::FILE, FROM_HERE,
+ NewRunnableMethod(
+ this, &SyslogsLibraryImpl::ReadSyslogs, request, compress_logs));
+
+ return request->handle();
+}
+
+// Called from FILE thread.
+void SyslogsLibraryImpl::ReadSyslogs(
+ scoped_refptr<CancelableRequest<ReadCompleteCallback> > request,
+ bool compress_logs) {
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE));
+
+ if (request->canceled())
+ return;
+
+ if (compress_logs && !CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kCompressSystemFeedback))
+ compress_logs = false;
+
+ // Create temp file.
+ FilePath zip_file;
+ if (compress_logs && !file_util::CreateTemporaryFile(&zip_file)) {
+ LOG(ERROR) << "Cannot create temp file";
+ compress_logs = false;
+ }
+
+ LogDictionaryType* logs = NULL;
+ if (CrosLibrary::Get()->EnsureLoaded())
+ logs = chromeos::GetSystemLogs(
+ compress_logs ? &zip_file : NULL);
+
+ std::string* zip_content = NULL;
+ if (compress_logs) {
+ // Load compressed logs.
+ zip_content = new std::string();
+ LoadCompressedLogs(zip_file, zip_content);
+ file_util::Delete(zip_file, false);
+ }
+
+ // Will call the callback on the calling thread.
+ request->ForwardResult(Tuple2<LogDictionaryType*,
+ std::string*>(logs, zip_content));
+}
+
+
+void SyslogsLibraryImpl::LoadCompressedLogs(const FilePath& zip_file,
+ std::string* zip_content) {
+ DCHECK(zip_content);
+ if (!file_util::ReadFileToString(zip_file, zip_content)) {
+ LOG(ERROR) << "Cannot read compressed logs file from " <<
+ zip_file.value().c_str();
+ }
+}
+
} // namespace chromeos
// Allows InvokeLater without adding refcounting. SyslogsLibraryImpl is a
// Singleton and won't be deleted until it's last InvokeLater is run.
DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::SyslogsLibraryImpl);
+
diff --git a/chrome/browser/chromeos/cros/syslogs_library.h b/chrome/browser/chromeos/cros/syslogs_library.h
index 56a07f7..3850a31 100644
--- a/chrome/browser/chromeos/cros/syslogs_library.h
+++ b/chrome/browser/chromeos/cros/syslogs_library.h
@@ -17,7 +17,8 @@ namespace chromeos {
// This interface defines interaction with the ChromeOS syslogs APIs.
class SyslogsLibrary : public CancelableRequestProvider {
public:
- typedef Callback1<LogDictionaryType*>::Type ReadCompleteCallback;
+ typedef Callback2<LogDictionaryType*,
+ std::string*>::Type ReadCompleteCallback;
SyslogsLibrary() {}
virtual ~SyslogsLibrary() {}
@@ -27,9 +28,10 @@ class SyslogsLibrary : public CancelableRequestProvider {
// Logs are owned by callback function (use delete when done with them).
// Returns the request handle. Call CancelRequest(Handle) to cancel
// the request before the callback gets called.
- virtual Handle RequestSyslogs(FilePath* tmpfilename,
- CancelableRequestConsumerBase* consumer,
- ReadCompleteCallback* callback) = 0;
+ virtual Handle RequestSyslogs(
+ bool compress_logs,
+ CancelableRequestConsumerBase* consumer,
+ ReadCompleteCallback* callback) = 0;
// Factory function, creates a new instance and returns ownership.
// For normal usage, access the singleton via CrosLibrary::Get().
diff --git a/chrome/browser/chromeos/dom_ui/system_info_ui.cc b/chrome/browser/chromeos/dom_ui/system_info_ui.cc
index 4b4f7a4..8a2b42f 100644
--- a/chrome/browser/chromeos/dom_ui/system_info_ui.cc
+++ b/chrome/browser/chromeos/dom_ui/system_info_ui.cc
@@ -46,7 +46,8 @@ class SystemInfoUIHTMLSource : public ChromeURLDataManager::DataSource {
private:
~SystemInfoUIHTMLSource() {}
- void SyslogsComplete(chromeos::LogDictionaryType* sys_info);
+ void SyslogsComplete(chromeos::LogDictionaryType* sys_info,
+ std::string* ignored_content);
CancelableRequestConsumer consumer_;
@@ -92,16 +93,18 @@ void SystemInfoUIHTMLSource::StartDataRequest(const std::string& path,
chromeos::SyslogsLibrary* syslogs_lib =
chromeos::CrosLibrary::Get()->GetSyslogsLibrary();
if (syslogs_lib) {
- FilePath* tmpfilename = NULL; // use default filepath.
syslogs_lib->RequestSyslogs(
- tmpfilename,
+ false,
&consumer_,
NewCallback(this, &SystemInfoUIHTMLSource::SyslogsComplete));
}
}
void SystemInfoUIHTMLSource::SyslogsComplete(
- chromeos::LogDictionaryType* sys_info) {
+ chromeos::LogDictionaryType* sys_info,
+ std::string* ignored_content) {
+ DCHECK(!ignored_content);
+
DictionaryValue strings;
strings.SetString("title", l10n_util::GetStringUTF16(IDS_ABOUT_SYS_TITLE));
strings.SetString("description",
diff --git a/chrome/browser/dom_ui/bug_report_ui.cc b/chrome/browser/dom_ui/bug_report_ui.cc
index 19e8363..5f25867 100644
--- a/chrome/browser/dom_ui/bug_report_ui.cc
+++ b/chrome/browser/dom_ui/bug_report_ui.cc
@@ -207,7 +207,8 @@ class BugReportHandler : public DOMMessageHandler,
void CloseTab();
void SendReport();
#if defined(OS_CHROMEOS)
- void SyslogsComplete(chromeos::LogDictionaryType* logs);
+ void SyslogsComplete(chromeos::LogDictionaryType* logs,
+ std::string* zip_content);
#endif
TabContents* tab_;
@@ -229,6 +230,8 @@ class BugReportHandler : public DOMMessageHandler,
// NOTE: Extra boolean sent_report_ is required because callback may
// occur before or after we call SendReport().
bool sent_report_;
+ // Content of the compressed system logs.
+ std::string* zip_content_;
// Variables to track SyslogsLibrary::RequestSyslogs callback.
chromeos::SyslogsLibrary::Handle syslogs_handle_;
CancelableRequestConsumer syslogs_consumer_;
@@ -380,6 +383,7 @@ BugReportHandler::BugReportHandler(TabContents* tab)
, sys_info_(NULL)
, send_sys_info_(false)
, sent_report_(false)
+ , zip_content_(NULL)
, syslogs_handle_(0)
#endif
{
@@ -394,7 +398,14 @@ BugReportHandler::~BugReportHandler() {
if (syslogs_lib)
syslogs_lib->CancelRequest(syslogs_handle_);
}
- delete sys_info_;
+ if (sys_info_) {
+ delete sys_info_;
+ sys_info_ = NULL;
+ }
+ if (zip_content_) {
+ delete zip_content_;
+ zip_content_ = NULL;
+ }
#endif
}
@@ -502,9 +513,8 @@ void BugReportHandler::HandleGetDialogDefaults(const ListValue*) {
chromeos::SyslogsLibrary* syslogs_lib =
chromeos::CrosLibrary::Get()->GetSyslogsLibrary();
if (syslogs_lib) {
- FilePath* tmpfilename = NULL; // use default filepath.
syslogs_handle_ = syslogs_lib->RequestSyslogs(
- tmpfilename, &syslogs_consumer_,
+ true, &syslogs_consumer_,
NewCallback(this, &BugReportHandler::SyslogsComplete));
}
// 2: user e-mail
@@ -595,7 +605,7 @@ void BugReportHandler::HandleSendReport(const ListValue* list_value) {
// If we don't require sys_info, or we have it, or we never requested it
// (because libcros failed to load), then send the report now.
// Otherwise, the report will get sent when we receive sys_info.
- if (send_sys_info_ == false || sys_info_ != NULL || syslogs_handle_ == 0) {
+ if (!send_sys_info_ || sys_info_ != NULL || syslogs_handle_ == 0) {
SendReport();
// If we scheduled a callback, don't call SendReport() again.
send_sys_info_ = false;
@@ -620,13 +630,21 @@ void BugReportHandler::SendReport() {
, browser::screen_size.height()
#if defined(OS_CHROMEOS)
, user_email_
+ , zip_content_ ? zip_content_->c_str() : NULL
+ , zip_content_ ? zip_content_->length() : 0
, send_sys_info_ ? sys_info_ : NULL
#endif
);
#if defined(OS_CHROMEOS)
- delete sys_info_;
- sys_info_ = NULL;
+ if (sys_info_) {
+ delete sys_info_;
+ sys_info_ = NULL;
+ }
+ if (zip_content_) {
+ delete zip_content_;
+ zip_content_ = NULL;
+ }
sent_report_ = true;
#endif
@@ -635,11 +653,16 @@ void BugReportHandler::SendReport() {
#if defined(OS_CHROMEOS)
// Called from the same thread as HandleGetDialogDefaults, i.e. the UI thread.
-void BugReportHandler::SyslogsComplete(chromeos::LogDictionaryType* logs) {
+void BugReportHandler::SyslogsComplete(chromeos::LogDictionaryType* logs,
+ std::string* zip_content) {
if (sent_report_) {
// We already sent the report, just delete the data.
- delete logs;
+ if (logs)
+ delete logs;
+ if (zip_content)
+ delete zip_content;
} else {
+ zip_content_ = zip_content;
sys_info_ = logs; // Will get deleted when SendReport() is called.
if (send_sys_info_) {
// We already prepared the report, send it now.
diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc
index 0e2eca2..231edea 100644
--- a/chrome/common/chrome_switches.cc
+++ b/chrome/common/chrome_switches.cc
@@ -1176,6 +1176,9 @@ const char kStubCros[] = "stub-cros";
// URL of the html page for Screen Saver.
const char kScreenSaverUrl[] = "screen-saver-url";
+// Flag to trigger ChromeOS system log compression during feedback submit.
+const char kCompressSystemFeedback[] = "compress-sys-feedback";
+
#ifndef NDEBUG
extern const char kDOMUIMenuUrl[] = "domui-menu-url";
#endif
diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h
index 03e748f..d2cc319 100644
--- a/chrome/common/chrome_switches.h
+++ b/chrome/common/chrome_switches.h
@@ -335,6 +335,7 @@ extern const char kCandidateWindowLang[];
extern const char kBWSI[];
extern const char kStubCros[];
extern const char kScreenSaverUrl[];
+extern const char kCompressSystemFeedback[];
#ifndef NDEBUG
extern const char kDOMUIMenuUrl[];
#endif