Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/feedback/feedback_data.h" | 5 #include "chrome/browser/feedback/feedback_data.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/json/json_string_value_serializer.h" | 8 #include "base/json/json_string_value_serializer.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/chromeos/settings/cros_settings.h" | 12 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 13 #include "chrome/browser/feedback/feedback_util.h" | 13 #include "chrome/browser/feedback/feedback_util.h" |
| 14 #include "chrome/browser/feedback/tracing_manager.h" | |
| 14 #include "chrome/browser/profiles/profile_manager.h" | 15 #include "chrome/browser/profiles/profile_manager.h" |
| 15 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 16 | 17 |
| 17 #if defined(USE_ASH) | 18 #if defined(USE_ASH) |
| 18 #include "ash/shell.h" | 19 #include "ash/shell.h" |
| 19 #include "ash/shell_delegate.h" | 20 #include "ash/shell_delegate.h" |
| 20 #endif | 21 #endif |
| 21 | 22 |
| 22 using content::BrowserThread; | 23 using content::BrowserThread; |
| 23 | 24 |
| 24 #if defined(OS_CHROMEOS) | 25 #if defined(OS_CHROMEOS) |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| 27 const char kMultilineIndicatorString[] = "<multiline>\n"; | 28 const char kMultilineIndicatorString[] = "<multiline>\n"; |
| 28 const char kMultilineStartString[] = "---------- START ----------\n"; | 29 const char kMultilineStartString[] = "---------- START ----------\n"; |
| 29 const char kMultilineEndString[] = "---------- END ----------\n\n"; | 30 const char kMultilineEndString[] = "---------- END ----------\n\n"; |
| 30 | 31 |
| 32 const char kTraceFilename[] = "tracing.log\n"; | |
| 33 | |
| 31 std::string LogsToString(chromeos::SystemLogsResponse* sys_info) { | 34 std::string LogsToString(chromeos::SystemLogsResponse* sys_info) { |
| 32 std::string syslogs_string; | 35 std::string syslogs_string; |
| 33 for (chromeos::SystemLogsResponse::const_iterator it = sys_info->begin(); | 36 for (chromeos::SystemLogsResponse::const_iterator it = sys_info->begin(); |
| 34 it != sys_info->end(); ++it) { | 37 it != sys_info->end(); ++it) { |
| 35 std::string key = it->first; | 38 std::string key = it->first; |
| 36 std::string value = it->second; | 39 std::string value = it->second; |
| 37 | 40 |
| 38 TrimString(key, "\n ", &key); | 41 TrimString(key, "\n ", &key); |
| 39 TrimString(value, "\n ", &value); | 42 TrimString(value, "\n ", &value); |
| 40 | 43 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 60 } | 63 } |
| 61 } | 64 } |
| 62 | 65 |
| 63 } // namespace | 66 } // namespace |
| 64 #endif // OS_CHROMEOS | 67 #endif // OS_CHROMEOS |
| 65 | 68 |
| 66 FeedbackData::FeedbackData() : profile_(NULL), | 69 FeedbackData::FeedbackData() : profile_(NULL), |
| 67 feedback_page_data_complete_(false) { | 70 feedback_page_data_complete_(false) { |
| 68 #if defined(OS_CHROMEOS) | 71 #if defined(OS_CHROMEOS) |
| 69 sys_info_.reset(NULL); | 72 sys_info_.reset(NULL); |
| 73 trace_id_ = 0; | |
| 70 attached_filedata_.reset(NULL); | 74 attached_filedata_.reset(NULL); |
| 71 send_sys_info_ = true; | 75 send_sys_info_ = true; |
| 72 read_attached_file_complete_ = false; | 76 read_attached_file_complete_ = false; |
| 73 syslogs_collection_complete_ = false; | 77 syslogs_collection_complete_ = false; |
| 74 #endif | 78 #endif |
| 75 } | 79 } |
| 76 | 80 |
| 77 FeedbackData::~FeedbackData() { | 81 FeedbackData::~FeedbackData() { |
| 78 } | 82 } |
| 79 | 83 |
| 80 bool FeedbackData::DataCollectionComplete() { | 84 bool FeedbackData::DataCollectionComplete() { |
| 81 #if defined(OS_CHROMEOS) | 85 #if defined(OS_CHROMEOS) |
| 82 return (syslogs_collection_complete_ || !send_sys_info_) && | 86 return (syslogs_collection_complete_ || !send_sys_info_) && |
| 83 read_attached_file_complete_ && | 87 read_attached_file_complete_ && |
| 84 feedback_page_data_complete_; | 88 feedback_page_data_complete_; |
| 85 #else | 89 #else |
| 86 return feedback_page_data_complete_; | 90 return feedback_page_data_complete_; |
| 87 #endif | 91 #endif |
| 88 } | 92 } |
| 89 void FeedbackData::SendReport() { | 93 void FeedbackData::SendReport() { |
| 90 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 94 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 91 if (DataCollectionComplete()) | 95 if (DataCollectionComplete()) |
| 92 FeedbackUtil::SendReport(this); | 96 FeedbackUtil::SendReport(this); |
| 93 } | 97 } |
| 94 | 98 |
| 95 void FeedbackData::FeedbackPageDataComplete() { | 99 void FeedbackData::FeedbackPageDataComplete() { |
| 96 #if defined(OS_CHROMEOS) | 100 #if defined(OS_CHROMEOS) |
| 101 if (trace_id_ != 0) { | |
| 102 TracingManager* manager = TracingManager::Get(); | |
| 103 if (manager && | |
| 104 manager->GetTraceData( | |
| 105 trace_id_, | |
| 106 base::Bind(&FeedbackData::OnGetTraceData, this))) { | |
| 107 return; | |
|
rkc
2013/08/09 21:15:44
Nit: Document this early return, this confused me
Zachary Kuznia
2013/08/09 21:45:28
Done.
| |
| 108 } else { | |
| 109 trace_id_ = 0; | |
| 110 } | |
| 111 } | |
| 97 if (attached_filename_.size() && | 112 if (attached_filename_.size() && |
| 98 base::FilePath::IsSeparator(attached_filename_[0]) && | 113 base::FilePath::IsSeparator(attached_filename_[0]) && |
| 99 !attached_filedata_.get()) { | 114 !attached_filedata_.get()) { |
| 100 // Read the attached file and then send this report. The allocated string | 115 // Read the attached file and then send this report. The allocated string |
| 101 // will be freed in FeedbackUtil::SendReport. | 116 // will be freed in FeedbackUtil::SendReport. |
| 102 attached_filedata_.reset(new std::string); | 117 attached_filedata_.reset(new std::string); |
| 103 | 118 |
| 104 base::FilePath root = | 119 base::FilePath root = |
| 105 ash::Shell::GetInstance()->delegate()-> | 120 ash::Shell::GetInstance()->delegate()-> |
| 106 GetCurrentBrowserContext()->GetPath(); | 121 GetCurrentBrowserContext()->GetPath(); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 171 fetcher->Fetch(base::Bind(&FeedbackData::CompressSyslogs, this)); | 186 fetcher->Fetch(base::Bind(&FeedbackData::CompressSyslogs, this)); |
| 172 } | 187 } |
| 173 | 188 |
| 174 // private | 189 // private |
| 175 void FeedbackData::ReadAttachedFile(const base::FilePath& from) { | 190 void FeedbackData::ReadAttachedFile(const base::FilePath& from) { |
| 176 if (!file_util::ReadFileToString(from, attached_filedata_.get())) { | 191 if (!file_util::ReadFileToString(from, attached_filedata_.get())) { |
| 177 if (attached_filedata_.get()) | 192 if (attached_filedata_.get()) |
| 178 attached_filedata_->clear(); | 193 attached_filedata_->clear(); |
| 179 } | 194 } |
| 180 } | 195 } |
| 196 | |
| 197 void FeedbackData::OnGetTraceData( | |
| 198 scoped_refptr<base::RefCountedString> trace_data) { | |
| 199 scoped_ptr<std::string> data(new std::string(trace_data->data())); | |
| 200 | |
| 201 set_attached_filename(kTraceFilename); | |
| 202 set_attached_filedata(data.Pass()); | |
| 203 trace_id_ = 0; | |
| 204 FeedbackPageDataComplete(); | |
| 205 } | |
| 206 | |
| 181 #endif | 207 #endif |
| OLD | NEW |