Don't save last used locations in open and save dialogs when in incognito mode.

For "Save page as..." we simply don't store the save location in incognito mode.

For "Open File"... and file upload controls, it's a bit more complicated: because NSOpenPanel and NSSavePanel default to using the last chosen directory from NavigationServices (which we can't influence),
we provide a preference value prefs::kLastChosenDirectory as fallback there, which is not persisted in incognito mode.

BUG=45064
TEST=See bug for manual test.

Review URL: http://codereview.chromium.org/2450004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@49237 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc
index 0dc47d206..0c3d035 100644
--- a/chrome/browser/browser.cc
+++ b/chrome/browser/browser.cc
@@ -1583,10 +1583,12 @@
   if (!select_file_dialog_.get())
     select_file_dialog_ = SelectFileDialog::Create(this);
 
+  const FilePath directory = profile_->last_selected_directory();
+
   // TODO(beng): figure out how to juggle this.
   gfx::NativeWindow parent_window = window_->GetNativeHandle();
   select_file_dialog_->SelectFile(SelectFileDialog::SELECT_OPEN_FILE,
-                                  string16(), FilePath(),
+                                  string16(), directory,
                                   NULL, 0, FILE_PATH_LITERAL(""),
                                   parent_window, NULL);
 #endif
@@ -2855,6 +2857,7 @@
 // Browser, SelectFileDialog::Listener implementation:
 
 void Browser::FileSelected(const FilePath& path, int index, void* params) {
+  profile_->set_last_selected_directory(path.DirName());
   GURL file_url = net::FilePathToFileURL(path);
   if (!file_url.is_empty())
     OpenURL(file_url, GURL(), CURRENT_TAB, PageTransition::TYPED);