summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/gdata/gdata_download_observer.cc
diff options
context:
space:
mode:
authorachuith@chromium.org <achuith@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-04 19:22:01 +0000
committerachuith@chromium.org <achuith@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-04 19:22:01 +0000
commit3167bd4f7389abfc5ff4010f09c4b6045b8e8311 (patch)
tree94cffc3fac9494f099b8b6078a3b6b27ed6f396a /chrome/browser/chromeos/gdata/gdata_download_observer.cc
parent2ccf3569d9ddd37172694d40643b61def982482f (diff)
downloadchromium_src-3167bd4f7389abfc5ff4010f09c4b6045b8e8311.zip
chromium_src-3167bd4f7389abfc5ff4010f09c4b6045b8e8311.tar.gz
chromium_src-3167bd4f7389abfc5ff4010f09c4b6045b8e8311.tar.bz2
Refactor gdata download path substitution logic.
* Add method SubstituteGDataDownloadPath for the gdata->temporary path substitution logic. Call this from DownloadFilePickerChromeos and SavePackageFilePickerChromeOS. * Replace SetGDataPath with SetDownloadParams to set up a gdata download. BUG=127159 TEST=manual Review URL: https://chromiumcodereview.appspot.com/10492007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@140345 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/chromeos/gdata/gdata_download_observer.cc')
-rw-r--r--chrome/browser/chromeos/gdata/gdata_download_observer.cc46
1 files changed, 41 insertions, 5 deletions
diff --git a/chrome/browser/chromeos/gdata/gdata_download_observer.cc b/chrome/browser/chromeos/gdata/gdata_download_observer.cc
index 2497b4f..f304735 100644
--- a/chrome/browser/chromeos/gdata/gdata_download_observer.cc
+++ b/chrome/browser/chromeos/gdata/gdata_download_observer.cc
@@ -5,10 +5,12 @@
#include "chrome/browser/chromeos/gdata/gdata_download_observer.h"
#include "base/file_util.h"
+#include "chrome/browser/chromeos/gdata/gdata_system_service.h"
#include "chrome/browser/chromeos/gdata/gdata_upload_file_info.h"
#include "chrome/browser/chromeos/gdata/gdata_uploader.h"
#include "chrome/browser/chromeos/gdata/gdata_util.h"
#include "chrome/browser/download/download_completion_blocker.h"
+#include "chrome/browser/profiles/profile_manager.h"
#include "net/base/net_util.h"
using content::BrowserThread;
@@ -100,11 +102,45 @@ void GDataDownloadObserver::Initialize(
}
// static
-void GDataDownloadObserver::SetGDataPath(DownloadItem* download,
- const FilePath& path) {
- if (download)
- download->SetExternalData(&kGDataPathKey,
- new GDataExternalData(path));
+void GDataDownloadObserver::SubstituteGDataDownloadPath(Profile* profile,
+ const FilePath& gdata_path, content::DownloadItem* download,
+ const SubstituteGDataDownloadPathCallback& callback) {
+ gdata::GDataSystemService* system_service =
+ gdata::GDataSystemServiceFactory::GetForProfile(
+ profile ? profile : ProfileManager::GetDefaultProfile());
+
+ if (system_service && gdata::util::IsUnderGDataMountPoint(gdata_path)) {
+ // If we're trying to download a file into gdata, save path in external
+ // data.
+ SetDownloadParams(gdata_path, download);
+
+ const FilePath gdata_tmp_download_dir =
+ system_service->file_system()->GetCacheDirectoryPath(
+ gdata::GDataCache::CACHE_TYPE_TMP_DOWNLOADS);
+
+ // Swap the gdata path with a local path. Local path must be created
+ // on the FILE thread.
+ FilePath* gdata_tmp_download_path(new FilePath());
+ BrowserThread::GetBlockingPool()->PostTaskAndReply(FROM_HERE,
+ base::Bind(&gdata::GDataDownloadObserver::GetGDataTempDownloadPath,
+ gdata_tmp_download_dir,
+ gdata_tmp_download_path),
+ base::Bind(callback, base::Owned(gdata_tmp_download_path)));
+ } else {
+ callback.Run(&gdata_path);
+ }
+}
+
+// static
+void GDataDownloadObserver::SetDownloadParams(const FilePath& gdata_path,
+ DownloadItem* download) {
+ if (!download)
+ return;
+
+ download->SetExternalData(&kGDataPathKey,
+ new GDataExternalData(gdata_path));
+ download->SetDisplayName(gdata_path.BaseName());
+ download->SetIsTemporary(true);
}
// static