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

Side by Side Diff: chrome/browser/ui/webui/net_export_ui.cc

Issue 1347043002: Move ChromeNetLog to //components (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: DetachFromThread Created 5 years, 3 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
OLDNEW
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/ui/webui/net_export_ui.h" 5 #include "chrome/browser/ui/webui/net_export_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/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "chrome/browser/browser_process.h" 14 #include "chrome/browser/browser_process.h"
15 #include "chrome/browser/net/chrome_net_log.h"
16 #include "chrome/browser/net/net_log_temp_file.h"
17 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/common/url_constants.h" 16 #include "chrome/common/url_constants.h"
17 #include "components/net_log/chrome_net_log.h"
18 #include "components/net_log/net_log_temp_file.h"
19 #include "content/public/browser/browser_thread.h" 19 #include "content/public/browser/browser_thread.h"
20 #include "content/public/browser/url_data_source.h" 20 #include "content/public/browser/url_data_source.h"
21 #include "content/public/browser/web_contents.h" 21 #include "content/public/browser/web_contents.h"
22 #include "content/public/browser/web_ui.h" 22 #include "content/public/browser/web_ui.h"
23 #include "content/public/browser/web_ui_data_source.h" 23 #include "content/public/browser/web_ui_data_source.h"
24 #include "content/public/browser/web_ui_message_handler.h" 24 #include "content/public/browser/web_ui_message_handler.h"
25 #include "grit/browser_resources.h" 25 #include "grit/browser_resources.h"
26 26
27 #if defined(OS_ANDROID) 27 #if defined(OS_ANDROID)
28 #include "chrome/browser/android/intent_helper.h" 28 #include "chrome/browser/android/intent_helper.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 // Messages. 61 // Messages.
62 void OnGetExportNetLogInfo(const base::ListValue* list); 62 void OnGetExportNetLogInfo(const base::ListValue* list);
63 void OnStartNetLog(const base::ListValue* list); 63 void OnStartNetLog(const base::ListValue* list);
64 void OnStopNetLog(const base::ListValue* list); 64 void OnStopNetLog(const base::ListValue* list);
65 void OnSendNetLog(const base::ListValue* list); 65 void OnSendNetLog(const base::ListValue* list);
66 66
67 private: 67 private:
68 // Calls NetLogTempFile's ProcessCommand with DO_START and DO_STOP commands. 68 // Calls NetLogTempFile's ProcessCommand with DO_START and DO_STOP commands.
69 static void ProcessNetLogCommand( 69 static void ProcessNetLogCommand(
70 base::WeakPtr<NetExportMessageHandler> net_export_message_handler, 70 base::WeakPtr<NetExportMessageHandler> net_export_message_handler,
71 NetLogTempFile* net_log_temp_file, 71 net_log::NetLogTempFile* net_log_temp_file,
eroman 2015/09/16 20:52:21 Observation: the distinction of the "net_log" name
droger 2015/09/17 08:39:10 I need to componentize some code from net-export a
72 NetLogTempFile::Command command); 72 net_log::NetLogTempFile::Command command);
73 73
74 // Returns the path to the file which has NetLog data. 74 // Returns the path to the file which has NetLog data.
75 static base::FilePath GetNetLogFileName(NetLogTempFile* net_log_temp_file); 75 static base::FilePath GetNetLogFileName(
76 net_log::NetLogTempFile* net_log_temp_file);
76 77
77 // Send state/file information from NetLogTempFile. 78 // Send state/file information from NetLogTempFile.
78 static void SendExportNetLogInfo( 79 static void SendExportNetLogInfo(
79 base::WeakPtr<NetExportMessageHandler> net_export_message_handler, 80 base::WeakPtr<NetExportMessageHandler> net_export_message_handler,
80 NetLogTempFile* net_log_temp_file); 81 net_log::NetLogTempFile* net_log_temp_file);
81 82
82 // Send NetLog data via email. This runs on UI thread. 83 // Send NetLog data via email. This runs on UI thread.
83 static void SendEmail(const base::FilePath& file_to_send); 84 static void SendEmail(const base::FilePath& file_to_send);
84 85
85 // Call NetExportView.onExportNetLogInfoChanged JavsScript function in the 86 // Call NetExportView.onExportNetLogInfoChanged JavsScript function in the
86 // renderer, passing in |arg|. Takes ownership of |arg|. 87 // renderer, passing in |arg|. Takes ownership of |arg|.
87 void OnExportNetLogInfoChanged(base::Value* arg); 88 void OnExportNetLogInfoChanged(base::Value* arg);
88 89
89 // Cache of g_browser_process->net_log()->net_log_temp_file(). 90 // Cache of g_browser_process->net_log()->net_log_temp_file().
90 NetLogTempFile* net_log_temp_file_; 91 net_log::NetLogTempFile* net_log_temp_file_;
91 92
92 base::WeakPtrFactory<NetExportMessageHandler> weak_ptr_factory_; 93 base::WeakPtrFactory<NetExportMessageHandler> weak_ptr_factory_;
93 94
94 DISALLOW_COPY_AND_ASSIGN(NetExportMessageHandler); 95 DISALLOW_COPY_AND_ASSIGN(NetExportMessageHandler);
95 }; 96 };
96 97
97 NetExportMessageHandler::NetExportMessageHandler() 98 NetExportMessageHandler::NetExportMessageHandler()
98 : net_log_temp_file_(g_browser_process->net_log()->net_log_temp_file()), 99 : net_log_temp_file_(g_browser_process->net_log()->net_log_temp_file()),
99 weak_ptr_factory_(this) { 100 weak_ptr_factory_(this) {
100 } 101 }
101 102
102 NetExportMessageHandler::~NetExportMessageHandler() { 103 NetExportMessageHandler::~NetExportMessageHandler() {
103 // Cancel any in-progress requests to collect net_log into temporary file. 104 // Cancel any in-progress requests to collect net_log into temporary file.
104 BrowserThread::PostTask( 105 BrowserThread::PostTask(BrowserThread::FILE_USER_BLOCKING, FROM_HERE,
105 BrowserThread::FILE_USER_BLOCKING, 106 base::Bind(&net_log::NetLogTempFile::ProcessCommand,
106 FROM_HERE, 107 base::Unretained(net_log_temp_file_),
107 base::Bind(&NetLogTempFile::ProcessCommand, 108 net_log::NetLogTempFile::DO_STOP));
108 base::Unretained(net_log_temp_file_),
109 NetLogTempFile::DO_STOP));
110 } 109 }
111 110
112 void NetExportMessageHandler::RegisterMessages() { 111 void NetExportMessageHandler::RegisterMessages() {
113 DCHECK_CURRENTLY_ON(BrowserThread::UI); 112 DCHECK_CURRENTLY_ON(BrowserThread::UI);
114 113
115 web_ui()->RegisterMessageCallback( 114 web_ui()->RegisterMessageCallback(
116 "getExportNetLogInfo", 115 "getExportNetLogInfo",
117 base::Bind(&NetExportMessageHandler::OnGetExportNetLogInfo, 116 base::Bind(&NetExportMessageHandler::OnGetExportNetLogInfo,
118 base::Unretained(this))); 117 base::Unretained(this)));
119 web_ui()->RegisterMessageCallback( 118 web_ui()->RegisterMessageCallback(
(...skipping 18 matching lines...) Expand all
138 base::Bind(&NetExportMessageHandler::SendExportNetLogInfo, 137 base::Bind(&NetExportMessageHandler::SendExportNetLogInfo,
139 weak_ptr_factory_.GetWeakPtr(), 138 weak_ptr_factory_.GetWeakPtr(),
140 net_log_temp_file_)); 139 net_log_temp_file_));
141 } 140 }
142 141
143 void NetExportMessageHandler::OnStartNetLog(const base::ListValue* list) { 142 void NetExportMessageHandler::OnStartNetLog(const base::ListValue* list) {
144 std::string log_mode; 143 std::string log_mode;
145 bool result = list->GetString(0, &log_mode); 144 bool result = list->GetString(0, &log_mode);
146 DCHECK(result); 145 DCHECK(result);
147 146
148 NetLogTempFile::Command command; 147 net_log::NetLogTempFile::Command command;
149 if (log_mode == "LOG_BYTES") { 148 if (log_mode == "LOG_BYTES") {
150 command = NetLogTempFile::DO_START_LOG_BYTES; 149 command = net_log::NetLogTempFile::DO_START_LOG_BYTES;
151 } else if (log_mode == "NORMAL") { 150 } else if (log_mode == "NORMAL") {
152 command = NetLogTempFile::DO_START; 151 command = net_log::NetLogTempFile::DO_START;
153 } else { 152 } else {
154 DCHECK_EQ("STRIP_PRIVATE_DATA", log_mode); 153 DCHECK_EQ("STRIP_PRIVATE_DATA", log_mode);
155 command = NetLogTempFile::DO_START_STRIP_PRIVATE_DATA; 154 command = net_log::NetLogTempFile::DO_START_STRIP_PRIVATE_DATA;
156 } 155 }
157 156
158 ProcessNetLogCommand(weak_ptr_factory_.GetWeakPtr(), net_log_temp_file_, 157 ProcessNetLogCommand(weak_ptr_factory_.GetWeakPtr(), net_log_temp_file_,
159 command); 158 command);
160 } 159 }
161 160
162 void NetExportMessageHandler::OnStopNetLog(const base::ListValue* list) { 161 void NetExportMessageHandler::OnStopNetLog(const base::ListValue* list) {
163 ProcessNetLogCommand(weak_ptr_factory_.GetWeakPtr(), 162 ProcessNetLogCommand(weak_ptr_factory_.GetWeakPtr(), net_log_temp_file_,
164 net_log_temp_file_, 163 net_log::NetLogTempFile::DO_STOP);
165 NetLogTempFile::DO_STOP);
166 } 164 }
167 165
168 void NetExportMessageHandler::OnSendNetLog(const base::ListValue* list) { 166 void NetExportMessageHandler::OnSendNetLog(const base::ListValue* list) {
169 content::BrowserThread::PostTaskAndReplyWithResult( 167 content::BrowserThread::PostTaskAndReplyWithResult(
170 content::BrowserThread::FILE_USER_BLOCKING, 168 content::BrowserThread::FILE_USER_BLOCKING,
171 FROM_HERE, 169 FROM_HERE,
172 base::Bind(&NetExportMessageHandler::GetNetLogFileName, 170 base::Bind(&NetExportMessageHandler::GetNetLogFileName,
173 base::Unretained(net_log_temp_file_)), 171 base::Unretained(net_log_temp_file_)),
174 base::Bind(&NetExportMessageHandler::SendEmail)); 172 base::Bind(&NetExportMessageHandler::SendEmail));
175 } 173 }
176 174
177 // static 175 // static
178 void NetExportMessageHandler::ProcessNetLogCommand( 176 void NetExportMessageHandler::ProcessNetLogCommand(
179 base::WeakPtr<NetExportMessageHandler> net_export_message_handler, 177 base::WeakPtr<NetExportMessageHandler> net_export_message_handler,
180 NetLogTempFile* net_log_temp_file, 178 net_log::NetLogTempFile* net_log_temp_file,
181 NetLogTempFile::Command command) { 179 net_log::NetLogTempFile::Command command) {
182 if (!BrowserThread::CurrentlyOn(BrowserThread::FILE_USER_BLOCKING)) { 180 if (!BrowserThread::CurrentlyOn(BrowserThread::FILE_USER_BLOCKING)) {
183 BrowserThread::PostTask( 181 BrowserThread::PostTask(
184 BrowserThread::FILE_USER_BLOCKING, 182 BrowserThread::FILE_USER_BLOCKING,
185 FROM_HERE, 183 FROM_HERE,
186 base::Bind(&NetExportMessageHandler::ProcessNetLogCommand, 184 base::Bind(&NetExportMessageHandler::ProcessNetLogCommand,
187 net_export_message_handler, 185 net_export_message_handler,
188 net_log_temp_file, 186 net_log_temp_file,
189 command)); 187 command));
190 return; 188 return;
191 } 189 }
192 190
193 DCHECK_CURRENTLY_ON(BrowserThread::FILE_USER_BLOCKING); 191 DCHECK_CURRENTLY_ON(BrowserThread::FILE_USER_BLOCKING);
194 net_log_temp_file->ProcessCommand(command); 192 net_log_temp_file->ProcessCommand(command);
195 SendExportNetLogInfo(net_export_message_handler, net_log_temp_file); 193 SendExportNetLogInfo(net_export_message_handler, net_log_temp_file);
196 } 194 }
197 195
198 // static 196 // static
199 base::FilePath NetExportMessageHandler::GetNetLogFileName( 197 base::FilePath NetExportMessageHandler::GetNetLogFileName(
200 NetLogTempFile* net_log_temp_file) { 198 net_log::NetLogTempFile* net_log_temp_file) {
201 DCHECK_CURRENTLY_ON(BrowserThread::FILE_USER_BLOCKING); 199 DCHECK_CURRENTLY_ON(BrowserThread::FILE_USER_BLOCKING);
202 base::FilePath net_export_file_path; 200 base::FilePath net_export_file_path;
203 net_log_temp_file->GetFilePath(&net_export_file_path); 201 net_log_temp_file->GetFilePath(&net_export_file_path);
204 return net_export_file_path; 202 return net_export_file_path;
205 } 203 }
206 204
207 // static 205 // static
208 void NetExportMessageHandler::SendExportNetLogInfo( 206 void NetExportMessageHandler::SendExportNetLogInfo(
209 base::WeakPtr<NetExportMessageHandler> net_export_message_handler, 207 base::WeakPtr<NetExportMessageHandler> net_export_message_handler,
210 NetLogTempFile* net_log_temp_file) { 208 net_log::NetLogTempFile* net_log_temp_file) {
211 DCHECK_CURRENTLY_ON(BrowserThread::FILE_USER_BLOCKING); 209 DCHECK_CURRENTLY_ON(BrowserThread::FILE_USER_BLOCKING);
212 base::Value* value = net_log_temp_file->GetState(); 210 base::Value* value = net_log_temp_file->GetState();
213 if (!BrowserThread::PostTask( 211 if (!BrowserThread::PostTask(
214 BrowserThread::UI, FROM_HERE, 212 BrowserThread::UI, FROM_HERE,
215 base::Bind(&NetExportMessageHandler::OnExportNetLogInfoChanged, 213 base::Bind(&NetExportMessageHandler::OnExportNetLogInfoChanged,
216 net_export_message_handler, 214 net_export_message_handler,
217 value))) { 215 value))) {
218 // Failed posting the task, avoid leaking. 216 // Failed posting the task, avoid leaking.
219 delete value; 217 delete value;
220 } 218 }
(...skipping 28 matching lines...) Expand all
249 247
250 } // namespace 248 } // namespace
251 249
252 NetExportUI::NetExportUI(content::WebUI* web_ui) : WebUIController(web_ui) { 250 NetExportUI::NetExportUI(content::WebUI* web_ui) : WebUIController(web_ui) {
253 web_ui->AddMessageHandler(new NetExportMessageHandler()); 251 web_ui->AddMessageHandler(new NetExportMessageHandler());
254 252
255 // Set up the chrome://net-export/ source. 253 // Set up the chrome://net-export/ source.
256 Profile* profile = Profile::FromWebUI(web_ui); 254 Profile* profile = Profile::FromWebUI(web_ui);
257 content::WebUIDataSource::Add(profile, CreateNetExportHTMLSource()); 255 content::WebUIDataSource::Add(profile, CreateNetExportHTMLSource());
258 } 256 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698