| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_FILE_SYSTEM_DOWNLOAD_OPERATION_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_DOWNLOAD_OPERATION_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_DOWNLOAD_OPERATION_H_ | 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_DOWNLOAD_OPERATION_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "chrome/browser/chromeos/drive/file_errors.h" | 10 #include "chrome/browser/chromeos/drive/file_errors.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 | 38 |
| 39 class DownloadOperation { | 39 class DownloadOperation { |
| 40 public: | 40 public: |
| 41 DownloadOperation(base::SequencedTaskRunner* blocking_task_runner, | 41 DownloadOperation(base::SequencedTaskRunner* blocking_task_runner, |
| 42 OperationObserver* observer, | 42 OperationObserver* observer, |
| 43 JobScheduler* scheduler, | 43 JobScheduler* scheduler, |
| 44 internal::ResourceMetadata* metadata, | 44 internal::ResourceMetadata* metadata, |
| 45 internal::FileCache* cache); | 45 internal::FileCache* cache); |
| 46 ~DownloadOperation(); | 46 ~DownloadOperation(); |
| 47 | 47 |
| 48 // Ensures that the file content is locally downloaded. | 48 // Ensures that the file content specified by |resource_id| is locally |
| 49 // For hosted documents, this method may create a JSON file representing the | 49 // downloaded. |
| 50 // file. | 50 // For hosted documents, this method may create a JSON file representing th |
| 51 // e file. |
| 51 // For regular files, if the locally cached file is found, returns it. | 52 // For regular files, if the locally cached file is found, returns it. |
| 52 // If not found, start to download the file from the server. | 53 // If not found, start to download the file from the server. |
| 53 // When a JSON file is created, the cache file is found or downloading is | 54 // When a JSON file is created, the cache file is found or downloading is |
| 54 // being started, |initialized_callback| is called with |local_file| | 55 // being started, |initialized_callback| is called with |local_file| |
| 55 // for JSON file or the cache file, or with |cancel_download_closure| for | 56 // for JSON file or the cache file, or with |cancel_download_closure| for |
| 56 // downloading. | 57 // downloading. |
| 57 // During the downloading |get_content_callback| will be called periodically | 58 // During the downloading |get_content_callback| will be called periodically |
| 58 // with the downloaded content. | 59 // with the downloaded content. |
| 59 // Upon completion or an error is found, |completion_callback| will be | 60 // Upon completion or an error is found, |completion_callback| will be |
| 60 // called. | 61 // called. |
| 61 // |initialized_callback| and |get_content_callback| can be null if not | 62 // |initialized_callback| and |get_content_callback| can be null if not |
| 62 // needed. | 63 // needed. |
| 63 // |completion_callback| must not be null. | 64 // |completion_callback| must not be null. |
| 64 void EnsureFileDownloaded( | 65 void EnsureFileDownloadedByResourceId( |
| 66 const std::string& resource_id, |
| 67 const ClientContext& context, |
| 68 const GetFileContentInitializedCallback& initialized_callback, |
| 69 const google_apis::GetContentCallback& get_content_callback, |
| 70 const GetFileCallback& completion_callback); |
| 71 |
| 72 // Does the same thing as EnsureFileDownloadedByResourceId for the file |
| 73 // specified by |file_path|. |
| 74 void EnsureFileDownloadedByPath( |
| 65 const base::FilePath& file_path, | 75 const base::FilePath& file_path, |
| 66 const ClientContext& context, | 76 const ClientContext& context, |
| 67 const GetFileContentInitializedCallback& initialized_callback, | 77 const GetFileContentInitializedCallback& initialized_callback, |
| 68 const google_apis::GetContentCallback& get_content_callback, | 78 const google_apis::GetContentCallback& get_content_callback, |
| 69 const GetFileCallback& completion_callback); | 79 const GetFileCallback& completion_callback); |
| 70 | 80 |
| 71 private: | 81 private: |
| 72 // Thin wrapper of Callbacks for EnsureFileDownloaded. | 82 // Thin wrapper of Callbacks for EnsureFileDownloaded. |
| 73 class DownloadCallback; | 83 class DownloadCallback; |
| 74 | 84 |
| 75 // Parameters for JobScheduler::DownloadFile. | 85 // Parameters for JobScheduler::DownloadFile. |
| 76 struct DownloadParams; | 86 struct DownloadParams; |
| 77 | 87 |
| 78 // Part of EnsureFileDownloaded(). Called upon the completion of precondition | 88 // Part of EnsureFileDownloaded(). Called upon the completion of precondition |
| 79 // check. | 89 // check. |
| 80 void EnsureFileDownloadedAfterCheckPreCondition( | 90 void EnsureFileDownloadedAfterCheckPreCondition( |
| 81 const base::FilePath& file_path, | |
| 82 const ClientContext& context, | 91 const ClientContext& context, |
| 83 const DownloadCallback& callback, | 92 const DownloadCallback& callback, |
| 84 scoped_ptr<ResourceEntry> entry, | 93 scoped_ptr<ResourceEntry> entry, |
| 85 base::FilePath* cache_file_path, | 94 base::FilePath* cache_file_path, |
| 86 FileError error); | 95 FileError error); |
| 87 | 96 |
| 88 // Part of EnsureFileDownloaded(). Called upon the completion of fetching | 97 // Part of EnsureFileDownloaded(). Called upon the completion of fetching |
| 89 // ResourceEntry from the server. | 98 // ResourceEntry from the server. |
| 90 void EnsureFileDownloadedAfterGetResourceEntry( | 99 void EnsureFileDownloadedAfterGetResourceEntry( |
| 91 const ClientContext& context, | 100 const ClientContext& context, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 // Note: This should remain the last member so it'll be destroyed and | 138 // Note: This should remain the last member so it'll be destroyed and |
| 130 // invalidate its weak pointers before any other members are destroyed. | 139 // invalidate its weak pointers before any other members are destroyed. |
| 131 base::WeakPtrFactory<DownloadOperation> weak_ptr_factory_; | 140 base::WeakPtrFactory<DownloadOperation> weak_ptr_factory_; |
| 132 DISALLOW_COPY_AND_ASSIGN(DownloadOperation); | 141 DISALLOW_COPY_AND_ASSIGN(DownloadOperation); |
| 133 }; | 142 }; |
| 134 | 143 |
| 135 } // namespace file_system | 144 } // namespace file_system |
| 136 } // namespace drive | 145 } // namespace drive |
| 137 | 146 |
| 138 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_DOWNLOAD_OPERATION_H_ | 147 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_DOWNLOAD_OPERATION_H_ |
| OLD | NEW |