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

Unified 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: Added DCHECK_CURRENTLY_ON for functions that access last_save_dir Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/webui/net_export_ui.cc
diff --git a/chrome/browser/ui/webui/net_export_ui.cc b/chrome/browser/ui/webui/net_export_ui.cc
index 313d5ee53e953b57bcb3dd52e8718a26dc8e5ef5..d95a6e0fab7e8df294fe3e3db4a861ac079b7310 100644
--- a/chrome/browser/ui/webui/net_export_ui.cc
+++ b/chrome/browser/ui/webui/net_export_ui.cc
@@ -9,11 +9,13 @@
#include "base/bind.h"
#include "base/files/file_util.h"
+#include "base/lazy_instance.h"
#include "base/macros.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "chrome/browser/browser_process.h"
+#include "chrome/browser/download/download_prefs.h"
#include "chrome/browser/platform_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/chrome_select_file_policy.h"
@@ -41,6 +43,10 @@ using content::WebUIMessageHandler;
namespace {
+// May only be accessed on the UI thread
+base::LazyInstance<base::FilePath>::Leaky
+ last_save_dir = LAZY_INSTANCE_INITIALIZER;
+
content::WebUIDataSource* CreateNetExportHTMLSource() {
content::WebUIDataSource* source =
content::WebUIDataSource::Create(chrome::kChromeUINetExportHost);
@@ -188,16 +194,20 @@ void NetExportMessageHandler::OnGetExportNetLogInfo(
}
void NetExportMessageHandler::OnStartNetLog(const base::ListValue* list) {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
bool result = list->GetString(0, &log_mode_);
DCHECK(result);
if (UsingMobileUI()) {
StartNetLog();
} else {
- base::FilePath home_dir = base::GetHomeDir();
- base::FilePath default_path =
- home_dir.Append(FILE_PATH_LITERAL("chrome-net-export-log.json"));
- ShowSelectFileDialog(default_path);
+ base::FilePath initial_dir = last_save_dir.Pointer()->empty() ?
+ DownloadPrefs::FromBrowserContext(
+ web_ui()->GetWebContents()->GetBrowserContext())->DownloadPath() :
+ *last_save_dir.Pointer();
+ base::FilePath initial_path =
+ initial_dir.Append(FILE_PATH_LITERAL("chrome-net-export-log.json"));
+ ShowSelectFileDialog(initial_path);
}
}
@@ -332,9 +342,11 @@ void NetExportMessageHandler::ShowSelectFileDialog(
void NetExportMessageHandler::FileSelected(const base::FilePath& path,
int index,
void* params) {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
DCHECK(select_file_dialog_);
select_file_dialog_ = nullptr;
+ *last_save_dir.Pointer() = path.DirName();
BrowserThread::PostTaskAndReply(
BrowserThread::FILE_USER_BLOCKING, FROM_HERE,
base::Bind(&net_log::NetLogFileWriter::SetUpNetExportLogPath,
« 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