summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos
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
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')
-rw-r--r--chrome/browser/chromeos/gdata/gdata_download_observer.cc46
-rw-r--r--chrome/browser/chromeos/gdata/gdata_download_observer.h15
2 files changed, 53 insertions, 8 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
diff --git a/chrome/browser/chromeos/gdata/gdata_download_observer.h b/chrome/browser/chromeos/gdata/gdata_download_observer.h
index 5b8342df..0293549 100644
--- a/chrome/browser/chromeos/gdata/gdata_download_observer.h
+++ b/chrome/browser/chromeos/gdata/gdata_download_observer.h
@@ -14,6 +14,8 @@
#include "content/public/browser/download_item.h"
#include "content/public/browser/download_manager.h"
+class Profile;
+
namespace gdata {
class DocumentEntry;
@@ -33,10 +35,17 @@ class GDataDownloadObserver : public content::DownloadManager::Observer,
content::DownloadManager* download_manager,
const FilePath& gdata_tmp_download_path);
+ typedef base::Callback<void(const FilePath*)>
+ SubstituteGDataDownloadPathCallback;
+ static void SubstituteGDataDownloadPath(Profile* profile,
+ const FilePath& gdata_path, content::DownloadItem* download,
+ const SubstituteGDataDownloadPathCallback& callback);
+
// Sets gdata path, for example, '/special/drive/MyFolder/MyFile',
- // to external data in |download|.
- static void SetGDataPath(content::DownloadItem* download,
- const FilePath& gdata_path);
+ // to external data in |download|. Also sets display name and
+ // makes |download| a temporary.
+ static void SetDownloadParams(const FilePath& gdata_path,
+ content::DownloadItem* download);
// Checks if there is a GData upload associated with |download|
static bool IsGDataDownload(content::DownloadItem* download);