| 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_UPLOADER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_GDATA_GDATA_UPLOADER_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_UPLOADER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_UPLOADER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <set> | 10 #include <set> |
| 11 #include <string> | 11 #include <string> |
| 12 | 12 |
| 13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "base/platform_file.h" | 15 #include "base/platform_file.h" |
| 16 #include "base/synchronization/lock.h" |
| 16 #include "chrome/browser/chromeos/gdata/gdata_errorcode.h" | 17 #include "chrome/browser/chromeos/gdata/gdata_errorcode.h" |
| 17 #include "chrome/browser/chromeos/gdata/gdata_params.h" | 18 #include "chrome/browser/chromeos/gdata/gdata_params.h" |
| 18 #include "googleurl/src/gurl.h" | 19 #include "googleurl/src/gurl.h" |
| 19 | 20 |
| 20 namespace content { | 21 namespace content { |
| 21 class DownloadItem; | 22 class DownloadItem; |
| 22 } | 23 } |
| 23 | 24 |
| 24 namespace gdata { | 25 namespace gdata { |
| 25 | 26 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 36 // Uploads a file specified by |upload_file_info|. Transfers ownership. | 37 // Uploads a file specified by |upload_file_info|. Transfers ownership. |
| 37 // Returns the upload_id. | 38 // Returns the upload_id. |
| 38 int UploadFile(scoped_ptr<UploadFileInfo> upload_file_info); | 39 int UploadFile(scoped_ptr<UploadFileInfo> upload_file_info); |
| 39 | 40 |
| 40 // Updates attributes of streaming upload. | 41 // Updates attributes of streaming upload. |
| 41 void UpdateUpload(int upload_id, content::DownloadItem* download); | 42 void UpdateUpload(int upload_id, content::DownloadItem* download); |
| 42 | 43 |
| 43 // Returns the count of bytes confirmed as uploaded so far. | 44 // Returns the count of bytes confirmed as uploaded so far. |
| 44 int64 GetUploadedBytes(int upload_id) const; | 45 int64 GetUploadedBytes(int upload_id) const; |
| 45 | 46 |
| 46 // TODO(achuith): Make this private. | |
| 47 // Destroys |upload_file_info|. | |
| 48 void DeleteUpload(UploadFileInfo* upload_file_info); | |
| 49 | |
| 50 private: | 47 private: |
| 51 // Lookup UploadFileInfo* in pending_uploads_. | 48 // Lookup UploadFileInfo* in pending_uploads_. |
| 52 UploadFileInfo* GetUploadFileInfo(int upload_id) const; | 49 UploadFileInfo* GetUploadFileInfo(int upload_id) const; |
| 53 | 50 |
| 54 // Open the file. | 51 // Open the file. |
| 55 void OpenFile(UploadFileInfo* upload_file_info); | 52 void OpenFile(UploadFileInfo* upload_file_info); |
| 56 | 53 |
| 57 // net::FileStream::Open completion callback. The result of the file | 54 // net::FileStream::Open completion callback. The result of the file |
| 58 // open operation is passed as |result|. | 55 // open operation is passed as |result|. |
| 59 void OpenCompletionCallback(int upload_id, int result); | 56 void OpenCompletionCallback(int upload_id, int result); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 76 const ResumeUploadResponse& response, | 73 const ResumeUploadResponse& response, |
| 77 scoped_ptr<DocumentEntry> entry); | 74 scoped_ptr<DocumentEntry> entry); |
| 78 | 75 |
| 79 // When upload completes, move the file into the gdata cache. | 76 // When upload completes, move the file into the gdata cache. |
| 80 void MoveFileToCache(UploadFileInfo* upload_file_info); | 77 void MoveFileToCache(UploadFileInfo* upload_file_info); |
| 81 | 78 |
| 82 // Handle failed uploads. | 79 // Handle failed uploads. |
| 83 void UploadFailed(UploadFileInfo* upload_file_info, | 80 void UploadFailed(UploadFileInfo* upload_file_info, |
| 84 base::PlatformFileError error); | 81 base::PlatformFileError error); |
| 85 | 82 |
| 83 // Removes |upload_file_info| from UploadFileInfoMap |pending_uploads_|. |
| 84 // Note that this does not delete the |upload_file_info| object itself, |
| 85 // because it may still be in use by an asynchronous function. |
| 86 void RemoveUpload(UploadFileInfo* upload_file_info); |
| 87 |
| 88 // Helper function to delete the UploadFileInfo object after completion |
| 89 // of AddUploadedFile. |
| 90 void OnAddUploadFileComplete(UploadFileInfo* upload_file_info); |
| 91 |
| 86 // Pointers to GDataFileSystem and DocumentsServiceInterface objects owned by | 92 // Pointers to GDataFileSystem and DocumentsServiceInterface objects owned by |
| 87 // GDataSystemService. The lifetime of these two objects is guaranteed to | 93 // GDataSystemService. The lifetime of these two objects is guaranteed to |
| 88 // exceed that of the GDataUploader instance. | 94 // exceed that of the GDataUploader instance. |
| 89 GDataFileSystem* file_system_; | 95 GDataFileSystem* file_system_; |
| 90 DocumentsServiceInterface* documents_service_; | 96 DocumentsServiceInterface* documents_service_; |
| 91 | 97 |
| 92 int next_upload_id_; // id counter. | 98 int next_upload_id_; // id counter. |
| 93 | 99 |
| 94 typedef std::map<int, UploadFileInfo*> UploadFileInfoMap; | 100 typedef std::map<int, UploadFileInfo*> UploadFileInfoMap; |
| 95 UploadFileInfoMap pending_uploads_; | 101 UploadFileInfoMap pending_uploads_; |
| 96 | 102 |
| 97 // Factory for various callbacks. | 103 // Factory for various callbacks. |
| 98 base::WeakPtrFactory<GDataUploader> uploader_factory_; | 104 base::WeakPtrFactory<GDataUploader> uploader_factory_; |
| 99 | 105 |
| 106 // This ensures serialized access to UploadFileInfoMap |pending_uploads_|. |
| 107 base::Lock lock_; |
| 108 |
| 100 DISALLOW_COPY_AND_ASSIGN(GDataUploader); | 109 DISALLOW_COPY_AND_ASSIGN(GDataUploader); |
| 101 }; | 110 }; |
| 102 | 111 |
| 103 } // namespace gdata | 112 } // namespace gdata |
| 104 | 113 |
| 105 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_UPLOADER_H_ | 114 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_UPLOADER_H_ |
| OLD | NEW |