Commit eba1403a authored by thestig@chromium.org's avatar thestig@chromium.org

Media Galleries: Use the same last directory entry as file_system_api.

Review URL: https://codereview.chromium.org/46973005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@232958 0039d316-1c4b-4281-b951-d872f2087c98
parent 38bea829
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
#include "base/stl_util.h" #include "base/stl_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/api/file_system/file_system_api.h"
#include "chrome/browser/extensions/extension_prefs.h"
#include "chrome/browser/media_galleries/media_file_system_registry.h" #include "chrome/browser/media_galleries/media_file_system_registry.h"
#include "chrome/browser/media_galleries/media_galleries_histograms.h" #include "chrome/browser/media_galleries/media_galleries_histograms.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
...@@ -88,7 +90,7 @@ MediaGalleriesDialogController::MediaGalleriesDialogController( ...@@ -88,7 +90,7 @@ MediaGalleriesDialogController::MediaGalleriesDialogController(
on_finish_(on_finish) { on_finish_(on_finish) {
preferences_ = preferences_ =
g_browser_process->media_file_system_registry()->GetPreferences( g_browser_process->media_file_system_registry()->GetPreferences(
Profile::FromBrowserContext(web_contents_->GetBrowserContext())); GetProfile());
// Passing unretained pointer is safe, since the dialog controller // Passing unretained pointer is safe, since the dialog controller
// is self-deleting, and so won't be deleted until it can be shown // is self-deleting, and so won't be deleted until it can be shown
// and then closed. // and then closed.
...@@ -209,14 +211,17 @@ MediaGalleriesDialogController::UnattachedPermissions() const { ...@@ -209,14 +211,17 @@ MediaGalleriesDialogController::UnattachedPermissions() const {
} }
void MediaGalleriesDialogController::OnAddFolderClicked() { void MediaGalleriesDialogController::OnAddFolderClicked() {
base::FilePath desktop; base::FilePath default_path =
PathService::Get(base::DIR_USER_DESKTOP, &desktop); extensions::file_system_api::GetLastChooseEntryDirectory(
extensions::ExtensionPrefs::Get(GetProfile()), extension_->id());
if (default_path.empty())
PathService::Get(base::DIR_USER_DESKTOP, &default_path);
select_folder_dialog_ = select_folder_dialog_ =
ui::SelectFileDialog::Create(this, new ChromeSelectFilePolicy(NULL)); ui::SelectFileDialog::Create(this, new ChromeSelectFilePolicy(NULL));
select_folder_dialog_->SelectFile( select_folder_dialog_->SelectFile(
ui::SelectFileDialog::SELECT_FOLDER, ui::SelectFileDialog::SELECT_FOLDER,
l10n_util::GetStringUTF16(IDS_MEDIA_GALLERIES_DIALOG_ADD_GALLERY_TITLE), l10n_util::GetStringUTF16(IDS_MEDIA_GALLERIES_DIALOG_ADD_GALLERY_TITLE),
desktop, default_path,
NULL, NULL,
0, 0,
base::FilePath::StringType(), base::FilePath::StringType(),
...@@ -287,6 +292,11 @@ content::WebContents* MediaGalleriesDialogController::web_contents() { ...@@ -287,6 +292,11 @@ content::WebContents* MediaGalleriesDialogController::web_contents() {
void MediaGalleriesDialogController::FileSelected(const base::FilePath& path, void MediaGalleriesDialogController::FileSelected(const base::FilePath& path,
int /*index*/, int /*index*/,
void* /*params*/) { void* /*params*/) {
extensions::file_system_api::SetLastChooseEntryDirectory(
extensions::ExtensionPrefs::Get(GetProfile()),
extension_->id(),
path);
// Try to find it in the prefs. // Try to find it in the prefs.
MediaGalleryPrefInfo gallery; MediaGalleryPrefInfo gallery;
bool gallery_exists = preferences_->LookUpGalleryByPath(path, &gallery); bool gallery_exists = preferences_->LookUpGalleryByPath(path, &gallery);
...@@ -466,6 +476,10 @@ ui::MenuModel* MediaGalleriesDialogController::GetContextMenuModel( ...@@ -466,6 +476,10 @@ ui::MenuModel* MediaGalleriesDialogController::GetContextMenuModel(
return context_menu_model_.get(); return context_menu_model_.get();
} }
Profile* MediaGalleriesDialogController::GetProfile() {
return Profile::FromBrowserContext(web_contents_->GetBrowserContext());
}
// MediaGalleries dialog ------------------------------------------------------- // MediaGalleries dialog -------------------------------------------------------
MediaGalleriesDialog::~MediaGalleriesDialog() {} MediaGalleriesDialog::~MediaGalleriesDialog() {}
...@@ -30,6 +30,7 @@ class MenuModel; ...@@ -30,6 +30,7 @@ class MenuModel;
class GalleryContextMenuModel; class GalleryContextMenuModel;
class MediaGalleriesDialogController; class MediaGalleriesDialogController;
class Profile;
// The view. // The view.
class MediaGalleriesDialog { class MediaGalleriesDialog {
...@@ -167,6 +168,8 @@ class MediaGalleriesDialogController ...@@ -167,6 +168,8 @@ class MediaGalleriesDialogController
void FillPermissions(bool attached, void FillPermissions(bool attached,
GalleryPermissionsVector* permissions) const; GalleryPermissionsVector* permissions) const;
Profile* GetProfile();
// The web contents from which the request originated. // The web contents from which the request originated.
content::WebContents* web_contents_; content::WebContents* web_contents_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment