Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Side by Side Diff: content/browser/tracing/tracing_ui.cc

Issue 12213066: Use base namespace for FilePath in content/browser (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "content/browser/tracing/tracing_ui.h" 5 #include "content/browser/tracing/tracing_ui.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 public base::SupportsWeakPtr<TracingMessageHandler>, 58 public base::SupportsWeakPtr<TracingMessageHandler>,
59 public TraceSubscriber { 59 public TraceSubscriber {
60 public: 60 public:
61 TracingMessageHandler(); 61 TracingMessageHandler();
62 virtual ~TracingMessageHandler(); 62 virtual ~TracingMessageHandler();
63 63
64 // WebUIMessageHandler implementation. 64 // WebUIMessageHandler implementation.
65 virtual void RegisterMessages(); 65 virtual void RegisterMessages();
66 66
67 // SelectFileDialog::Listener implementation 67 // SelectFileDialog::Listener implementation
68 virtual void FileSelected(const FilePath& path, int index, void* params); 68 virtual void FileSelected(const base::FilePath& path,
69 int index,
70 void* params);
69 virtual void FileSelectionCanceled(void* params); 71 virtual void FileSelectionCanceled(void* params);
70 72
71 // TraceSubscriber implementation. 73 // TraceSubscriber implementation.
72 virtual void OnEndTracingComplete(); 74 virtual void OnEndTracingComplete();
73 virtual void OnTraceDataCollected( 75 virtual void OnTraceDataCollected(
74 const scoped_refptr<base::RefCountedString>& trace_fragment); 76 const scoped_refptr<base::RefCountedString>& trace_fragment);
75 virtual void OnTraceBufferPercentFullReply(float percent_full); 77 virtual void OnTraceBufferPercentFullReply(float percent_full);
76 78
77 // Messages. 79 // Messages.
78 void OnTracingControllerInitialized(const ListValue* list); 80 void OnTracingControllerInitialized(const ListValue* list);
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 } 207 }
206 } 208 }
207 209
208 void TracingMessageHandler::OnBeginRequestBufferPercentFull( 210 void TracingMessageHandler::OnBeginRequestBufferPercentFull(
209 const ListValue* list) { 211 const ListValue* list) {
210 TraceController::GetInstance()->GetTraceBufferPercentFullAsync(this); 212 TraceController::GetInstance()->GetTraceBufferPercentFullAsync(this);
211 } 213 }
212 214
213 // A callback used for asynchronously reading a file to a string. Calls the 215 // A callback used for asynchronously reading a file to a string. Calls the
214 // TaskProxy callback when reading is complete. 216 // TaskProxy callback when reading is complete.
215 void ReadTraceFileCallback(TaskProxy* proxy, const FilePath& path) { 217 void ReadTraceFileCallback(TaskProxy* proxy, const base::FilePath& path) {
216 std::string file_contents; 218 std::string file_contents;
217 if (!file_util::ReadFileToString(path, &file_contents)) 219 if (!file_util::ReadFileToString(path, &file_contents))
218 return; 220 return;
219 221
220 // We need to escape the file contents, because it will go into a javascript 222 // We need to escape the file contents, because it will go into a javascript
221 // quoted string in TracingMessageHandler::LoadTraceFileComplete. We need to 223 // quoted string in TracingMessageHandler::LoadTraceFileComplete. We need to
222 // escape control characters (to have well-formed javascript statements), as 224 // escape control characters (to have well-formed javascript statements), as
223 // well as \ and ' (the only special characters in a ''-quoted string). 225 // well as \ and ' (the only special characters in a ''-quoted string).
224 // Do the escaping on this thread, it may take a little while for big files 226 // Do the escaping on this thread, it may take a little while for big files
225 // and we don't want to block the UI during that time. Also do the UTF-16 227 // and we don't want to block the UI during that time. Also do the UTF-16
(...skipping 22 matching lines...) Expand all
248 250
249 BrowserThread::PostTask( 251 BrowserThread::PostTask(
250 BrowserThread::UI, FROM_HERE, 252 BrowserThread::UI, FROM_HERE,
251 base::Bind(&TaskProxy::LoadTraceFileCompleteProxy, proxy, 253 base::Bind(&TaskProxy::LoadTraceFileCompleteProxy, proxy,
252 contents16.release())); 254 contents16.release()));
253 } 255 }
254 256
255 // A callback used for asynchronously writing a file from a string. Calls the 257 // A callback used for asynchronously writing a file from a string. Calls the
256 // TaskProxy callback when writing is complete. 258 // TaskProxy callback when writing is complete.
257 void WriteTraceFileCallback(TaskProxy* proxy, 259 void WriteTraceFileCallback(TaskProxy* proxy,
258 const FilePath& path, 260 const base::FilePath& path,
259 std::string* contents) { 261 std::string* contents) {
260 if (!file_util::WriteFile(path, contents->c_str(), contents->size())) 262 if (!file_util::WriteFile(path, contents->c_str(), contents->size()))
261 return; 263 return;
262 264
263 BrowserThread::PostTask( 265 BrowserThread::PostTask(
264 BrowserThread::UI, FROM_HERE, 266 BrowserThread::UI, FROM_HERE,
265 base::Bind(&TaskProxy::SaveTraceFileCompleteProxy, proxy)); 267 base::Bind(&TaskProxy::SaveTraceFileCompleteProxy, proxy));
266 } 268 }
267 269
268 void TracingMessageHandler::FileSelected( 270 void TracingMessageHandler::FileSelected(
269 const FilePath& path, int index, void* params) { 271 const base::FilePath& path, int index, void* params) {
270 if (select_trace_file_dialog_type_ == 272 if (select_trace_file_dialog_type_ ==
271 ui::SelectFileDialog::SELECT_OPEN_FILE) { 273 ui::SelectFileDialog::SELECT_OPEN_FILE) {
272 BrowserThread::PostTask( 274 BrowserThread::PostTask(
273 BrowserThread::FILE, FROM_HERE, 275 BrowserThread::FILE, FROM_HERE,
274 base::Bind(&ReadTraceFileCallback, 276 base::Bind(&ReadTraceFileCallback,
275 make_scoped_refptr(new TaskProxy(AsWeakPtr())), path)); 277 make_scoped_refptr(new TaskProxy(AsWeakPtr())), path));
276 } else { 278 } else {
277 BrowserThread::PostTask( 279 BrowserThread::PostTask(
278 BrowserThread::FILE, FROM_HERE, 280 BrowserThread::FILE, FROM_HERE,
279 base::Bind(&WriteTraceFileCallback, 281 base::Bind(&WriteTraceFileCallback,
(...skipping 21 matching lines...) Expand all
301 if (select_trace_file_dialog_.get()) 303 if (select_trace_file_dialog_.get())
302 return; 304 return;
303 select_trace_file_dialog_type_ = ui::SelectFileDialog::SELECT_OPEN_FILE; 305 select_trace_file_dialog_type_ = ui::SelectFileDialog::SELECT_OPEN_FILE;
304 select_trace_file_dialog_ = ui::SelectFileDialog::Create( 306 select_trace_file_dialog_ = ui::SelectFileDialog::Create(
305 this, 307 this,
306 GetContentClient()->browser()->CreateSelectFilePolicy( 308 GetContentClient()->browser()->CreateSelectFilePolicy(
307 web_ui()->GetWebContents())); 309 web_ui()->GetWebContents()));
308 select_trace_file_dialog_->SelectFile( 310 select_trace_file_dialog_->SelectFile(
309 ui::SelectFileDialog::SELECT_OPEN_FILE, 311 ui::SelectFileDialog::SELECT_OPEN_FILE,
310 string16(), 312 string16(),
311 FilePath(), 313 base::FilePath(),
312 NULL, 0, FILE_PATH_LITERAL(""), 314 NULL, 0, FILE_PATH_LITERAL(""),
313 web_ui()->GetWebContents()->GetView()->GetTopLevelNativeWindow(), NULL); 315 web_ui()->GetWebContents()->GetView()->GetTopLevelNativeWindow(), NULL);
314 } 316 }
315 317
316 void TracingMessageHandler::LoadTraceFileComplete(string16* contents) { 318 void TracingMessageHandler::LoadTraceFileComplete(string16* contents) {
317 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 319 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
318 320
319 // We need to pass contents to tracingController.onLoadTraceFileComplete, but 321 // We need to pass contents to tracingController.onLoadTraceFileComplete, but
320 // that may be arbitrarily big, and IPCs messages are limited in size. So we 322 // that may be arbitrarily big, and IPCs messages are limited in size. So we
321 // need to cut it into pieces and rebuild the string in Javascript. 323 // need to cut it into pieces and rebuild the string in Javascript.
(...skipping 29 matching lines...) Expand all
351 trace_data_to_save_.reset(trace_data); 353 trace_data_to_save_.reset(trace_data);
352 354
353 select_trace_file_dialog_type_ = ui::SelectFileDialog::SELECT_SAVEAS_FILE; 355 select_trace_file_dialog_type_ = ui::SelectFileDialog::SELECT_SAVEAS_FILE;
354 select_trace_file_dialog_ = ui::SelectFileDialog::Create( 356 select_trace_file_dialog_ = ui::SelectFileDialog::Create(
355 this, 357 this,
356 GetContentClient()->browser()->CreateSelectFilePolicy( 358 GetContentClient()->browser()->CreateSelectFilePolicy(
357 web_ui()->GetWebContents())); 359 web_ui()->GetWebContents()));
358 select_trace_file_dialog_->SelectFile( 360 select_trace_file_dialog_->SelectFile(
359 ui::SelectFileDialog::SELECT_SAVEAS_FILE, 361 ui::SelectFileDialog::SELECT_SAVEAS_FILE,
360 string16(), 362 string16(),
361 FilePath(), 363 base::FilePath(),
362 NULL, 0, FILE_PATH_LITERAL(""), 364 NULL, 0, FILE_PATH_LITERAL(""),
363 web_ui()->GetWebContents()->GetView()->GetTopLevelNativeWindow(), NULL); 365 web_ui()->GetWebContents()->GetView()->GetTopLevelNativeWindow(), NULL);
364 } 366 }
365 367
366 void TracingMessageHandler::SaveTraceFileComplete() { 368 void TracingMessageHandler::SaveTraceFileComplete() {
367 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 369 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
368 web_ui()->CallJavascriptFunction("tracingController.onSaveTraceFileComplete"); 370 web_ui()->CallJavascriptFunction("tracingController.onSaveTraceFileComplete");
369 } 371 }
370 372
371 void TracingMessageHandler::OnBeginTracing(const ListValue* args) { 373 void TracingMessageHandler::OnBeginTracing(const ListValue* args) {
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 TracingUI::TracingUI(WebUI* web_ui) : WebUIController(web_ui) { 484 TracingUI::TracingUI(WebUI* web_ui) : WebUIController(web_ui) {
483 web_ui->AddMessageHandler(new TracingMessageHandler()); 485 web_ui->AddMessageHandler(new TracingMessageHandler());
484 486
485 // Set up the chrome://tracing/ source. 487 // Set up the chrome://tracing/ source.
486 BrowserContext* browser_context = 488 BrowserContext* browser_context =
487 web_ui->GetWebContents()->GetBrowserContext(); 489 web_ui->GetWebContents()->GetBrowserContext();
488 WebUIDataSource::Add(browser_context, CreateTracingHTMLSource()); 490 WebUIDataSource::Add(browser_context, CreateTracingHTMLSource());
489 } 491 }
490 492
491 } // namespace content 493 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/tracing/trace_subscriber_stdio_unittest.cc ('k') | content/browser/utility_process_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698