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 #include "chrome/browser/chromeos/gdata/gdata_protocol_handler.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_protocol_handler.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 | 156 |
157 void OnUrlFetchDownloadData(GDataErrorCode error, | 157 void OnUrlFetchDownloadData(GDataErrorCode error, |
158 scoped_ptr<std::string> download_data); | 158 scoped_ptr<std::string> download_data); |
159 // Called from ReadRawData, returns true if data is ready, false otherwise. | 159 // Called from ReadRawData, returns true if data is ready, false otherwise. |
160 bool ContinueReadFromDownloadData(int* bytes_read); | 160 bool ContinueReadFromDownloadData(int* bytes_read); |
161 // Copies from download buffer into response buffer. | 161 // Copies from download buffer into response buffer. |
162 bool ReadFromDownloadData(); | 162 bool ReadFromDownloadData(); |
163 | 163 |
164 // Helper callback for handling async responses from | 164 // Helper callback for handling async responses from |
165 // GDataFileSystem::GetFileByResourceId(). | 165 // GDataFileSystem::GetFileByResourceId(). |
166 void OnGetFileByResourceId(GDataFileError error, | 166 void OnGetFileByResourceId(DriveFileError error, |
167 const FilePath& local_file_path, | 167 const FilePath& local_file_path, |
168 const std::string& mime_type, | 168 const std::string& mime_type, |
169 DriveFileType file_type); | 169 DriveFileType file_type); |
170 | 170 |
171 // Helper callback for GetFileSizeOnBlockingPool that sets |remaining_bytes_| | 171 // Helper callback for GetFileSizeOnBlockingPool that sets |remaining_bytes_| |
172 // to |file_size|, and notifies result for Start(). | 172 // to |file_size|, and notifies result for Start(). |
173 void OnGetFileSize(int64 *file_size); | 173 void OnGetFileSize(int64 *file_size); |
174 | 174 |
175 // Helper callback for GetEntryInfoByResourceId invoked by StartAsync. | 175 // Helper callback for GetEntryInfoByResourceId invoked by StartAsync. |
176 void OnGetEntryInfoByResourceId(const std::string& resource_id, | 176 void OnGetEntryInfoByResourceId(const std::string& resource_id, |
177 GDataFileError error, | 177 DriveFileError error, |
178 const FilePath& gdata_file_path, | 178 const FilePath& gdata_file_path, |
179 scoped_ptr<DriveEntryProto> entry_proto); | 179 scoped_ptr<DriveEntryProto> entry_proto); |
180 | 180 |
181 // Helper methods for ReadRawData to open file and read from its corresponding | 181 // Helper methods for ReadRawData to open file and read from its corresponding |
182 // stream in a streaming fashion. | 182 // stream in a streaming fashion. |
183 bool ContinueReadFromFile(int* bytes_read); | 183 bool ContinueReadFromFile(int* bytes_read); |
184 void ReadFromFile(); | 184 void ReadFromFile(); |
185 void ReadFileStream(int bytes_to_read); | 185 void ReadFileStream(int bytes_to_read); |
186 | 186 |
187 // Helper callback for handling async responses from FileStream::Open(). | 187 // Helper callback for handling async responses from FileStream::Open(). |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 | 501 |
502 file_system_->GetEntryInfoByResourceId( | 502 file_system_->GetEntryInfoByResourceId( |
503 resource_id, | 503 resource_id, |
504 base::Bind(&GDataURLRequestJob::OnGetEntryInfoByResourceId, | 504 base::Bind(&GDataURLRequestJob::OnGetEntryInfoByResourceId, |
505 weak_ptr_factory_->GetWeakPtr(), | 505 weak_ptr_factory_->GetWeakPtr(), |
506 resource_id)); | 506 resource_id)); |
507 } | 507 } |
508 | 508 |
509 void GDataURLRequestJob::OnGetEntryInfoByResourceId( | 509 void GDataURLRequestJob::OnGetEntryInfoByResourceId( |
510 const std::string& resource_id, | 510 const std::string& resource_id, |
511 GDataFileError error, | 511 DriveFileError error, |
512 const FilePath& gdata_file_path, | 512 const FilePath& gdata_file_path, |
513 scoped_ptr<DriveEntryProto> entry_proto) { | 513 scoped_ptr<DriveEntryProto> entry_proto) { |
514 if (entry_proto.get() && !entry_proto->has_file_specific_info()) | 514 if (entry_proto.get() && !entry_proto->has_file_specific_info()) |
515 error = GDATA_FILE_ERROR_NOT_FOUND; | 515 error = DRIVE_FILE_ERROR_NOT_FOUND; |
516 | 516 |
517 if (error == GDATA_FILE_OK) { | 517 if (error == DRIVE_FILE_OK) { |
518 DCHECK(entry_proto.get()); | 518 DCHECK(entry_proto.get()); |
519 mime_type_ = entry_proto->file_specific_info().content_mime_type(); | 519 mime_type_ = entry_proto->file_specific_info().content_mime_type(); |
520 gdata_file_path_ = gdata_file_path; | 520 gdata_file_path_ = gdata_file_path; |
521 initial_file_size_ = entry_proto->file_info().size(); | 521 initial_file_size_ = entry_proto->file_info().size(); |
522 } else { | 522 } else { |
523 mime_type_.clear(); | 523 mime_type_.clear(); |
524 gdata_file_path_.clear(); | 524 gdata_file_path_.clear(); |
525 initial_file_size_ = 0; | 525 initial_file_size_ = 0; |
526 } | 526 } |
527 remaining_bytes_ = initial_file_size_; | 527 remaining_bytes_ = initial_file_size_; |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
647 // Set offset in download buffer to where we finished moving. | 647 // Set offset in download buffer to where we finished moving. |
648 download_drainable_buf_->SetOffset(bytes_not_copied); | 648 download_drainable_buf_->SetOffset(bytes_not_copied); |
649 } | 649 } |
650 DVLOG(1) << "Copied from download data: bytes_read=" << bytes_to_read; | 650 DVLOG(1) << "Copied from download data: bytes_read=" << bytes_to_read; |
651 | 651 |
652 // Return true if read buffer is filled up or there's no more bytes to read. | 652 // Return true if read buffer is filled up or there's no more bytes to read. |
653 return read_buf_->BytesRemaining() == 0 || remaining_bytes_ == 0; | 653 return read_buf_->BytesRemaining() == 0 || remaining_bytes_ == 0; |
654 } | 654 } |
655 | 655 |
656 void GDataURLRequestJob::OnGetFileByResourceId( | 656 void GDataURLRequestJob::OnGetFileByResourceId( |
657 GDataFileError error, | 657 DriveFileError error, |
658 const FilePath& local_file_path, | 658 const FilePath& local_file_path, |
659 const std::string& mime_type, | 659 const std::string& mime_type, |
660 DriveFileType file_type) { | 660 DriveFileType file_type) { |
661 DVLOG(1) << "Got OnGetFileByResourceId"; | 661 DVLOG(1) << "Got OnGetFileByResourceId"; |
662 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 662 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
663 | 663 |
664 if (error != GDATA_FILE_OK || file_type != REGULAR_FILE) { | 664 if (error != DRIVE_FILE_OK || file_type != REGULAR_FILE) { |
665 LOG(WARNING) << "Failed to start request: can't get file for resource id"; | 665 LOG(WARNING) << "Failed to start request: can't get file for resource id"; |
666 NotifyStartError(net::URLRequestStatus(net::URLRequestStatus::FAILED, | 666 NotifyStartError(net::URLRequestStatus(net::URLRequestStatus::FAILED, |
667 net::ERR_FILE_NOT_FOUND)); | 667 net::ERR_FILE_NOT_FOUND)); |
668 return; | 668 return; |
669 } | 669 } |
670 | 670 |
671 local_file_path_ = local_file_path; | 671 local_file_path_ = local_file_path; |
672 | 672 |
673 // If we've already streamed download data to response, we're done. | 673 // If we've already streamed download data to response, we're done. |
674 if (streaming_download_) | 674 if (streaming_download_) |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
933 GDataProtocolHandler::~GDataProtocolHandler() { | 933 GDataProtocolHandler::~GDataProtocolHandler() { |
934 } | 934 } |
935 | 935 |
936 net::URLRequestJob* GDataProtocolHandler::MaybeCreateJob( | 936 net::URLRequestJob* GDataProtocolHandler::MaybeCreateJob( |
937 net::URLRequest* request) const { | 937 net::URLRequest* request) const { |
938 DVLOG(1) << "Handling url: " << request->url().spec(); | 938 DVLOG(1) << "Handling url: " << request->url().spec(); |
939 return new GDataURLRequestJob(request); | 939 return new GDataURLRequestJob(request); |
940 } | 940 } |
941 | 941 |
942 } // namespace gdata | 942 } // namespace gdata |
OLD | NEW |