| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/chromeos/fileapi/external_file_url_request_job.h" | 5 #include "chrome/browser/chromeos/fileapi/external_file_url_request_job.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 const char kMimeTypeForRFC822[] = "message/rfc822"; | 42 const char kMimeTypeForRFC822[] = "message/rfc822"; |
| 43 const char kMimeTypeForMHTML[] = "multipart/related"; | 43 const char kMimeTypeForMHTML[] = "multipart/related"; |
| 44 | 44 |
| 45 // Helper for obtaining FileSystemContext, FileSystemURL, and mime type on the | 45 // Helper for obtaining FileSystemContext, FileSystemURL, and mime type on the |
| 46 // UI thread. | 46 // UI thread. |
| 47 class URLHelper { | 47 class URLHelper { |
| 48 public: | 48 public: |
| 49 // The scoped pointer to control lifetime of the instance itself. The pointer | 49 // The scoped pointer to control lifetime of the instance itself. The pointer |
| 50 // is passed to callback functions and binds the lifetime of the instance to | 50 // is passed to callback functions and binds the lifetime of the instance to |
| 51 // the callback's lifetime. | 51 // the callback's lifetime. |
| 52 typedef scoped_ptr<URLHelper> Lifetime; | 52 typedef std::unique_ptr<URLHelper> Lifetime; |
| 53 | 53 |
| 54 URLHelper(void* profile_id, | 54 URLHelper(void* profile_id, |
| 55 const GURL& url, | 55 const GURL& url, |
| 56 const ExternalFileURLRequestJob::HelperCallback& callback) | 56 const ExternalFileURLRequestJob::HelperCallback& callback) |
| 57 : profile_id_(profile_id), url_(url), callback_(callback) { | 57 : profile_id_(profile_id), url_(url), callback_(callback) { |
| 58 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 58 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 59 Lifetime lifetime(this); | 59 Lifetime lifetime(this); |
| 60 BrowserThread::PostTask(BrowserThread::UI, | 60 BrowserThread::PostTask(BrowserThread::UI, |
| 61 FROM_HERE, | 61 FROM_HERE, |
| 62 base::Bind(&URLHelper::RunOnUIThread, | 62 base::Bind(&URLHelper::RunOnUIThread, |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 file_system_context_, | 133 file_system_context_, |
| 134 base::Passed(&isolated_file_system_scope_), | 134 base::Passed(&isolated_file_system_scope_), |
| 135 file_system_url_, | 135 file_system_url_, |
| 136 mime_type_)); | 136 mime_type_)); |
| 137 } | 137 } |
| 138 | 138 |
| 139 void* const profile_id_; | 139 void* const profile_id_; |
| 140 const GURL url_; | 140 const GURL url_; |
| 141 const ExternalFileURLRequestJob::HelperCallback callback_; | 141 const ExternalFileURLRequestJob::HelperCallback callback_; |
| 142 scoped_refptr<storage::FileSystemContext> file_system_context_; | 142 scoped_refptr<storage::FileSystemContext> file_system_context_; |
| 143 scoped_ptr<ExternalFileURLRequestJob::IsolatedFileSystemScope> | 143 std::unique_ptr<ExternalFileURLRequestJob::IsolatedFileSystemScope> |
| 144 isolated_file_system_scope_; | 144 isolated_file_system_scope_; |
| 145 storage::FileSystemURL file_system_url_; | 145 storage::FileSystemURL file_system_url_; |
| 146 std::string mime_type_; | 146 std::string mime_type_; |
| 147 | 147 |
| 148 DISALLOW_COPY_AND_ASSIGN(URLHelper); | 148 DISALLOW_COPY_AND_ASSIGN(URLHelper); |
| 149 }; | 149 }; |
| 150 | 150 |
| 151 } // namespace | 151 } // namespace |
| 152 | 152 |
| 153 ExternalFileURLRequestJob::IsolatedFileSystemScope::IsolatedFileSystemScope( | 153 ExternalFileURLRequestJob::IsolatedFileSystemScope::IsolatedFileSystemScope( |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 // Owned by itself. | 226 // Owned by itself. |
| 227 new URLHelper(profile_id_, | 227 new URLHelper(profile_id_, |
| 228 request()->url(), | 228 request()->url(), |
| 229 base::Bind(&ExternalFileURLRequestJob::OnHelperResultObtained, | 229 base::Bind(&ExternalFileURLRequestJob::OnHelperResultObtained, |
| 230 weak_ptr_factory_.GetWeakPtr())); | 230 weak_ptr_factory_.GetWeakPtr())); |
| 231 } | 231 } |
| 232 | 232 |
| 233 void ExternalFileURLRequestJob::OnHelperResultObtained( | 233 void ExternalFileURLRequestJob::OnHelperResultObtained( |
| 234 net::Error error, | 234 net::Error error, |
| 235 const scoped_refptr<storage::FileSystemContext>& file_system_context, | 235 const scoped_refptr<storage::FileSystemContext>& file_system_context, |
| 236 scoped_ptr<IsolatedFileSystemScope> isolated_file_system_scope, | 236 std::unique_ptr<IsolatedFileSystemScope> isolated_file_system_scope, |
| 237 const storage::FileSystemURL& file_system_url, | 237 const storage::FileSystemURL& file_system_url, |
| 238 const std::string& mime_type) { | 238 const std::string& mime_type) { |
| 239 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 239 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 240 | 240 |
| 241 if (error != net::OK) { | 241 if (error != net::OK) { |
| 242 NotifyStartError( | 242 NotifyStartError( |
| 243 net::URLRequestStatus(net::URLRequestStatus::FAILED, error)); | 243 net::URLRequestStatus(net::URLRequestStatus::FAILED, error)); |
| 244 return; | 244 return; |
| 245 } | 245 } |
| 246 | 246 |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 void ExternalFileURLRequestJob::OnReadCompleted(int read_result) { | 371 void ExternalFileURLRequestJob::OnReadCompleted(int read_result) { |
| 372 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 372 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 373 | 373 |
| 374 if (read_result > 0) | 374 if (read_result > 0) |
| 375 remaining_bytes_ -= read_result; | 375 remaining_bytes_ -= read_result; |
| 376 | 376 |
| 377 ReadRawDataComplete(read_result); | 377 ReadRawDataComplete(read_result); |
| 378 } | 378 } |
| 379 | 379 |
| 380 } // namespace chromeos | 380 } // namespace chromeos |
| OLD | NEW |