Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(848)

Side by Side Diff: chrome/browser/chromeos/drive/drive_protocol_handler.cc

Issue 10701050: net: Implement canceling of all async operations in FileStream. (Closed) Base URL: https://src.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/drive/drive_protocol_handler.h" 5 #include "chrome/browser/chromeos/drive/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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 }; 70 };
71 71
72 std::string FixupMimeType(const std::string& type) { 72 std::string FixupMimeType(const std::string& type) {
73 for (size_t i = 0; i < arraysize(kMimeTypeReplacements); i++) { 73 for (size_t i = 0; i < arraysize(kMimeTypeReplacements); i++) {
74 if (type == kMimeTypeReplacements[i].original_type) 74 if (type == kMimeTypeReplacements[i].original_type)
75 return kMimeTypeReplacements[i].new_type; 75 return kMimeTypeReplacements[i].new_type;
76 } 76 }
77 return type; 77 return type;
78 } 78 }
79 79
80 // Empty callback for net::FileStream::Close().
81 void EmptyCompletionCallback(int) {
82 }
83
84 // Helper function that extracts and unescapes resource_id from drive urls 80 // Helper function that extracts and unescapes resource_id from drive urls
85 // (drive:<resource_id>). 81 // (drive:<resource_id>).
86 bool ParseDriveUrl(const std::string& path, std::string* resource_id) { 82 bool ParseDriveUrl(const std::string& path, std::string* resource_id) {
87 const std::string drive_schema(chrome::kDriveScheme + std::string(":")); 83 const std::string drive_schema(chrome::kDriveScheme + std::string(":"));
88 if (!StartsWithASCII(path, drive_schema, false) || 84 if (!StartsWithASCII(path, drive_schema, false) ||
89 path.size() <= drive_schema.size()) { 85 path.size() <= drive_schema.size()) {
90 return false; 86 return false;
91 } 87 }
92 88
93 std::string id = path.substr(drive_schema.size()); 89 std::string id = path.substr(drive_schema.size());
(...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 // Subtract the remaining bytes. 822 // Subtract the remaining bytes.
827 remaining_bytes_ -= bytes_read; 823 remaining_bytes_ -= bytes_read;
828 DCHECK_GE(remaining_bytes_, 0); 824 DCHECK_GE(remaining_bytes_, 0);
829 825
830 // Adjust the read buffer. 826 // Adjust the read buffer.
831 read_buf_->DidConsume(bytes_read); 827 read_buf_->DidConsume(bytes_read);
832 DCHECK_GE(read_buf_->BytesRemaining(), 0); 828 DCHECK_GE(read_buf_->BytesRemaining(), 0);
833 } 829 }
834 830
835 void DriveURLRequestJob::CloseFileStream() { 831 void DriveURLRequestJob::CloseFileStream() {
836 if (!stream_.get()) 832 stream_.reset();
837 return;
838 stream_->Close(base::Bind(&EmptyCompletionCallback));
839 // net::FileStream::Close blocks until stream is closed, so it's safe to
840 // release the pointer here.
841 stream_.reset(NULL);
842 } 833 }
843 834
844 void DriveURLRequestJob::NotifySuccess() { 835 void DriveURLRequestJob::NotifySuccess() {
845 HeadersCompleted(kHTTPOk, kHTTPOkText); 836 HeadersCompleted(kHTTPOk, kHTTPOkText);
846 } 837 }
847 838
848 void DriveURLRequestJob::NotifyFailure(int error_code) { 839 void DriveURLRequestJob::NotifyFailure(int error_code) {
849 error_ = true; 840 error_ = true;
850 841
851 // If we already return the headers on success, we can't change the headers 842 // If we already return the headers on success, we can't change the headers
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
924 DriveProtocolHandler::~DriveProtocolHandler() { 915 DriveProtocolHandler::~DriveProtocolHandler() {
925 } 916 }
926 917
927 net::URLRequestJob* DriveProtocolHandler::MaybeCreateJob( 918 net::URLRequestJob* DriveProtocolHandler::MaybeCreateJob(
928 net::URLRequest* request, net::NetworkDelegate* network_delegate) const { 919 net::URLRequest* request, net::NetworkDelegate* network_delegate) const {
929 DVLOG(1) << "Handling url: " << request->url().spec(); 920 DVLOG(1) << "Handling url: " << request->url().spec();
930 return new DriveURLRequestJob(request, network_delegate); 921 return new DriveURLRequestJob(request, network_delegate);
931 } 922 }
932 923
933 } // namespace drive 924 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698