| 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 #include "chrome/browser/sync_file_system/drive/api_util.h" | 5 #include "chrome/browser/sync_file_system/drive/api_util.h" |
| 6 | 6 |
| 7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/message_loop/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop_proxy.h" |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 public: | 116 public: |
| 117 explicit FakeDriveUploader(FakeDriveServiceWrapper* fake_drive_service) | 117 explicit FakeDriveUploader(FakeDriveServiceWrapper* fake_drive_service) |
| 118 : fake_drive_service_(fake_drive_service), | 118 : fake_drive_service_(fake_drive_service), |
| 119 make_file_conflict_(false) {} | 119 make_file_conflict_(false) {} |
| 120 virtual ~FakeDriveUploader() {} | 120 virtual ~FakeDriveUploader() {} |
| 121 | 121 |
| 122 // DriveUploaderInterface overrides. | 122 // DriveUploaderInterface overrides. |
| 123 | 123 |
| 124 // Pretends that a new file was uploaded successfully, and returns the | 124 // Pretends that a new file was uploaded successfully, and returns the |
| 125 // contents of "chromeos/gdata/file_entry.json" to the caller. | 125 // contents of "chromeos/gdata/file_entry.json" to the caller. |
| 126 virtual void UploadNewFile( | 126 virtual google_apis::CancelCallback UploadNewFile( |
| 127 const std::string& parent_resource_id, | 127 const std::string& parent_resource_id, |
| 128 const base::FilePath& drive_file_path, | 128 const base::FilePath& drive_file_path, |
| 129 const base::FilePath& local_file_path, | 129 const base::FilePath& local_file_path, |
| 130 const std::string& title, | 130 const std::string& title, |
| 131 const std::string& content_type, | 131 const std::string& content_type, |
| 132 const google_apis::UploadCompletionCallback& callback, | 132 const google_apis::UploadCompletionCallback& callback, |
| 133 const google_apis::ProgressCallback& progress_callback) OVERRIDE { | 133 const google_apis::ProgressCallback& progress_callback) OVERRIDE { |
| 134 DCHECK(!callback.is_null()); | 134 DCHECK(!callback.is_null()); |
| 135 | 135 |
| 136 scoped_ptr<base::Value> file_entry_data( | 136 scoped_ptr<base::Value> file_entry_data( |
| 137 LoadJSONFile("chromeos/gdata/file_entry.json")); | 137 LoadJSONFile("chromeos/gdata/file_entry.json")); |
| 138 scoped_ptr<ResourceEntry> file_entry( | 138 scoped_ptr<ResourceEntry> file_entry( |
| 139 ResourceEntry::ExtractAndParse(*file_entry_data)); | 139 ResourceEntry::ExtractAndParse(*file_entry_data)); |
| 140 | 140 |
| 141 if (make_file_conflict_) { | 141 if (make_file_conflict_) { |
| 142 fake_drive_service_->LoadResourceListForWapi( | 142 fake_drive_service_->LoadResourceListForWapi( |
| 143 "chromeos/sync_file_system/conflict_with_file.json"); | 143 "chromeos/sync_file_system/conflict_with_file.json"); |
| 144 } else { | 144 } else { |
| 145 fake_drive_service_->LoadResourceListForWapi( | 145 fake_drive_service_->LoadResourceListForWapi( |
| 146 "chromeos/sync_file_system/upload_new_file.json"); | 146 "chromeos/sync_file_system/upload_new_file.json"); |
| 147 } | 147 } |
| 148 | 148 |
| 149 base::MessageLoopProxy::current()->PostTask( | 149 base::MessageLoopProxy::current()->PostTask( |
| 150 FROM_HERE, | 150 FROM_HERE, |
| 151 base::Bind(callback, | 151 base::Bind(callback, |
| 152 google_apis::HTTP_SUCCESS, | 152 google_apis::HTTP_SUCCESS, |
| 153 GURL(), | 153 GURL(), |
| 154 base::Passed(&file_entry))); | 154 base::Passed(&file_entry))); |
| 155 return google_apis::CancelCallback(); |
| 155 } | 156 } |
| 156 | 157 |
| 157 // Pretends that an existing file ("file:resource_id") was uploaded | 158 // Pretends that an existing file ("file:resource_id") was uploaded |
| 158 // successfully, and returns the contents of "chromeos/gdata/file_entry.json" | 159 // successfully, and returns the contents of "chromeos/gdata/file_entry.json" |
| 159 // to the caller. | 160 // to the caller. |
| 160 virtual void UploadExistingFile( | 161 virtual google_apis::CancelCallback UploadExistingFile( |
| 161 const std::string& resource_id, | 162 const std::string& resource_id, |
| 162 const base::FilePath& drive_file_path, | 163 const base::FilePath& drive_file_path, |
| 163 const base::FilePath& local_file_path, | 164 const base::FilePath& local_file_path, |
| 164 const std::string& content_type, | 165 const std::string& content_type, |
| 165 const std::string& etag, | 166 const std::string& etag, |
| 166 const google_apis::UploadCompletionCallback& callback, | 167 const google_apis::UploadCompletionCallback& callback, |
| 167 const google_apis::ProgressCallback& progress_callback) OVERRIDE { | 168 const google_apis::ProgressCallback& progress_callback) OVERRIDE { |
| 168 DCHECK(!callback.is_null()); | 169 DCHECK(!callback.is_null()); |
| 169 | 170 |
| 170 scoped_ptr<base::Value> file_entry_data( | 171 scoped_ptr<base::Value> file_entry_data( |
| 171 LoadJSONFile("chromeos/gdata/file_entry.json")); | 172 LoadJSONFile("chromeos/gdata/file_entry.json")); |
| 172 scoped_ptr<ResourceEntry> file_entry( | 173 scoped_ptr<ResourceEntry> file_entry( |
| 173 ResourceEntry::ExtractAndParse(*file_entry_data)); | 174 ResourceEntry::ExtractAndParse(*file_entry_data)); |
| 174 | 175 |
| 175 base::MessageLoopProxy::current()->PostTask( | 176 base::MessageLoopProxy::current()->PostTask( |
| 176 FROM_HERE, | 177 FROM_HERE, |
| 177 base::Bind(callback, | 178 base::Bind(callback, |
| 178 google_apis::HTTP_SUCCESS, | 179 google_apis::HTTP_SUCCESS, |
| 179 GURL(), | 180 GURL(), |
| 180 base::Passed(&file_entry))); | 181 base::Passed(&file_entry))); |
| 182 return google_apis::CancelCallback(); |
| 181 } | 183 } |
| 182 | 184 |
| 183 // At the moment, sync file system doesn't support resuming of the uploading. | 185 // At the moment, sync file system doesn't support resuming of the uploading. |
| 184 // So this method shouldn't be reached. | 186 // So this method shouldn't be reached. |
| 185 virtual void ResumeUploadFile( | 187 virtual google_apis::CancelCallback ResumeUploadFile( |
| 186 const GURL& upload_location, | 188 const GURL& upload_location, |
| 187 const base::FilePath& drive_file_path, | 189 const base::FilePath& drive_file_path, |
| 188 const base::FilePath& local_file_path, | 190 const base::FilePath& local_file_path, |
| 189 const std::string& content_type, | 191 const std::string& content_type, |
| 190 const google_apis::UploadCompletionCallback& callback, | 192 const google_apis::UploadCompletionCallback& callback, |
| 191 const google_apis::ProgressCallback& progress_callback) OVERRIDE { | 193 const google_apis::ProgressCallback& progress_callback) OVERRIDE { |
| 192 NOTREACHED(); | 194 NOTREACHED(); |
| 195 return google_apis::CancelCallback(); |
| 193 } | 196 } |
| 194 | 197 |
| 195 void set_make_file_conflict(bool enable) { | 198 void set_make_file_conflict(bool enable) { |
| 196 make_file_conflict_ = enable; | 199 make_file_conflict_ = enable; |
| 197 } | 200 } |
| 198 | 201 |
| 199 private: | 202 private: |
| 200 FakeDriveServiceWrapper* fake_drive_service_; | 203 FakeDriveServiceWrapper* fake_drive_service_; |
| 201 bool make_file_conflict_; | 204 bool make_file_conflict_; |
| 202 | 205 |
| (...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 837 FROM_HERE, | 840 FROM_HERE, |
| 838 resource_id, | 841 resource_id, |
| 839 google_apis::ENTRY_KIND_FOLDER)); | 842 google_apis::ENTRY_KIND_FOLDER)); |
| 840 message_loop()->RunUntilIdle(); | 843 message_loop()->RunUntilIdle(); |
| 841 } | 844 } |
| 842 | 845 |
| 843 #endif // !defined(OS_ANDROID) | 846 #endif // !defined(OS_ANDROID) |
| 844 | 847 |
| 845 } // namespace drive | 848 } // namespace drive |
| 846 } // namespace sync_file_system | 849 } // namespace sync_file_system |
| OLD | NEW |