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

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

Issue 2444523003: Have net-export's save dialog default to last used save directory (Closed)
Patch Set: Created 4 years, 2 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
« no previous file with comments | « no previous file | no next file » | 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) 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 <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/files/file_util.h" 11 #include "base/files/file_util.h"
12 #include "base/lazy_instance.h"
12 #include "base/macros.h" 13 #include "base/macros.h"
13 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
14 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
15 #include "base/values.h" 16 #include "base/values.h"
16 #include "chrome/browser/browser_process.h" 17 #include "chrome/browser/browser_process.h"
17 #include "chrome/browser/platform_util.h" 18 #include "chrome/browser/platform_util.h"
18 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/ui/chrome_select_file_policy.h" 20 #include "chrome/browser/ui/chrome_select_file_policy.h"
20 #include "chrome/common/features.h" 21 #include "chrome/common/features.h"
21 #include "chrome/common/url_constants.h" 22 #include "chrome/common/url_constants.h"
(...skipping 12 matching lines...) Expand all
34 #if BUILDFLAG(ANDROID_JAVA_UI) 35 #if BUILDFLAG(ANDROID_JAVA_UI)
35 #include "chrome/browser/android/intent_helper.h" 36 #include "chrome/browser/android/intent_helper.h"
36 #endif 37 #endif
37 38
38 using content::BrowserThread; 39 using content::BrowserThread;
39 using content::WebContents; 40 using content::WebContents;
40 using content::WebUIMessageHandler; 41 using content::WebUIMessageHandler;
41 42
42 namespace { 43 namespace {
43 44
45 base::LazyInstance<base::FilePath>::Leaky
46 last_save_dir = LAZY_INSTANCE_INITIALIZER;
47
44 content::WebUIDataSource* CreateNetExportHTMLSource() { 48 content::WebUIDataSource* CreateNetExportHTMLSource() {
45 content::WebUIDataSource* source = 49 content::WebUIDataSource* source =
46 content::WebUIDataSource::Create(chrome::kChromeUINetExportHost); 50 content::WebUIDataSource::Create(chrome::kChromeUINetExportHost);
47 51
48 source->SetJsonPath("strings.js"); 52 source->SetJsonPath("strings.js");
49 source->AddResourcePath(net_log::kNetExportUIJS, IDR_NET_LOG_NET_EXPORT_JS); 53 source->AddResourcePath(net_log::kNetExportUIJS, IDR_NET_LOG_NET_EXPORT_JS);
50 source->SetDefaultResource(IDR_NET_LOG_NET_EXPORT_HTML); 54 source->SetDefaultResource(IDR_NET_LOG_NET_EXPORT_HTML);
51 return source; 55 return source;
52 } 56 }
53 57
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 weak_ptr_factory_.GetWeakPtr(), net_log_file_writer_)); 191 weak_ptr_factory_.GetWeakPtr(), net_log_file_writer_));
188 } 192 }
189 193
190 void NetExportMessageHandler::OnStartNetLog(const base::ListValue* list) { 194 void NetExportMessageHandler::OnStartNetLog(const base::ListValue* list) {
191 bool result = list->GetString(0, &log_mode_); 195 bool result = list->GetString(0, &log_mode_);
192 DCHECK(result); 196 DCHECK(result);
193 197
194 if (UsingMobileUI()) { 198 if (UsingMobileUI()) {
195 StartNetLog(); 199 StartNetLog();
196 } else { 200 } else {
197 base::FilePath home_dir = base::GetHomeDir(); 201 base::FilePath initial_dir =
198 base::FilePath default_path = 202 last_save_dir.Pointer()->empty() ? base::GetHomeDir()
199 home_dir.Append(FILE_PATH_LITERAL("chrome-net-export-log.json")); 203 : *last_save_dir.Pointer();
200 ShowSelectFileDialog(default_path); 204 base::FilePath initial_path =
205 initial_dir.Append(FILE_PATH_LITERAL("chrome-net-export-log.json"));
206 ShowSelectFileDialog(initial_path);
mmenke 2016/10/24 17:04:55 This will show the home directory every time Chrom
wangyix 2016/10/24 23:35:15 I'm working on Goobuntu, and the behavior is the f
201 } 207 }
202 } 208 }
203 209
204 void NetExportMessageHandler::OnStopNetLog(const base::ListValue* list) { 210 void NetExportMessageHandler::OnStopNetLog(const base::ListValue* list) {
205 ProcessNetLogCommand(weak_ptr_factory_.GetWeakPtr(), net_log_file_writer_, 211 ProcessNetLogCommand(weak_ptr_factory_.GetWeakPtr(), net_log_file_writer_,
206 net_log::NetLogFileWriter::DO_STOP); 212 net_log::NetLogFileWriter::DO_STOP);
207 } 213 }
208 214
209 void NetExportMessageHandler::OnSendNetLog(const base::ListValue* list) { 215 void NetExportMessageHandler::OnSendNetLog(const base::ListValue* list) {
210 content::BrowserThread::PostTaskAndReplyWithResult( 216 content::BrowserThread::PostTaskAndReplyWithResult(
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 326
321 WebContents* webcontents = web_ui()->GetWebContents(); 327 WebContents* webcontents = web_ui()->GetWebContents();
322 328
323 select_file_dialog_ = ui::SelectFileDialog::Create( 329 select_file_dialog_ = ui::SelectFileDialog::Create(
324 this, new ChromeSelectFilePolicy(webcontents)); 330 this, new ChromeSelectFilePolicy(webcontents));
325 ui::SelectFileDialog::FileTypeInfo file_type_info; 331 ui::SelectFileDialog::FileTypeInfo file_type_info;
326 file_type_info.extensions = {{FILE_PATH_LITERAL("json")}}; 332 file_type_info.extensions = {{FILE_PATH_LITERAL("json")}};
327 gfx::NativeWindow owning_window = 333 gfx::NativeWindow owning_window =
328 webcontents ? webcontents->GetTopLevelNativeWindow() 334 webcontents ? webcontents->GetTopLevelNativeWindow()
329 : nullptr; 335 : nullptr;
336
330 select_file_dialog_->SelectFile( 337 select_file_dialog_->SelectFile(
331 ui::SelectFileDialog::SELECT_SAVEAS_FILE, base::string16(), default_path, 338 ui::SelectFileDialog::SELECT_SAVEAS_FILE, base::string16(), default_path,
332 &file_type_info, 0, base::FilePath::StringType(), owning_window, nullptr); 339 &file_type_info, 0, base::FilePath::StringType(), owning_window, nullptr);
333 } 340 }
334 341
335 void NetExportMessageHandler::FileSelected(const base::FilePath& path, 342 void NetExportMessageHandler::FileSelected(const base::FilePath& path,
336 int index, 343 int index,
337 void* params) { 344 void* params) {
338 select_file_dialog_ = nullptr; 345 select_file_dialog_ = nullptr;
346 *last_save_dir.Pointer() = path.DirName();
347
339 BrowserThread::PostTaskAndReply( 348 BrowserThread::PostTaskAndReply(
340 BrowserThread::FILE_USER_BLOCKING, FROM_HERE, 349 BrowserThread::FILE_USER_BLOCKING, FROM_HERE,
341 base::Bind(&net_log::NetLogFileWriter::SetUpNetExportLogPath, 350 base::Bind(&net_log::NetLogFileWriter::SetUpNetExportLogPath,
342 base::Unretained(net_log_file_writer_), path), 351 base::Unretained(net_log_file_writer_), path),
343 // NetExportMessageHandler is tied to the lifetime of the tab 352 // NetExportMessageHandler is tied to the lifetime of the tab
344 // so it cannot be assured that it will be valid when this 353 // so it cannot be assured that it will be valid when this
345 // StartNetLog is called. Instead of using base::Unretained a 354 // StartNetLog is called. Instead of using base::Unretained a
346 // weak pointer is used to adjust for this. 355 // weak pointer is used to adjust for this.
347 base::Bind(&NetExportMessageHandler::StartNetLog, 356 base::Bind(&NetExportMessageHandler::StartNetLog,
348 weak_ptr_factory_.GetWeakPtr())); 357 weak_ptr_factory_.GetWeakPtr()));
349 } 358 }
350 359
351 void NetExportMessageHandler::FileSelectionCanceled(void* params) { 360 void NetExportMessageHandler::FileSelectionCanceled(void* params) {
352 select_file_dialog_ = nullptr; 361 select_file_dialog_ = nullptr;
353 } 362 }
354 363
355 } // namespace 364 } // namespace
356 365
357 NetExportUI::NetExportUI(content::WebUI* web_ui) : WebUIController(web_ui) { 366 NetExportUI::NetExportUI(content::WebUI* web_ui) : WebUIController(web_ui) {
358 web_ui->AddMessageHandler(new NetExportMessageHandler()); 367 web_ui->AddMessageHandler(new NetExportMessageHandler());
359 368
360 // Set up the chrome://net-export/ source. 369 // Set up the chrome://net-export/ source.
361 Profile* profile = Profile::FromWebUI(web_ui); 370 Profile* profile = Profile::FromWebUI(web_ui);
362 content::WebUIDataSource::Add(profile, CreateNetExportHTMLSource()); 371 content::WebUIDataSource::Add(profile, CreateNetExportHTMLSource());
363 } 372 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698