| 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/drive_protocol_handler.h" | 5 #include "chrome/browser/chromeos/gdata/drive_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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 }; | 72 }; |
| 73 | 73 |
| 74 std::string FixupMimeType(const std::string& type) { | 74 std::string FixupMimeType(const std::string& type) { |
| 75 for (size_t i = 0; i < arraysize(kMimeTypeReplacements); i++) { | 75 for (size_t i = 0; i < arraysize(kMimeTypeReplacements); i++) { |
| 76 if (type == kMimeTypeReplacements[i].original_type) | 76 if (type == kMimeTypeReplacements[i].original_type) |
| 77 return kMimeTypeReplacements[i].new_type; | 77 return kMimeTypeReplacements[i].new_type; |
| 78 } | 78 } |
| 79 return type; | 79 return type; |
| 80 } | 80 } |
| 81 | 81 |
| 82 // Empty callback for net::FileStream::Close(). | |
| 83 void EmptyCompletionCallback(int) { | |
| 84 } | |
| 85 | |
| 86 // Helper function that reads file size. | 82 // Helper function that reads file size. |
| 87 void GetFileSizeOnBlockingPool(const FilePath& file_path, | 83 void GetFileSizeOnBlockingPool(const FilePath& file_path, |
| 88 int64* file_size) { | 84 int64* file_size) { |
| 89 if (!file_util::GetFileSize(file_path, file_size)) | 85 if (!file_util::GetFileSize(file_path, file_size)) |
| 90 *file_size = kInvalidFileSize; | 86 *file_size = kInvalidFileSize; |
| 91 } | 87 } |
| 92 | 88 |
| 93 // Helper function that extracts and unescapes resource_id from drive urls | 89 // Helper function that extracts and unescapes resource_id from drive urls |
| 94 // (drive:<resource_id>). | 90 // (drive:<resource_id>). |
| 95 bool ParseDriveUrl(const std::string& path, std::string* resource_id) { | 91 bool ParseDriveUrl(const std::string& path, std::string* resource_id) { |
| (...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 838 DCHECK_GE(remaining_bytes_, 0); | 834 DCHECK_GE(remaining_bytes_, 0); |
| 839 | 835 |
| 840 // Adjust the read buffer. | 836 // Adjust the read buffer. |
| 841 read_buf_->DidConsume(bytes_read); | 837 read_buf_->DidConsume(bytes_read); |
| 842 DCHECK_GE(read_buf_->BytesRemaining(), 0); | 838 DCHECK_GE(read_buf_->BytesRemaining(), 0); |
| 843 } | 839 } |
| 844 | 840 |
| 845 void DriveURLRequestJob::CloseFileStream() { | 841 void DriveURLRequestJob::CloseFileStream() { |
| 846 if (!stream_.get()) | 842 if (!stream_.get()) |
| 847 return; | 843 return; |
| 848 stream_->Close(base::Bind(&EmptyCompletionCallback)); | |
| 849 // net::FileStream::Close blocks until stream is closed, so it's safe to | |
| 850 // release the pointer here. | |
| 851 stream_.reset(NULL); | 844 stream_.reset(NULL); |
| 852 } | 845 } |
| 853 | 846 |
| 854 void DriveURLRequestJob::NotifySuccess() { | 847 void DriveURLRequestJob::NotifySuccess() { |
| 855 HeadersCompleted(kHTTPOk, kHTTPOkText); | 848 HeadersCompleted(kHTTPOk, kHTTPOkText); |
| 856 } | 849 } |
| 857 | 850 |
| 858 void DriveURLRequestJob::NotifyFailure(int error_code) { | 851 void DriveURLRequestJob::NotifyFailure(int error_code) { |
| 859 error_ = true; | 852 error_ = true; |
| 860 | 853 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 934 DriveProtocolHandler::~DriveProtocolHandler() { | 927 DriveProtocolHandler::~DriveProtocolHandler() { |
| 935 } | 928 } |
| 936 | 929 |
| 937 net::URLRequestJob* DriveProtocolHandler::MaybeCreateJob( | 930 net::URLRequestJob* DriveProtocolHandler::MaybeCreateJob( |
| 938 net::URLRequest* request, net::NetworkDelegate* network_delegate) const { | 931 net::URLRequest* request, net::NetworkDelegate* network_delegate) const { |
| 939 DVLOG(1) << "Handling url: " << request->url().spec(); | 932 DVLOG(1) << "Handling url: " << request->url().spec(); |
| 940 return new DriveURLRequestJob(request, network_delegate); | 933 return new DriveURLRequestJob(request, network_delegate); |
| 941 } | 934 } |
| 942 | 935 |
| 943 } // namespace gdata | 936 } // namespace gdata |
| OLD | NEW |