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_GDATA_GDATA_DOWNLOAD_OBSERVER_H__ | 5 #ifndef CHROME_BROWSER_CHROMEOS_GDATA_GDATA_DOWNLOAD_OBSERVER_H__ |
6 #define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_DOWNLOAD_OBSERVER_H__ | 6 #define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_DOWNLOAD_OBSERVER_H__ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 | 10 |
(...skipping 11 matching lines...) Expand all Loading... |
22 | 22 |
23 // Observes downloads to temporary local gdata folder. Schedules these | 23 // Observes downloads to temporary local gdata folder. Schedules these |
24 // downloads for upload to gdata service. | 24 // downloads for upload to gdata service. |
25 class GDataDownloadObserver : public content::DownloadManager::Observer, | 25 class GDataDownloadObserver : public content::DownloadManager::Observer, |
26 public content::DownloadItem::Observer { | 26 public content::DownloadItem::Observer { |
27 public: | 27 public: |
28 GDataDownloadObserver(); | 28 GDataDownloadObserver(); |
29 virtual ~GDataDownloadObserver(); | 29 virtual ~GDataDownloadObserver(); |
30 | 30 |
31 // Become an observer of DownloadManager. | 31 // Become an observer of DownloadManager. |
32 void Initialize(const FilePath& temp_download_path, | 32 void Initialize(GDataUploader* gdata_uploader, |
33 GDataUploader* gdata_uploader, | 33 content::DownloadManager* download_manager, |
34 content::DownloadManager* download_manager); | 34 const FilePath& gdata_tmp_download_path); |
35 | 35 |
36 // Sets gdata path, for example, '/special/gdata/MyFolder/MyFile', | 36 // Sets gdata path, for example, '/special/gdata/MyFolder/MyFile', |
37 // to external data in |download|. | 37 // to external data in |download|. |
38 static void SetGDataPath(content::DownloadItem* download, | 38 static void SetGDataPath(content::DownloadItem* download, |
39 const FilePath& gdata_path); | 39 const FilePath& gdata_path); |
40 | 40 |
41 // Checks if there is a GData upload associated with |download| | 41 // Checks if there is a GData upload associated with |download| |
42 static bool IsGDataDownload(content::DownloadItem* download); | 42 static bool IsGDataDownload(content::DownloadItem* download); |
43 | 43 |
44 // Checks if |download| is ready to complete. Returns true if |download| has | 44 // Checks if |download| is ready to complete. Returns true if |download| has |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 // Starts the upload of a downloaded/downloading file. | 86 // Starts the upload of a downloaded/downloading file. |
87 void UploadDownloadItem(content::DownloadItem* download); | 87 void UploadDownloadItem(content::DownloadItem* download); |
88 | 88 |
89 // Updates metadata of ongoing upload if it exists. | 89 // Updates metadata of ongoing upload if it exists. |
90 void UpdateUpload(content::DownloadItem* download); | 90 void UpdateUpload(content::DownloadItem* download); |
91 | 91 |
92 // Checks if this DownloadItem should be uploaded. | 92 // Checks if this DownloadItem should be uploaded. |
93 bool ShouldUpload(content::DownloadItem* download); | 93 bool ShouldUpload(content::DownloadItem* download); |
94 | 94 |
95 // Creates UploadFileInfo and initializes it using DownloadItem*. | 95 // Creates UploadFileInfo and initializes it using DownloadItem*. |
96 UploadFileInfo* CreateUploadFileInfo(content::DownloadItem* download); | 96 scoped_ptr<UploadFileInfo> CreateUploadFileInfo( |
| 97 content::DownloadItem* download); |
97 | 98 |
98 // Callback invoked by GDataUploader when the upload associated with | 99 // Callback invoked by GDataUploader when the upload associated with |
99 // |download_id| has completed. |error| indicated whether the | 100 // |download_id| has completed. |error| indicated whether the |
100 // call was successful. This function invokes the MaybeCompleteDownload() | 101 // call was successful. This function invokes the MaybeCompleteDownload() |
101 // method on the DownloadItem to allow it to complete. | 102 // method on the DownloadItem to allow it to complete. |
102 void OnUploadComplete(int32 download_id, base::PlatformFileError error, | 103 void OnUploadComplete(int32 download_id, |
103 DocumentEntry* unused_entry); | 104 base::PlatformFileError error, |
| 105 UploadFileInfo* upload_file_info); |
104 | 106 |
105 // Private data. | 107 // Private data. |
106 // Use GDataUploader to trigger file uploads. | 108 // Use GDataUploader to trigger file uploads. |
107 GDataUploader* gdata_uploader_; | 109 GDataUploader* gdata_uploader_; |
108 // Observe the DownloadManager for new downloads. | 110 // Observe the DownloadManager for new downloads. |
109 content::DownloadManager* download_manager_; | 111 content::DownloadManager* download_manager_; |
110 | 112 |
| 113 // Temporary download location directory. |
| 114 FilePath gdata_tmp_download_path_; |
| 115 |
| 116 // Map of pending downloads. |
111 typedef std::map<int32, content::DownloadItem*> DownloadMap; | 117 typedef std::map<int32, content::DownloadItem*> DownloadMap; |
112 DownloadMap pending_downloads_; | 118 DownloadMap pending_downloads_; |
113 | 119 |
114 base::WeakPtrFactory<GDataDownloadObserver> weak_ptr_factory_; | 120 base::WeakPtrFactory<GDataDownloadObserver> weak_ptr_factory_; |
115 | 121 |
116 // Temporary download location directory. | |
117 FilePath temp_download_path_; | |
118 | |
119 DISALLOW_COPY_AND_ASSIGN(GDataDownloadObserver); | 122 DISALLOW_COPY_AND_ASSIGN(GDataDownloadObserver); |
120 }; | 123 }; |
121 | 124 |
122 } // namespace gdata | 125 } // namespace gdata |
123 | 126 |
124 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_DOWNLOAD_OBSERVER_H__ | 127 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_DOWNLOAD_OBSERVER_H__ |
OLD | NEW |