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 // When there is a trace id attached to this report, fetch it and attach it |
| 104 // as a file. In this case, return early and retry this function later. |
| 105 if (manager && |
| 106 manager->GetTraceData( |
| 107 trace_id_, |
| 108 base::Bind(&FeedbackData::OnGetTraceData, this))) { |
| 109 return; |
| 110 } else { |
| 111 trace_id_ = 0; |
| 112 } |
| 113 } |
97 if (attached_filename_.size() && | 114 if (attached_filename_.size() && |
98 base::FilePath::IsSeparator(attached_filename_[0]) && | 115 base::FilePath::IsSeparator(attached_filename_[0]) && |
99 !attached_filedata_.get()) { | 116 !attached_filedata_.get()) { |
100 // Read the attached file and then send this report. The allocated string | 117 // Read the attached file and then send this report. The allocated string |
101 // will be freed in FeedbackUtil::SendReport. | 118 // will be freed in FeedbackUtil::SendReport. |
102 attached_filedata_.reset(new std::string); | 119 attached_filedata_.reset(new std::string); |
103 | 120 |
104 base::FilePath root = | 121 base::FilePath root = |
105 ash::Shell::GetInstance()->delegate()-> | 122 ash::Shell::GetInstance()->delegate()-> |
106 GetCurrentBrowserContext()->GetPath(); | 123 GetCurrentBrowserContext()->GetPath(); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 fetcher->Fetch(base::Bind(&FeedbackData::CompressSyslogs, this)); | 188 fetcher->Fetch(base::Bind(&FeedbackData::CompressSyslogs, this)); |
172 } | 189 } |
173 | 190 |
174 // private | 191 // private |
175 void FeedbackData::ReadAttachedFile(const base::FilePath& from) { | 192 void FeedbackData::ReadAttachedFile(const base::FilePath& from) { |
176 if (!file_util::ReadFileToString(from, attached_filedata_.get())) { | 193 if (!file_util::ReadFileToString(from, attached_filedata_.get())) { |
177 if (attached_filedata_.get()) | 194 if (attached_filedata_.get()) |
178 attached_filedata_->clear(); | 195 attached_filedata_->clear(); |
179 } | 196 } |
180 } | 197 } |
| 198 |
| 199 void FeedbackData::OnGetTraceData( |
| 200 scoped_refptr<base::RefCountedString> trace_data) { |
| 201 scoped_ptr<std::string> data(new std::string(trace_data->data())); |
| 202 |
| 203 set_attached_filename(kTraceFilename); |
| 204 set_attached_filedata(data.Pass()); |
| 205 trace_id_ = 0; |
| 206 FeedbackPageDataComplete(); |
| 207 } |
| 208 |
181 #endif | 209 #endif |
OLD | NEW |