| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/download/download_file_picker_chromeos.h" | 5 #include "chrome/browser/download/download_file_picker_chromeos.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/threading/sequenced_worker_pool.h" | 10 #include "base/threading/sequenced_worker_pool.h" |
| 11 #include "content/public/browser/browser_thread.h" | |
| 12 #include "content/public/browser/download_item.h" | |
| 13 #include "content/public/browser/download_manager.h" | |
| 14 #include "chrome/browser/chromeos/gdata/gdata_download_observer.h" | 11 #include "chrome/browser/chromeos/gdata/gdata_download_observer.h" |
| 15 #include "chrome/browser/chromeos/gdata/gdata_file_system.h" | 12 #include "chrome/browser/chromeos/gdata/gdata_file_system.h" |
| 16 #include "chrome/browser/chromeos/gdata/gdata_system_service.h" | 13 #include "chrome/browser/chromeos/gdata/gdata_system_service.h" |
| 17 #include "chrome/browser/chromeos/gdata/gdata_util.h" | 14 #include "chrome/browser/chromeos/gdata/gdata_util.h" |
| 18 #include "chrome/browser/profiles/profile_manager.h" | 15 #include "chrome/browser/profiles/profile_manager.h" |
| 16 #include "content/public/browser/browser_thread.h" |
| 17 #include "content/public/browser/download_item.h" |
| 18 #include "content/public/browser/download_manager.h" |
| 19 | 19 |
| 20 using content::BrowserThread; | 20 using content::BrowserThread; |
| 21 using content::DownloadManager; | 21 using content::DownloadManager; |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 // Callbacks for PostTaskAndReply. | |
| 26 | |
| 27 // |temp_path| is set to a temporary local download path in | |
| 28 // ~/GCache/v1/tmp/downloads/ | |
| 29 // Must be called on the FILE thread. | |
| 30 void GetGDataTempDownloadPath(const FilePath& download_cache_path, | |
| 31 FilePath* temp_path) { | |
| 32 if (!file_util::CreateDirectory(download_cache_path)) { | |
| 33 NOTREACHED(); | |
| 34 LOG(ERROR) << "Can not create temp download directory at " | |
| 35 << download_cache_path.value(); | |
| 36 } | |
| 37 bool created = file_util::CreateTemporaryFileInDir(download_cache_path, | |
| 38 temp_path); | |
| 39 // TODO(achuith): Handle failure in CreateTemporaryFileInDir. | |
| 40 DCHECK(created); | |
| 41 } | |
| 42 | |
| 43 // Call FileSelected on |download_manager|. | 25 // Call FileSelected on |download_manager|. |
| 44 void GDataTempFileSelected(DownloadManager* download_manager, | 26 void GDataTempFileSelected(DownloadManager* download_manager, |
| 45 FilePath* file_path, | 27 FilePath* file_path, |
| 46 int32 download_id) { | 28 int32 download_id) { |
| 47 download_manager->FileSelected(*file_path, download_id); | 29 download_manager->FileSelected(*file_path, download_id); |
| 48 } | 30 } |
| 49 | 31 |
| 50 } // namespace | 32 } // namespace |
| 51 | 33 |
| 52 DownloadFilePickerChromeOS::DownloadFilePickerChromeOS( | 34 DownloadFilePickerChromeOS::DownloadFilePickerChromeOS( |
| (...skipping 22 matching lines...) Expand all Loading... |
| 75 if (system_service && gdata::util::IsUnderGDataMountPoint(path)) { | 57 if (system_service && gdata::util::IsUnderGDataMountPoint(path)) { |
| 76 // If we're trying to download a file into gdata, save path in external | 58 // If we're trying to download a file into gdata, save path in external |
| 77 // data. | 59 // data. |
| 78 content::DownloadItem* download = | 60 content::DownloadItem* download = |
| 79 download_manager_->GetActiveDownloadItem(download_id_); | 61 download_manager_->GetActiveDownloadItem(download_id_); |
| 80 if (download) { | 62 if (download) { |
| 81 gdata::GDataDownloadObserver::SetGDataPath(download, path); | 63 gdata::GDataDownloadObserver::SetGDataPath(download, path); |
| 82 download->SetDisplayName(path.BaseName()); | 64 download->SetDisplayName(path.BaseName()); |
| 83 download->SetIsTemporary(true); | 65 download->SetIsTemporary(true); |
| 84 | 66 |
| 85 const FilePath download_cache_path = | 67 const FilePath gdata_tmp_download_dir = |
| 86 system_service->file_system()->GetGDataTempDownloadFolderPath(); | 68 system_service->file_system()->GetGDataTempDownloadFolderPath(); |
| 87 | 69 |
| 88 // Swap the gdata path with a local path. Local path must be created | 70 // Swap the gdata path with a local path. Local path must be created |
| 89 // on the IO thread pool. | 71 // on the IO thread pool. |
| 90 FilePath* download_path(new FilePath()); | 72 FilePath* gdata_tmp_download_path(new FilePath()); |
| 91 BrowserThread::GetBlockingPool()->PostTaskAndReply(FROM_HERE, | 73 BrowserThread::GetBlockingPool()->PostTaskAndReply(FROM_HERE, |
| 92 base::Bind(&GetGDataTempDownloadPath, | 74 base::Bind(&gdata::GDataDownloadObserver::GetGDataTempDownloadPath, |
| 93 download_cache_path, | 75 gdata_tmp_download_dir, |
| 94 download_path), | 76 gdata_tmp_download_path), |
| 95 base::Bind(&GDataTempFileSelected, | 77 base::Bind(&GDataTempFileSelected, |
| 96 download_manager_, | 78 download_manager_, |
| 97 base::Owned(download_path), | 79 base::Owned(gdata_tmp_download_path), |
| 98 download_id_)); | 80 download_id_)); |
| 99 } | 81 } |
| 100 } else { | 82 } else { |
| 101 download_manager_->FileSelected(path, download_id_); | 83 download_manager_->FileSelected(path, download_id_); |
| 102 } | 84 } |
| 103 } | 85 } |
| 104 delete this; | 86 delete this; |
| 105 } | 87 } |
| OLD | NEW |