| 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 <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 const int kHTTPInternalError = 500; | 52 const int kHTTPInternalError = 500; |
| 53 | 53 |
| 54 const char kHTTPOkText[] = "OK"; | 54 const char kHTTPOkText[] = "OK"; |
| 55 const char kHTTPNotAllowedText[] = "Not Allowed"; | 55 const char kHTTPNotAllowedText[] = "Not Allowed"; |
| 56 const char kHTTPNotFoundText[] = "Not Found"; | 56 const char kHTTPNotFoundText[] = "Not Found"; |
| 57 const char kHTTPInternalErrorText[] = "Internal Error"; | 57 const char kHTTPInternalErrorText[] = "Internal Error"; |
| 58 | 58 |
| 59 // Initial size of download buffer, same as kBufferSize used for URLFetcherCore. | 59 // Initial size of download buffer, same as kBufferSize used for URLFetcherCore. |
| 60 const int kInitialDownloadBufferSizeInBytes = 4096; | 60 const int kInitialDownloadBufferSizeInBytes = 4096; |
| 61 | 61 |
| 62 struct MimeTypeReplacement { |
| 63 const char* original_type; |
| 64 const char* new_type; |
| 65 }; |
| 66 |
| 67 const MimeTypeReplacement kMimeTypeReplacements[] = { |
| 68 {"message/rfc822","multipart/related"} // Fixes MHTML |
| 69 }; |
| 70 |
| 71 std::string FixupMimeType(const std::string& type) { |
| 72 for (size_t i = 0; i < arraysize(kMimeTypeReplacements); i++) { |
| 73 if (type == kMimeTypeReplacements[i].original_type) |
| 74 return kMimeTypeReplacements[i].new_type; |
| 75 } |
| 76 return type; |
| 77 } |
| 78 |
| 62 // Empty callback for net::FileStream::Close(). | 79 // Empty callback for net::FileStream::Close(). |
| 63 void EmptyCompletionCallback(int) { | 80 void EmptyCompletionCallback(int) { |
| 64 } | 81 } |
| 65 | 82 |
| 66 // Helper function that reads file size. | 83 // Helper function that reads file size. |
| 67 void GetFileSizeOnBlockingPool(const FilePath& file_path, | 84 void GetFileSizeOnBlockingPool(const FilePath& file_path, |
| 68 int64* file_size) { | 85 int64* file_size) { |
| 69 if (!file_util::GetFileSize(file_path, file_size)) | 86 if (!file_util::GetFileSize(file_path, file_size)) |
| 70 *file_size = 0; | 87 *file_size = 0; |
| 71 } | 88 } |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 base::Bind(&CancelGDataDownloadOnUIThread, | 335 base::Bind(&CancelGDataDownloadOnUIThread, |
| 319 gdata_file_path_)); | 336 gdata_file_path_)); |
| 320 } | 337 } |
| 321 | 338 |
| 322 net::URLRequestJob::Kill(); | 339 net::URLRequestJob::Kill(); |
| 323 weak_ptr_factory_->InvalidateWeakPtrs(); | 340 weak_ptr_factory_->InvalidateWeakPtrs(); |
| 324 } | 341 } |
| 325 | 342 |
| 326 bool GDataURLRequestJob::GetMimeType(std::string* mime_type) const { | 343 bool GDataURLRequestJob::GetMimeType(std::string* mime_type) const { |
| 327 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 344 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 328 mime_type->assign(mime_type_); | 345 mime_type->assign(FixupMimeType(mime_type_)); |
| 329 return !mime_type->empty(); | 346 return !mime_type->empty(); |
| 330 } | 347 } |
| 331 | 348 |
| 332 void GDataURLRequestJob::GetResponseInfo(net::HttpResponseInfo* info) { | 349 void GDataURLRequestJob::GetResponseInfo(net::HttpResponseInfo* info) { |
| 333 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 350 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 334 if (response_info_.get()) | 351 if (response_info_.get()) |
| 335 *info = *response_info_; | 352 *info = *response_info_; |
| 336 } | 353 } |
| 337 | 354 |
| 338 int GDataURLRequestJob::GetResponseCode() const { | 355 int GDataURLRequestJob::GetResponseCode() const { |
| (...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 903 GDataProtocolHandler::~GDataProtocolHandler() { | 920 GDataProtocolHandler::~GDataProtocolHandler() { |
| 904 } | 921 } |
| 905 | 922 |
| 906 net::URLRequestJob* GDataProtocolHandler::MaybeCreateJob( | 923 net::URLRequestJob* GDataProtocolHandler::MaybeCreateJob( |
| 907 net::URLRequest* request) const { | 924 net::URLRequest* request) const { |
| 908 DVLOG(1) << "Handling url: " << request->url().spec(); | 925 DVLOG(1) << "Handling url: " << request->url().spec(); |
| 909 return new GDataURLRequestJob(request); | 926 return new GDataURLRequestJob(request); |
| 910 } | 927 } |
| 911 | 928 |
| 912 } // namespace gdata | 929 } // namespace gdata |
| OLD | NEW |