| 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 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_DOWNLOAD_OBSERVER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_DOWNLOAD_OBSERVER_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_DOWNLOAD_OBSERVER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_DOWNLOAD_OBSERVER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
| 11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 12 #include "chrome/browser/chromeos/drive/drive_uploader.h" | 12 #include "chrome/browser/chromeos/drive/drive_uploader.h" |
| 13 #include "chrome/browser/google_apis/gdata_errorcode.h" | 13 #include "chrome/browser/google_apis/gdata_errorcode.h" |
| 14 #include "content/public/browser/download_item.h" | 14 #include "content/public/browser/download_item.h" |
| 15 #include "content/public/browser/download_manager.h" | 15 #include "content/public/browser/download_manager.h" |
| 16 #include "googleurl/src/gurl.h" | 16 #include "googleurl/src/gurl.h" |
| 17 | 17 |
| 18 class Profile; | 18 class Profile; |
| 19 | 19 |
| 20 namespace gdata { | 20 namespace gdata { |
| 21 class DocumentEntry; |
| 22 } |
| 21 | 23 |
| 22 class DocumentEntry; | 24 namespace drive { |
| 25 |
| 23 class DriveEntryProto; | 26 class DriveEntryProto; |
| 24 class DriveFileSystemInterface; | 27 class DriveFileSystemInterface; |
| 25 class DriveUploader; | 28 class DriveUploader; |
| 26 | 29 |
| 27 // Observes downloads to temporary local drive folder. Schedules these | 30 // Observes downloads to temporary local drive folder. Schedules these |
| 28 // downloads for upload to drive service. | 31 // downloads for upload to drive service. |
| 29 class DriveDownloadObserver : public content::DownloadManager::Observer, | 32 class DriveDownloadObserver : public content::DownloadManager::Observer, |
| 30 public content::DownloadItem::Observer { | 33 public content::DownloadItem::Observer { |
| 31 public: | 34 public: |
| 32 DriveDownloadObserver(DriveUploader* uploader, | 35 DriveDownloadObserver(DriveUploader* uploader, |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 | 187 |
| 185 // Callback invoked by DriveUploader when the upload associated with | 188 // Callback invoked by DriveUploader when the upload associated with |
| 186 // |download_id| has completed. |error| indicated whether the | 189 // |download_id| has completed. |error| indicated whether the |
| 187 // call was successful. This function takes ownership of DocumentEntry from | 190 // call was successful. This function takes ownership of DocumentEntry from |
| 188 // for use by MoveFileToDriveCache(). It also invokes the | 191 // for use by MoveFileToDriveCache(). It also invokes the |
| 189 // MaybeCompleteDownload() method on the DownloadItem to allow it to complete. | 192 // MaybeCompleteDownload() method on the DownloadItem to allow it to complete. |
| 190 void OnUploadComplete(int32 download_id, | 193 void OnUploadComplete(int32 download_id, |
| 191 DriveFileError error, | 194 DriveFileError error, |
| 192 const FilePath& drive_path, | 195 const FilePath& drive_path, |
| 193 const FilePath& file_path, | 196 const FilePath& file_path, |
| 194 scoped_ptr<DocumentEntry> document_entry); | 197 scoped_ptr<gdata::DocumentEntry> document_entry); |
| 195 | 198 |
| 196 // Moves the downloaded file to drive cache. | 199 // Moves the downloaded file to drive cache. |
| 197 // Must be called after DriveDownloadObserver receives COMPLETE notification. | 200 // Must be called after DriveDownloadObserver receives COMPLETE notification. |
| 198 void MoveFileToDriveCache(content::DownloadItem* download); | 201 void MoveFileToDriveCache(content::DownloadItem* download); |
| 199 | 202 |
| 200 // Private data. | 203 // Private data. |
| 201 // The uploader owned by DriveSystemService. Used to trigger file uploads. | 204 // The uploader owned by DriveSystemService. Used to trigger file uploads. |
| 202 DriveUploader* drive_uploader_; | 205 DriveUploader* drive_uploader_; |
| 203 // The file system owned by DriveSystemService. | 206 // The file system owned by DriveSystemService. |
| 204 DriveFileSystemInterface* file_system_; | 207 DriveFileSystemInterface* file_system_; |
| 205 // Observe the DownloadManager for new downloads. | 208 // Observe the DownloadManager for new downloads. |
| 206 content::DownloadManager* download_manager_; | 209 content::DownloadManager* download_manager_; |
| 207 | 210 |
| 208 // Temporary download location directory. | 211 // Temporary download location directory. |
| 209 FilePath drive_tmp_download_path_; | 212 FilePath drive_tmp_download_path_; |
| 210 | 213 |
| 211 // Map of pending downloads. | 214 // Map of pending downloads. |
| 212 typedef std::map<int32, content::DownloadItem*> DownloadMap; | 215 typedef std::map<int32, content::DownloadItem*> DownloadMap; |
| 213 DownloadMap pending_downloads_; | 216 DownloadMap pending_downloads_; |
| 214 | 217 |
| 215 // Note: This should remain the last member so it'll be destroyed and | 218 // Note: This should remain the last member so it'll be destroyed and |
| 216 // invalidate its weak pointers before any other members are destroyed. | 219 // invalidate its weak pointers before any other members are destroyed. |
| 217 base::WeakPtrFactory<DriveDownloadObserver> weak_ptr_factory_; | 220 base::WeakPtrFactory<DriveDownloadObserver> weak_ptr_factory_; |
| 218 | 221 |
| 219 DISALLOW_COPY_AND_ASSIGN(DriveDownloadObserver); | 222 DISALLOW_COPY_AND_ASSIGN(DriveDownloadObserver); |
| 220 }; | 223 }; |
| 221 | 224 |
| 222 } // namespace gdata | 225 } // namespace drive |
| 223 | 226 |
| 224 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_DOWNLOAD_OBSERVER_H_ | 227 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_DOWNLOAD_OBSERVER_H_ |
| OLD | NEW |