diff options
author | achuith@chromium.org <achuith@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-20 01:30:02 +0000 |
---|---|---|
committer | achuith@chromium.org <achuith@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-20 01:30:02 +0000 |
commit | 07a9cf58aabc1e1f5eefe0fb546ec187eaef44a3 (patch) | |
tree | 271b33231daca94214e7da26fa73fc9e62132cc3 /chrome/browser | |
parent | dc31f646fee5f9a5039fb6118b14fd66ba1464d4 (diff) | |
download | chromium_src-07a9cf58aabc1e1f5eefe0fb546ec187eaef44a3.zip chromium_src-07a9cf58aabc1e1f5eefe0fb546ec187eaef44a3.tar.gz chromium_src-07a9cf58aabc1e1f5eefe0fb546ec187eaef44a3.tar.bz2 |
Fix for downloading to default destination drive in incognito mode.
* Rename DownloadPrefs::download_path() to DownloadPrefs::DownloadPath(). Most of the changes are due to this.
* Store Profile* instead of PrefService* in DownloadPrefs.
* Determine if GDataSystemService* is available in DownloadPath() on ChromeOS. If not, use the default download directory.
BUG=137706
TEST=set default download destination to drive on cros. Open an incognito window, click on a link that would cause an automatic download. This should work.
TBR=sky@chromium.org
Review URL: https://chromiumcodereview.appspot.com/10805026
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@147592 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/automation/testing_automation_provider.cc | 2 | ||||
-rw-r--r-- | chrome/browser/debugger/devtools_file_helper.cc | 11 | ||||
-rw-r--r-- | chrome/browser/download/chrome_download_manager_delegate.cc | 8 | ||||
-rw-r--r-- | chrome/browser/download/download_browsertest.cc | 2 | ||||
-rw-r--r-- | chrome/browser/download/download_prefs.cc | 19 | ||||
-rw-r--r-- | chrome/browser/download/download_prefs.h | 10 | ||||
-rw-r--r-- | chrome/browser/download/save_page_browsertest.cc | 4 | ||||
-rw-r--r-- | chrome/browser/extensions/webstore_installer.cc | 2 | ||||
-rw-r--r-- | chrome/browser/ui/ash/screenshot_taker.cc | 2 | ||||
-rw-r--r-- | chrome/browser/ui/webui/downloads_dom_handler.cc | 2 | ||||
-rw-r--r-- | chrome/browser/ui/webui/feedback_ui.cc | 2 | ||||
-rw-r--r-- | chrome/browser/ui/webui/screenshot_source.cc | 2 |
12 files changed, 44 insertions, 22 deletions
diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc index 2dcee1a..deb355f 100644 --- a/chrome/browser/automation/testing_automation_provider.cc +++ b/chrome/browser/automation/testing_automation_provider.cc @@ -1152,7 +1152,7 @@ void TestingAutomationProvider::GetDownloadDirectory( DownloadManager* dlm = BrowserContext::GetDownloadManager(tab->GetBrowserContext()); *download_directory = - DownloadPrefs::FromDownloadManager(dlm)->download_path(); + DownloadPrefs::FromDownloadManager(dlm)->DownloadPath(); } } diff --git a/chrome/browser/debugger/devtools_file_helper.cc b/chrome/browser/debugger/devtools_file_helper.cc index b3ea82e..188c8c8 100644 --- a/chrome/browser/debugger/devtools_file_helper.cc +++ b/chrome/browser/debugger/devtools_file_helper.cc @@ -4,6 +4,8 @@ #include "chrome/browser/debugger/devtools_file_helper.h" +#include <vector> + #include "base/bind.h" #include "base/callback.h" #include "base/file_util.h" @@ -18,8 +20,12 @@ #include "chrome/browser/ui/chrome_select_file_policy.h" #include "chrome/browser/ui/select_file_dialog.h" #include "chrome/common/pref_names.h" +#include "content/public/browser/browser_context.h" +#include "content/public/browser/download_manager.h" +using content::BrowserContext; using content::BrowserThread; +using content::DownloadManager; namespace { @@ -147,8 +153,9 @@ void DevToolsFileHelper::Save(const std::string& url, initial_path = g_last_save_path.Pointer()->DirName().AppendASCII( suggested_file_name); } else { - DownloadPrefs prefs(profile_->GetPrefs()); - initial_path = prefs.download_path().AppendASCII(suggested_file_name); + FilePath download_path = DownloadPrefs::FromDownloadManager( + BrowserContext::GetDownloadManager(profile_))->DownloadPath(); + initial_path = download_path.AppendASCII(suggested_file_name); } } diff --git a/chrome/browser/download/chrome_download_manager_delegate.cc b/chrome/browser/download/chrome_download_manager_delegate.cc index 87d4aa8..cffda03 100644 --- a/chrome/browser/download/chrome_download_manager_delegate.cc +++ b/chrome/browser/download/chrome_download_manager_delegate.cc @@ -106,7 +106,7 @@ SafeBrowsingState::~SafeBrowsingState() {} ChromeDownloadManagerDelegate::ChromeDownloadManagerDelegate(Profile* profile) : profile_(profile), next_download_id_(0), - download_prefs_(new DownloadPrefs(profile->GetPrefs())) { + download_prefs_(new DownloadPrefs(profile)) { } ChromeDownloadManagerDelegate::~ChromeDownloadManagerDelegate() { @@ -660,7 +660,7 @@ void ChromeDownloadManagerDelegate::CheckVisitedReferrerBeforeDone( if (should_prompt && !download_manager_->LastDownloadPath().empty()) target_directory = download_manager_->LastDownloadPath(); else - target_directory = download_prefs_->download_path(); + target_directory = download_prefs_->DownloadPath(); suggested_path = target_directory.Append(generated_name); } else { DCHECK(!should_prompt); @@ -704,7 +704,7 @@ void ChromeDownloadManagerDelegate::CheckVisitedReferrerBeforeDone( this, download->GetId(), should_prompt, is_forced_path, danger_type)); #else GetReservedPath( - *download, suggested_path, download_prefs_->download_path(), + *download, suggested_path, download_prefs_->DownloadPath(), !is_forced_path, base::Bind(&ChromeDownloadManagerDelegate::OnPathReservationAvailable, this, download->GetId(), should_prompt, danger_type)); @@ -725,7 +725,7 @@ void ChromeDownloadManagerDelegate::SubstituteGDataDownloadPathCallback( return; GetReservedPath( - *download, suggested_path, download_prefs_->download_path(), + *download, suggested_path, download_prefs_->DownloadPath(), !is_forced_path, base::Bind(&ChromeDownloadManagerDelegate::OnPathReservationAvailable, this, download->GetId(), should_prompt, danger_type)); diff --git a/chrome/browser/download/download_browsertest.cc b/chrome/browser/download/download_browsertest.cc index 4585d77..4b21c37 100644 --- a/chrome/browser/download/download_browsertest.cc +++ b/chrome/browser/download/download_browsertest.cc @@ -353,7 +353,7 @@ class DownloadTest : public InProcessBrowserTest { } FilePath GetDownloadDirectory(Browser* browser) { - return GetDownloadPrefs(browser)->download_path(); + return GetDownloadPrefs(browser)->DownloadPath(); } // Create a DownloadTestObserverTerminal that will wait for the diff --git a/chrome/browser/download/download_prefs.cc b/chrome/browser/download/download_prefs.cc index bc8a396..e5590b6 100644 --- a/chrome/browser/download/download_prefs.cc +++ b/chrome/browser/download/download_prefs.cc @@ -22,12 +22,14 @@ #include "chrome/browser/download/download_util.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/profiles/profile_manager.h" #include "chrome/common/pref_names.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/download_manager.h" #include "content/public/browser/save_page_type.h" #if defined(OS_CHROMEOS) +#include "chrome/browser/chromeos/gdata/gdata_system_service.h" #include "chrome/browser/chromeos/gdata/gdata_util.h" #endif @@ -35,7 +37,8 @@ using content::BrowserContext; using content::BrowserThread; using content::DownloadManager; -DownloadPrefs::DownloadPrefs(PrefService* prefs) : prefs_(prefs) { +DownloadPrefs::DownloadPrefs(Profile* profile) : profile_(profile) { + PrefService* prefs = profile->GetPrefs(); prompt_for_download_.Init(prefs::kPromptForDownload, prefs, NULL); download_path_.Init(prefs::kDownloadDefaultDirectory, prefs, NULL); save_file_type_.Init(prefs::kSaveFileType, prefs, NULL); @@ -122,6 +125,18 @@ DownloadPrefs* DownloadPrefs::FromBrowserContext( return FromDownloadManager(BrowserContext::GetDownloadManager(context)); } +FilePath DownloadPrefs::DownloadPath() const { +#if defined(OS_CHROMEOS) + // If the download path is under /drive, and GDataSystemService isn't + // available (which it isn't for incognito mode, for instance), use the + // default download directory (/Downloads). + if (gdata::util::IsUnderGDataMountPoint(*download_path_) && + !gdata::GDataSystemServiceFactory::GetForProfile(profile_)) + return download_util::GetDefaultDownloadDirectory(); +#endif + return *download_path_; +} + bool DownloadPrefs::PromptForDownload() const { // If the DownloadDirectory policy is set, then |prompt_for_download_| should // always be false. @@ -184,7 +199,7 @@ void DownloadPrefs::SaveAutoOpenState() { if (!extensions.empty()) extensions.erase(extensions.size() - 1); - prefs_->SetString(prefs::kDownloadExtensionsToOpen, extensions); + profile_->GetPrefs()->SetString(prefs::kDownloadExtensionsToOpen, extensions); } bool DownloadPrefs::AutoOpenCompareFunctor::operator()( diff --git a/chrome/browser/download/download_prefs.h b/chrome/browser/download/download_prefs.h index ab95eaf..86fd106 100644 --- a/chrome/browser/download/download_prefs.h +++ b/chrome/browser/download/download_prefs.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -10,7 +10,7 @@ #include "base/file_path.h" #include "chrome/browser/prefs/pref_member.h" -class PrefService; +class Profile; namespace content { class BrowserContext; @@ -20,7 +20,7 @@ class DownloadManager; // Stores all download-related preferences. class DownloadPrefs { public: - explicit DownloadPrefs(PrefService* prefs); + explicit DownloadPrefs(Profile* profile); ~DownloadPrefs(); static void RegisterUserPrefs(PrefService* prefs); @@ -32,7 +32,7 @@ class DownloadPrefs { static DownloadPrefs* FromBrowserContext( content::BrowserContext* browser_context); - FilePath download_path() const { return *download_path_; } + FilePath DownloadPath() const; int save_file_type() const { return *save_file_type_; } // Returns true if the prompt_for_download preference has been set and the @@ -62,7 +62,7 @@ class DownloadPrefs { private: void SaveAutoOpenState(); - PrefService* prefs_; + Profile* profile_; BooleanPrefMember prompt_for_download_; FilePathPrefMember download_path_; diff --git a/chrome/browser/download/save_page_browsertest.cc b/chrome/browser/download/save_page_browsertest.cc index 66e2843..0d4a106 100644 --- a/chrome/browser/download/save_page_browsertest.cc +++ b/chrome/browser/download/save_page_browsertest.cc @@ -352,7 +352,7 @@ IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, CleanFilenameFromPageTitle) { const FilePath file_name(FILE_PATH_LITERAL("c.htm")); FilePath download_dir = DownloadPrefs::FromDownloadManager(GetDownloadManager())-> - download_path(); + DownloadPath(); FilePath full_file_name = download_dir.AppendASCII(std::string("test.exe") + kAppendedExtension); FilePath dir = download_dir.AppendASCII("test.exe_files"); @@ -395,7 +395,7 @@ IN_PROC_BROWSER_TEST_F(SavePageAsMHTMLBrowserTest, SavePageAsMHTML) { static const int64 kFileSizeMin = 2758; GURL url = NavigateToMockURL("b"); FilePath download_dir = DownloadPrefs::FromDownloadManager( - GetDownloadManager())->download_path(); + GetDownloadManager())->DownloadPath(); FilePath full_file_name = download_dir.AppendASCII(std::string( "Test page for saving page feature.mhtml")); #if defined(OS_CHROMEOS) diff --git a/chrome/browser/extensions/webstore_installer.cc b/chrome/browser/extensions/webstore_installer.cc index faf29c9..4bf576a 100644 --- a/chrome/browser/extensions/webstore_installer.cc +++ b/chrome/browser/extensions/webstore_installer.cc @@ -206,7 +206,7 @@ void WebstoreInstaller::Start() { } FilePath download_path = DownloadPrefs::FromDownloadManager( - BrowserContext::GetDownloadManager(profile_))->download_path(); + BrowserContext::GetDownloadManager(profile_))->DownloadPath(); BrowserThread::PostTask( BrowserThread::FILE, FROM_HERE, base::Bind(&GetDownloadFilePath, download_path, id_, diff --git a/chrome/browser/ui/ash/screenshot_taker.cc b/chrome/browser/ui/ash/screenshot_taker.cc index 12e6bd2..3e9d655 100644 --- a/chrome/browser/ui/ash/screenshot_taker.cc +++ b/chrome/browser/ui/ash/screenshot_taker.cc @@ -153,7 +153,7 @@ void ScreenshotTaker::HandleTakePartialScreenshot( if (is_logged_in) { DownloadPrefs* download_prefs = DownloadPrefs::FromBrowserContext( ash::Shell::GetInstance()->delegate()->GetCurrentBrowserContext()); - screenshot_directory = download_prefs->download_path(); + screenshot_directory = download_prefs->DownloadPath(); } else { if (!file_util::GetTempDir(&screenshot_directory)) { LOG(ERROR) << "Failed to find temporary directory."; diff --git a/chrome/browser/ui/webui/downloads_dom_handler.cc b/chrome/browser/ui/webui/downloads_dom_handler.cc index d10d8e6..514ae7a 100644 --- a/chrome/browser/ui/webui/downloads_dom_handler.cc +++ b/chrome/browser/ui/webui/downloads_dom_handler.cc @@ -341,7 +341,7 @@ void DownloadsDOMHandler::HandleClearAll(const ListValue* args) { void DownloadsDOMHandler::HandleOpenDownloadsFolder(const ListValue* args) { CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_OPEN_FOLDER); platform_util::OpenItem( - DownloadPrefs::FromDownloadManager(download_manager_)->download_path()); + DownloadPrefs::FromDownloadManager(download_manager_)->DownloadPath()); } // DownloadsDOMHandler, private: ---------------------------------------------- diff --git a/chrome/browser/ui/webui/feedback_ui.cc b/chrome/browser/ui/webui/feedback_ui.cc index 96ea099..83bbe87 100644 --- a/chrome/browser/ui/webui/feedback_ui.cc +++ b/chrome/browser/ui/webui/feedback_ui.cc @@ -98,7 +98,7 @@ void GetSavedScreenshots(std::vector<std::string>* saved_screenshots) { DownloadPrefs* download_prefs = DownloadPrefs::FromBrowserContext( ash::Shell::GetInstance()->delegate()->GetCurrentBrowserContext()); FeedbackUI::GetMostRecentScreenshots( - download_prefs->download_path(), + download_prefs->DownloadPath(), saved_screenshots, kMaxSavedScreenshots); } diff --git a/chrome/browser/ui/webui/screenshot_source.cc b/chrome/browser/ui/webui/screenshot_source.cc index 9a7798f..15d0d57 100644 --- a/chrome/browser/ui/webui/screenshot_source.cc +++ b/chrome/browser/ui/webui/screenshot_source.cc @@ -104,7 +104,7 @@ void ScreenshotSource::SendSavedScreenshot(const std::string& screenshot_path, int64 file_size = 0; DownloadPrefs* download_prefs = DownloadPrefs::FromBrowserContext( ash::Shell::GetInstance()->delegate()->GetCurrentBrowserContext()); - FilePath file = download_prefs->download_path().Append(decoded_filename); + FilePath file = download_prefs->DownloadPath().Append(decoded_filename); if (!file_util::GetFileSize(file, &file_size)) { CacheAndSendScreenshot(screenshot_path, request_id, read_bytes); return; |