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

Side by Side Diff: content/browser/trace_subscriber_stdio.cc

Issue 9333003: Use FILE thread for disk operations in TraceSubscriberStdio (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 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
« no previous file with comments | « no previous file | content/browser/trace_subscriber_stdio_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/trace_subscriber_stdio.h" 5 #include "content/browser/trace_subscriber_stdio.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 9
10 TraceSubscriberStdio::TraceSubscriberStdio() : file_(0) { 10 TraceSubscriberStdio::TraceSubscriberStdio() : file_(0) {
11 } 11 }
12 12
13 TraceSubscriberStdio::TraceSubscriberStdio(const FilePath& path) : file_(0) { 13 TraceSubscriberStdio::TraceSubscriberStdio(const FilePath& path) : file_(0) {
14 OpenFile(path); 14 OpenFile(path);
15 } 15 }
16 16
17 TraceSubscriberStdio::~TraceSubscriberStdio() { 17 TraceSubscriberStdio::~TraceSubscriberStdio() {
18 CloseFile(); 18 CloseFile();
19 } 19 }
20 20
21 bool TraceSubscriberStdio::OpenFile(const FilePath& path) { 21 bool TraceSubscriberStdio::OpenFile(const FilePath& path) {
22 LOG(INFO) << "Logging performance trace to file: " << path.value(); 22 LOG(INFO) << "Logging performance trace to file: " << path.value();
23 CloseFile(); 23 CloseFile();
24
25 // We're in the UI thread, so creating a file is not a great thing to do!
26 // But TraceEvent is not an end user feature, so let's disable the check.
27 base::ThreadRestrictions::ScopedAllowIO scoped_allow_io;
jam 2012/02/06 20:25:29 the goal is to eventually remove ThreadRestriction
joth 2012/02/07 09:14:59 I understand what you're saying here, but several
jam 2012/02/17 23:56:34 If we keep it because a few places are valid, then
Iain Merrick 2012/02/17 23:59:33 Removed in latest patch.
24 file_ = file_util::OpenFile(path, "w+"); 28 file_ = file_util::OpenFile(path, "w+");
25 if (IsValid()) { 29 if (IsValid()) {
26 trace_buffer_.SetOutputCallback(base::Bind(&TraceSubscriberStdio::Write, 30 trace_buffer_.SetOutputCallback(base::Bind(&TraceSubscriberStdio::Write,
27 base::Unretained(this))); 31 base::Unretained(this)));
28 trace_buffer_.Start(); 32 trace_buffer_.Start();
29 return true; 33 return true;
30 } else { 34 } else {
31 LOG(ERROR) << "Failed to open performance trace file: " << path.value(); 35 LOG(ERROR) << "Failed to open performance trace file: " << path.value();
32 return false; 36 return false;
33 } 37 }
(...skipping 22 matching lines...) Expand all
56 60
57 void TraceSubscriberStdio::Write(const std::string& output_str) { 61 void TraceSubscriberStdio::Write(const std::string& output_str) {
58 if (IsValid()) { 62 if (IsValid()) {
59 size_t written = fwrite(output_str.data(), 1, output_str.size(), file_); 63 size_t written = fwrite(output_str.data(), 1, output_str.size(), file_);
60 if (written != output_str.size()) { 64 if (written != output_str.size()) {
61 LOG(ERROR) << "Error " << ferror(file_) << " when writing to trace file"; 65 LOG(ERROR) << "Error " << ferror(file_) << " when writing to trace file";
62 CloseFile(); 66 CloseFile();
63 } 67 }
64 } 68 }
65 } 69 }
OLDNEW
« no previous file with comments | « no previous file | content/browser/trace_subscriber_stdio_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698