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 |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "base/platform_file.h" | 13 #include "base/platform_file.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 | 16 |
17 class Profile; | 17 class Profile; |
18 | 18 |
19 namespace gdata { | 19 namespace gdata { |
20 | 20 |
21 class DocumentEntry; | 21 class DocumentEntry; |
22 class GDataFileSystem; | |
22 class GDataUploader; | 23 class GDataUploader; |
23 struct UploadFileInfo; | 24 struct UploadFileInfo; |
24 | 25 |
25 // Observes downloads to temporary local gdata folder. Schedules these | 26 // Observes downloads to temporary local gdata folder. Schedules these |
26 // downloads for upload to gdata service. | 27 // downloads for upload to gdata service. |
27 class GDataDownloadObserver : public content::DownloadManager::Observer, | 28 class GDataDownloadObserver : public content::DownloadManager::Observer, |
28 public content::DownloadItem::Observer { | 29 public content::DownloadItem::Observer { |
29 public: | 30 public: |
30 GDataDownloadObserver(); | 31 GDataDownloadObserver(GDataUploader* uploader, GDataFileSystem* file_system); |
31 virtual ~GDataDownloadObserver(); | 32 virtual ~GDataDownloadObserver(); |
32 | 33 |
33 // Become an observer of DownloadManager. | 34 // Become an observer of DownloadManager. |
34 void Initialize(GDataUploader* gdata_uploader, | 35 void Initialize(content::DownloadManager* download_manager, |
35 content::DownloadManager* download_manager, | |
36 const FilePath& gdata_tmp_download_path); | 36 const FilePath& gdata_tmp_download_path); |
37 | 37 |
38 typedef base::Callback<void(const FilePath&)> | 38 typedef base::Callback<void(const FilePath&)> |
39 SubstituteGDataDownloadPathCallback; | 39 SubstituteGDataDownloadPathCallback; |
40 static void SubstituteGDataDownloadPath(Profile* profile, | 40 static void SubstituteGDataDownloadPath(Profile* profile, |
41 const FilePath& gdata_path, content::DownloadItem* download, | 41 const FilePath& gdata_path, content::DownloadItem* download, |
42 const SubstituteGDataDownloadPathCallback& callback); | 42 const SubstituteGDataDownloadPathCallback& callback); |
43 | 43 |
44 // Sets gdata path, for example, '/special/drive/MyFolder/MyFile', | 44 // Sets gdata path, for example, '/special/drive/MyFolder/MyFile', |
45 // to external data in |download|. Also sets display name and | 45 // to external data in |download|. Also sets display name and |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
107 | 107 |
108 // Checks if this DownloadItem should be uploaded. | 108 // Checks if this DownloadItem should be uploaded. |
109 bool ShouldUpload(content::DownloadItem* download); | 109 bool ShouldUpload(content::DownloadItem* download); |
110 | 110 |
111 // Creates UploadFileInfo and initializes it using DownloadItem*. | 111 // Creates UploadFileInfo and initializes it using DownloadItem*. |
112 scoped_ptr<UploadFileInfo> CreateUploadFileInfo( | 112 scoped_ptr<UploadFileInfo> CreateUploadFileInfo( |
113 content::DownloadItem* download); | 113 content::DownloadItem* download); |
114 | 114 |
115 // Callback invoked by GDataUploader when the upload associated with | 115 // Callback invoked by GDataUploader when the upload associated with |
116 // |download_id| has completed. |error| indicated whether the | 116 // |download_id| has completed. |error| indicated whether the |
117 // call was successful. This function invokes the MaybeCompleteDownload() | 117 // call was successful. This function takes ownership of DocumentEntry from |
118 // method on the DownloadItem to allow it to complete. | 118 // |upload_file_info| for use by MoveFileToGDataCache(). It also invokes the |
119 // MaybeCompleteDownload() method on the DownloadItem to allow it to complete. | |
asanka
2012/07/11 15:56:52
Nit: This doesn't call MaybeCompleteDownload() any
| |
119 void OnUploadComplete(int32 download_id, | 120 void OnUploadComplete(int32 download_id, |
120 base::PlatformFileError error, | 121 base::PlatformFileError error, |
121 scoped_ptr<UploadFileInfo> upload_file_info); | 122 scoped_ptr<UploadFileInfo> upload_file_info); |
122 | 123 |
124 // Moves the downloaded file to gdata cache. | |
125 // Must be called after GDataDownloadObserver receives COMPLETE notification. | |
126 void MoveFileToGDataCache(content::DownloadItem* download); | |
127 | |
123 // Private data. | 128 // Private data. |
124 // Use GDataUploader to trigger file uploads. | 129 // The uploader owned by GDataSystemService. Used to trigger file uploads. |
125 GDataUploader* gdata_uploader_; | 130 GDataUploader* gdata_uploader_; |
131 // The file system owned by GDataSystemService. | |
132 GDataFileSystem* file_system_; | |
126 // Observe the DownloadManager for new downloads. | 133 // Observe the DownloadManager for new downloads. |
127 content::DownloadManager* download_manager_; | 134 content::DownloadManager* download_manager_; |
128 | 135 |
129 // Temporary download location directory. | 136 // Temporary download location directory. |
130 FilePath gdata_tmp_download_path_; | 137 FilePath gdata_tmp_download_path_; |
131 | 138 |
132 // Map of pending downloads. | 139 // Map of pending downloads. |
133 typedef std::map<int32, content::DownloadItem*> DownloadMap; | 140 typedef std::map<int32, content::DownloadItem*> DownloadMap; |
134 DownloadMap pending_downloads_; | 141 DownloadMap pending_downloads_; |
135 | 142 |
136 base::WeakPtrFactory<GDataDownloadObserver> weak_ptr_factory_; | 143 base::WeakPtrFactory<GDataDownloadObserver> weak_ptr_factory_; |
137 | 144 |
138 DISALLOW_COPY_AND_ASSIGN(GDataDownloadObserver); | 145 DISALLOW_COPY_AND_ASSIGN(GDataDownloadObserver); |
139 }; | 146 }; |
140 | 147 |
141 } // namespace gdata | 148 } // namespace gdata |
142 | 149 |
143 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_DOWNLOAD_OBSERVER_H__ | 150 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_DOWNLOAD_OBSERVER_H__ |
OLD | NEW |