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

Side by Side Diff: webkit/fileapi/file_system_url_request_job.cc

Issue 8311010: base::Bind: Convert FileUtilProxy::CreateOrOpenCallback. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 2 months 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "webkit/fileapi/file_system_url_request_job.h" 5 #include "webkit/fileapi/file_system_url_request_job.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/file_util_proxy.h" 10 #include "base/file_util_proxy.h"
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 DISALLOW_COPY_AND_ASSIGN(CallbackDispatcher); 100 DISALLOW_COPY_AND_ASSIGN(CallbackDispatcher);
101 }; 101 };
102 102
103 FileSystemURLRequestJob::FileSystemURLRequestJob( 103 FileSystemURLRequestJob::FileSystemURLRequestJob(
104 URLRequest* request, FileSystemContext* file_system_context, 104 URLRequest* request, FileSystemContext* file_system_context,
105 scoped_refptr<base::MessageLoopProxy> file_thread_proxy) 105 scoped_refptr<base::MessageLoopProxy> file_thread_proxy)
106 : URLRequestJob(request), 106 : URLRequestJob(request),
107 file_system_context_(file_system_context), 107 file_system_context_(file_system_context),
108 file_thread_proxy_(file_thread_proxy), 108 file_thread_proxy_(file_thread_proxy),
109 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), 109 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)),
110 ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)), 110 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
111 stream_(NULL), 111 stream_(NULL),
112 is_directory_(false), 112 is_directory_(false),
113 remaining_bytes_(0) { 113 remaining_bytes_(0) {
114 } 114 }
115 115
116 FileSystemURLRequestJob::~FileSystemURLRequestJob() { 116 FileSystemURLRequestJob::~FileSystemURLRequestJob() {
117 // Since we use the two-arg constructor of FileStream, we need to call Close() 117 // Since we use the two-arg constructor of FileStream, we need to call Close()
118 // manually: ~FileStream won't call it for us. 118 // manually: ~FileStream won't call it for us.
119 if (stream_ != NULL) 119 if (stream_ != NULL)
120 stream_->Close(); 120 stream_->Close();
121 } 121 }
122 122
123 void FileSystemURLRequestJob::Start() { 123 void FileSystemURLRequestJob::Start() {
124 MessageLoop::current()->PostTask(FROM_HERE, 124 MessageLoop::current()->PostTask(FROM_HERE,
125 method_factory_.NewRunnableMethod( 125 method_factory_.NewRunnableMethod(
126 &FileSystemURLRequestJob::StartAsync)); 126 &FileSystemURLRequestJob::StartAsync));
127 } 127 }
128 128
129 void FileSystemURLRequestJob::Kill() { 129 void FileSystemURLRequestJob::Kill() {
130 if (stream_ != NULL) { 130 if (stream_ != NULL) {
131 stream_->Close(); 131 stream_->Close();
132 stream_.reset(NULL); 132 stream_.reset(NULL);
133 } 133 }
134 URLRequestJob::Kill(); 134 URLRequestJob::Kill();
135 method_factory_.RevokeAll(); 135 method_factory_.RevokeAll();
136 callback_factory_.RevokeAll(); 136 weak_factory_.InvalidateWeakPtrs();
137 } 137 }
138 138
139 bool FileSystemURLRequestJob::ReadRawData(net::IOBuffer* dest, int dest_size, 139 bool FileSystemURLRequestJob::ReadRawData(net::IOBuffer* dest, int dest_size,
140 int *bytes_read) { 140 int *bytes_read) {
141 DCHECK_NE(dest_size, 0); 141 DCHECK_NE(dest_size, 0);
142 DCHECK(bytes_read); 142 DCHECK(bytes_read);
143 DCHECK_GE(remaining_bytes_, 0); 143 DCHECK_GE(remaining_bytes_, 0);
144 144
145 if (stream_ == NULL) 145 if (stream_ == NULL)
146 return false; 146 return false;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 is_directory_ = file_info.is_directory; 232 is_directory_ = file_info.is_directory;
233 233
234 if (!byte_range_.ComputeBounds(file_info.size)) { 234 if (!byte_range_.ComputeBounds(file_info.size)) {
235 NotifyFailed(net::ERR_REQUEST_RANGE_NOT_SATISFIABLE); 235 NotifyFailed(net::ERR_REQUEST_RANGE_NOT_SATISFIABLE);
236 return; 236 return;
237 } 237 }
238 238
239 if (!is_directory_) { 239 if (!is_directory_) {
240 base::FileUtilProxy::CreateOrOpen( 240 base::FileUtilProxy::CreateOrOpen(
241 file_thread_proxy_, platform_path, kFileFlags, 241 file_thread_proxy_, platform_path, kFileFlags,
242 callback_factory_.NewCallback(&FileSystemURLRequestJob::DidOpen)); 242 base::Bind(&FileSystemURLRequestJob::DidOpen,
243 weak_factory_.GetWeakPtr()));
243 } else { 244 } else {
244 NotifyHeadersComplete(); 245 NotifyHeadersComplete();
245 } 246 }
246 } 247 }
247 248
248 void FileSystemURLRequestJob::DidOpen(base::PlatformFileError error_code, 249 void FileSystemURLRequestJob::DidOpen(base::PlatformFileError error_code,
249 base::PassPlatformFile file, 250 base::PassPlatformFile file,
250 bool created) { 251 bool created) {
251 if (error_code != base::PLATFORM_FILE_OK) { 252 if (error_code != base::PLATFORM_FILE_OK) {
252 NotifyFailed(error_code); 253 NotifyFailed(error_code);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 } 308 }
308 309
309 return false; 310 return false;
310 } 311 }
311 312
312 void FileSystemURLRequestJob::NotifyFailed(int rv) { 313 void FileSystemURLRequestJob::NotifyFailed(int rv) {
313 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv)); 314 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv));
314 } 315 }
315 316
316 } // namespace fileapi 317 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/fileapi/file_system_url_request_job.h ('k') | webkit/fileapi/file_system_url_request_job_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698