| 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 "chrome/browser/chromeos/gdata/gdata_errorcode.h" | 16 #include "chrome/browser/chromeos/gdata/gdata_errorcode.h" |
| 17 #include "chrome/browser/chromeos/gdata/gdata_params.h" | 17 #include "chrome/browser/chromeos/gdata/gdata_params.h" |
| 18 #include "googleurl/src/gurl.h" | 18 #include "googleurl/src/gurl.h" |
| 19 | 19 |
| 20 namespace content { | 20 namespace content { |
| 21 class DownloadItem; | 21 class DownloadItem; |
| 22 } | 22 } |
| 23 | 23 |
| 24 namespace gdata { | 24 namespace gdata { |
| 25 | 25 |
| 26 class GDataFileSystem; | 26 class GDataFileSystem; |
| 27 class DocumentsServiceInterface; | 27 class DocumentsServiceInterface; |
| 28 struct UploadFileInfo; | 28 struct UploadFileInfo; |
| 29 | 29 |
| 30 class GDataUploader { | 30 class GDataUploaderInterface { |
| 31 public: | 31 public: |
| 32 explicit GDataUploader(GDataFileSystem* file_system, | 32 ~GDataUploaderInterface() {} |
| 33 DocumentsServiceInterface* documents_service); | |
| 34 virtual ~GDataUploader(); | |
| 35 | 33 |
| 36 // Uploads a file specified by |upload_file_info|. Transfers ownership. | 34 // Uploads a file specified by |upload_file_info|. Transfers ownership. |
| 37 // Returns the upload_id. | 35 // Returns the upload_id. |
| 38 int UploadFile(scoped_ptr<UploadFileInfo> upload_file_info); | 36 // |
| 37 // WARNING: This is not mockable by gmock because it takes scoped_ptr<>. |
| 38 // See "Announcing scoped_ptr<>::Pass(). The latest in pointer ownership |
| 39 // technology!" thread on chromium-dev. |
| 40 virtual int UploadFile(scoped_ptr<UploadFileInfo> upload_file_info) = 0; |
| 39 | 41 |
| 40 // Updates attributes of streaming upload. | 42 // Updates attributes of streaming upload. |
| 41 void UpdateUpload(int upload_id, content::DownloadItem* download); | 43 virtual void UpdateUpload(int upload_id, |
| 44 content::DownloadItem* download) = 0; |
| 42 | 45 |
| 43 // Returns the count of bytes confirmed as uploaded so far. | 46 // Returns the count of bytes confirmed as uploaded so far. |
| 44 int64 GetUploadedBytes(int upload_id) const; | 47 virtual int64 GetUploadedBytes(int upload_id) const = 0; |
| 48 }; |
| 49 |
| 50 class GDataUploader : public GDataUploaderInterface { |
| 51 public: |
| 52 explicit GDataUploader(DocumentsServiceInterface* documents_service); |
| 53 virtual ~GDataUploader(); |
| 54 |
| 55 // Sets the file system. This must be called before calling other member |
| 56 // functions. |
| 57 // |
| 58 // TODO(satorux): The dependency to GDataFileSystem should be |
| 59 // eliminated. http://crbug.com/133860 |
| 60 void set_file_system(GDataFileSystem* file_system) { |
| 61 file_system_ = file_system; |
| 62 } |
| 63 |
| 64 // GDataUploaderInterface overrides. |
| 65 virtual int UploadFile( |
| 66 scoped_ptr<UploadFileInfo> upload_file_info) OVERRIDE; |
| 67 virtual void UpdateUpload( |
| 68 int upload_id, content::DownloadItem* download) OVERRIDE; |
| 69 virtual int64 GetUploadedBytes(int upload_id) const OVERRIDE; |
| 45 | 70 |
| 46 private: | 71 private: |
| 47 // Lookup UploadFileInfo* in pending_uploads_. | 72 // Lookup UploadFileInfo* in pending_uploads_. |
| 48 UploadFileInfo* GetUploadFileInfo(int upload_id) const; | 73 UploadFileInfo* GetUploadFileInfo(int upload_id) const; |
| 49 | 74 |
| 50 // Open the file. | 75 // Open the file. |
| 51 void OpenFile(UploadFileInfo* upload_file_info); | 76 void OpenFile(UploadFileInfo* upload_file_info); |
| 52 | 77 |
| 53 // net::FileStream::Open completion callback. The result of the file | 78 // net::FileStream::Open completion callback. The result of the file |
| 54 // open operation is passed as |result|. | 79 // open operation is passed as |result|. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 | 122 |
| 98 // Factory for various callbacks. | 123 // Factory for various callbacks. |
| 99 base::WeakPtrFactory<GDataUploader> uploader_factory_; | 124 base::WeakPtrFactory<GDataUploader> uploader_factory_; |
| 100 | 125 |
| 101 DISALLOW_COPY_AND_ASSIGN(GDataUploader); | 126 DISALLOW_COPY_AND_ASSIGN(GDataUploader); |
| 102 }; | 127 }; |
| 103 | 128 |
| 104 } // namespace gdata | 129 } // namespace gdata |
| 105 | 130 |
| 106 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_UPLOADER_H_ | 131 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_UPLOADER_H_ |
| OLD | NEW |