OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/net/net_log_temp_file.h" | 5 #include "chrome/browser/net/net_log_temp_file.h" |
6 | 6 |
7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
8 #include "base/files/scoped_file.h" | 8 #include "base/files/scoped_file.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "chrome/browser/net/chrome_net_log.h" | 10 #include "chrome/browser/net/chrome_net_log.h" |
11 #include "chrome/browser/ui/webui/net_internals/net_internals_ui.h" | 11 #include "chrome/browser/ui/webui/net_internals/net_internals_ui.h" |
12 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
13 #include "net/log/net_log_logger.h" | 13 #include "net/log/write_to_file_net_log_observer.h" |
14 | 14 |
15 using content::BrowserThread; | 15 using content::BrowserThread; |
16 | 16 |
17 NetLogTempFile::NetLogTempFile(ChromeNetLog* chrome_net_log) | 17 NetLogTempFile::NetLogTempFile(ChromeNetLog* chrome_net_log) |
18 : state_(STATE_UNINITIALIZED), | 18 : state_(STATE_UNINITIALIZED), |
19 log_type_(LOG_TYPE_NONE), | 19 log_type_(LOG_TYPE_NONE), |
20 log_filename_(FILE_PATH_LITERAL("chrome-net-export-log.json")), | 20 log_filename_(FILE_PATH_LITERAL("chrome-net-export-log.json")), |
21 chrome_net_log_(chrome_net_log) { | 21 chrome_net_log_(chrome_net_log) { |
22 } | 22 } |
23 | 23 |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 // TODO(rtenneti): Find a better for doing the following. Surface some error | 137 // TODO(rtenneti): Find a better for doing the following. Surface some error |
138 // to the user if we couldn't create the file. | 138 // to the user if we couldn't create the file. |
139 base::ScopedFILE file(base::OpenFile(log_path_, "w")); | 139 base::ScopedFILE file(base::OpenFile(log_path_, "w")); |
140 if (!file) | 140 if (!file) |
141 return; | 141 return; |
142 | 142 |
143 log_type_ = log_type; | 143 log_type_ = log_type; |
144 state_ = STATE_LOGGING; | 144 state_ = STATE_LOGGING; |
145 | 145 |
146 scoped_ptr<base::Value> constants(NetInternalsUI::GetConstants()); | 146 scoped_ptr<base::Value> constants(NetInternalsUI::GetConstants()); |
147 net_log_logger_.reset(new net::NetLogLogger()); | 147 net_log_logger_.reset(new net::WriteToFileNetLogObserver()); |
148 net_log_logger_->set_log_level(GetLogLevelForLogType(log_type)); | 148 net_log_logger_->set_log_level(GetLogLevelForLogType(log_type)); |
149 net_log_logger_->StartObserving(chrome_net_log_, file.Pass(), constants.get(), | 149 net_log_logger_->StartObserving(chrome_net_log_, file.Pass(), constants.get(), |
150 nullptr); | 150 nullptr); |
151 } | 151 } |
152 | 152 |
153 void NetLogTempFile::StopNetLog() { | 153 void NetLogTempFile::StopNetLog() { |
154 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE_USER_BLOCKING)); | 154 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE_USER_BLOCKING)); |
155 if (state_ != STATE_LOGGING) | 155 if (state_ != STATE_LOGGING) |
156 return; | 156 return; |
157 | 157 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 bool NetLogTempFile::GetNetExportLogDirectory(base::FilePath* path) { | 192 bool NetLogTempFile::GetNetExportLogDirectory(base::FilePath* path) { |
193 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE_USER_BLOCKING)); | 193 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE_USER_BLOCKING)); |
194 return base::GetTempDir(path); | 194 return base::GetTempDir(path); |
195 } | 195 } |
196 | 196 |
197 bool NetLogTempFile::NetExportLogExists() { | 197 bool NetLogTempFile::NetExportLogExists() { |
198 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE_USER_BLOCKING)); | 198 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE_USER_BLOCKING)); |
199 DCHECK(!log_path_.empty()); | 199 DCHECK(!log_path_.empty()); |
200 return base::PathExists(log_path_); | 200 return base::PathExists(log_path_); |
201 } | 201 } |
OLD | NEW |