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/ui/webui/net_internals/net_internals_ui.h" | 5 #include "chrome/browser/ui/webui/net_internals/net_internals_ui.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <list> | 8 #include <list> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
159 #ifdef OS_CHROMEOS | 159 #ifdef OS_CHROMEOS |
160 // Following functions are used for getting debug logs. Logs are | 160 // Following functions are used for getting debug logs. Logs are |
161 // fetched from /var/log/* and put on the fileshelf. | 161 // fetched from /var/log/* and put on the fileshelf. |
162 | 162 |
163 // Called once StoreDebugLogs is complete. Takes two parameters: | 163 // Called once StoreDebugLogs is complete. Takes two parameters: |
164 // - log_path: where the log file was saved in the case of success; | 164 // - log_path: where the log file was saved in the case of success; |
165 // - succeeded: was the log file saved successfully. | 165 // - succeeded: was the log file saved successfully. |
166 typedef base::Callback<void(const FilePath& log_path, | 166 typedef base::Callback<void(const FilePath& log_path, |
167 bool succeded)> StoreDebugLogsCallback; | 167 bool succeded)> StoreDebugLogsCallback; |
168 | 168 |
169 // Deletes debug log file, so should be called on the FILE thread. | |
170 void DeleteDebugLogFile(const FilePath& log_path) { | |
171 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | |
172 file_util::Delete(log_path, false); | |
173 } | |
174 | |
169 // Called once creation of the debug log file is completed. If | 175 // Called once creation of the debug log file is completed. If |
170 // creation failed, deletes the file by |log_path|. So, this function | 176 // creation failed, deletes the file by |log_path|. After all, calls |
171 // should be called on the FILE thread. After all, calls |callback| on | 177 // |callback| on the UI thread. |
172 // the UI thread. | |
173 void CreateDebugLogFileCompleted(const StoreDebugLogsCallback& callback, | 178 void CreateDebugLogFileCompleted(const StoreDebugLogsCallback& callback, |
174 const FilePath& log_path, | 179 const FilePath& log_path, |
175 bool succeeded) { | 180 bool succeeded) { |
176 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 181 if (!succeeded) { |
177 | 182 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
178 if (!succeeded) | 183 base::Bind(&DeleteDebugLogFile, log_path)); |
179 file_util::Delete(log_path, false); | 184 } |
180 | |
181 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 185 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
182 base::Bind(callback, log_path, succeeded)); | 186 base::Bind(callback, log_path, succeeded)); |
183 } | 187 } |
184 | 188 |
185 // Retrieves debug logs from DebugDaemon and puts them on the | 189 // Retrieves debug logs from DebugDaemon and puts them on the |
186 // fileshelf directory into .tgz archive. So, this function should be | 190 // fileshelf directory into .tgz archive. So, this function should be |
187 // called on the FILE thread. Calls CreateDebugLogFileCompleted on the | 191 // called on the FILE thread. Calls CreateDebugLogFileCompleted on the |
188 // FILE thread when creation of archive is completed. | 192 // FILE thread when creation of archive is completed. |
189 void CreateDebugLogFile(const StoreDebugLogsCallback& callback) { | 193 void CreateDebugLogFile(const StoreDebugLogsCallback& callback) { |
190 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 194 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
191 | 195 |
192 const FilePath::CharType kLogFileName[] = FILE_PATH_LITERAL("debug-log.tgz"); | 196 const FilePath::CharType kLogFileName[] = FILE_PATH_LITERAL("debug-log.tgz"); |
193 | 197 |
194 FilePath fileshelf_dir; | 198 FilePath fileshelf_dir; |
195 if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, &fileshelf_dir)) { | 199 if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS_SAFE, &fileshelf_dir)) { |
Sam Leffler
2012/05/14 15:52:38
should this be download_util::GetDefaultDownloadDi
ygorshenin1
2012/05/15 12:46:20
Done.
| |
196 LOG(ERROR) << "Can't get fileshelf dir"; | 200 LOG(ERROR) << "Can't get fileshelf dir"; |
197 CreateDebugLogFileCompleted(callback, FilePath(), false); | 201 CreateDebugLogFileCompleted(callback, FilePath(), false); |
198 return; | 202 return; |
199 } | 203 } |
200 | 204 |
201 FilePath log_path = fileshelf_dir.Append(kLogFileName); | 205 FilePath log_path = fileshelf_dir.Append(kLogFileName); |
202 log_path = logging::GenerateTimestampedName(log_path, base::Time::Now()); | 206 log_path = logging::GenerateTimestampedName(log_path, base::Time::Now()); |
203 | 207 |
204 int flags = base::PLATFORM_FILE_CREATE_ALWAYS | | 208 int flags = base::PLATFORM_FILE_CREATE_ALWAYS | |
205 base::PLATFORM_FILE_WRITE; | 209 base::PLATFORM_FILE_WRITE; |
206 bool created; | 210 bool created; |
207 PlatformFileError error; | 211 PlatformFileError error; |
208 PlatformFile log_file = base::CreatePlatformFile( | 212 PlatformFile log_file = base::CreatePlatformFile( |
209 log_path, flags, &created, &error); | 213 log_path, flags, &created, &error); |
Sam Leffler
2012/05/14 15:52:38
feels like this belongs in download_util (just a c
| |
210 | 214 |
211 if (!created) { | 215 if (!created) { |
212 LOG(ERROR) << | 216 LOG(ERROR) << |
213 "Can't create log file: " << log_path.AsUTF8Unsafe() << ", " << | 217 "Can't create log file: " << log_path.AsUTF8Unsafe() << ", " << |
214 "error: " << error; | 218 "error: " << error; |
215 CreateDebugLogFileCompleted(callback, log_path, false); | 219 CreateDebugLogFileCompleted(callback, log_path, false); |
216 return; | 220 return; |
217 } | 221 } |
218 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient()-> | 222 |
219 GetDebugLogs(log_file, | 223 chromeos::DebugDaemonClient* client = |
220 base::Bind(&CreateDebugLogFileCompleted, | 224 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient(); |
221 callback, log_path)); | 225 BrowserThread::PostTask( |
226 BrowserThread::UI, FROM_HERE, | |
227 base::Bind(&chromeos::DebugDaemonClient::GetDebugLogs, | |
228 base::Unretained(client), | |
229 log_file, | |
230 base::Bind(&CreateDebugLogFileCompleted, | |
231 callback, | |
232 log_path))); | |
222 } | 233 } |
223 | 234 |
224 // Delegates the job of saving debug logs on the fileshelf to | 235 // Delegates the job of saving debug logs on the fileshelf to |
225 // CreateDebugLogsFile on the FILE thread. Calls |callback| on the UI | 236 // CreateDebugLogsFile on the FILE thread. Calls |callback| on the UI |
226 // thread when saving is completed. This function should be called on | 237 // thread when saving is completed. This function should be called on |
227 // the UI thread. | 238 // the UI thread. |
228 void StoreDebugLogs(const StoreDebugLogsCallback& callback) { | 239 void StoreDebugLogs(const StoreDebugLogsCallback& callback) { |
229 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 240 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
230 | 241 |
231 BrowserThread::PostTask( | 242 BrowserThread::PostTask( |
Sam Leffler
2012/05/14 15:52:38
I think it's cleaner to make this a call to Browse
ygorshenin1
2012/05/15 12:46:20
Thanks! It's a cool idea to use WorkerPool for fil
| |
232 BrowserThread::FILE, FROM_HERE, | 243 BrowserThread::FILE, FROM_HERE, |
233 base::Bind(&CreateDebugLogFile, callback)); | 244 base::Bind(&CreateDebugLogFile, callback)); |
234 } | 245 } |
235 #endif // OS_CHROMEOS | 246 #endif // OS_CHROMEOS |
236 | 247 |
237 // This class receives javascript messages from the renderer. | 248 // This class receives javascript messages from the renderer. |
238 // Note that the WebUI infrastructure runs on the UI thread, therefore all of | 249 // Note that the WebUI infrastructure runs on the UI thread, therefore all of |
239 // this class's methods are expected to run on the UI thread. | 250 // this class's methods are expected to run on the UI thread. |
240 // | 251 // |
241 // Since the network code we want to run lives on the IO thread, we proxy | 252 // Since the network code we want to run lives on the IO thread, we proxy |
(...skipping 1428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1670 } | 1681 } |
1671 | 1682 |
1672 NetInternalsUI::NetInternalsUI(content::WebUI* web_ui) | 1683 NetInternalsUI::NetInternalsUI(content::WebUI* web_ui) |
1673 : WebUIController(web_ui) { | 1684 : WebUIController(web_ui) { |
1674 web_ui->AddMessageHandler(new NetInternalsMessageHandler()); | 1685 web_ui->AddMessageHandler(new NetInternalsMessageHandler()); |
1675 | 1686 |
1676 // Set up the chrome://net-internals/ source. | 1687 // Set up the chrome://net-internals/ source. |
1677 Profile* profile = Profile::FromWebUI(web_ui); | 1688 Profile* profile = Profile::FromWebUI(web_ui); |
1678 ChromeURLDataManager::AddDataSource(profile, CreateNetInternalsHTMLSource()); | 1689 ChromeURLDataManager::AddDataSource(profile, CreateNetInternalsHTMLSource()); |
1679 } | 1690 } |
OLD | NEW |