OLD | NEW |
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/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
8 #include "base/file_path.h" | 9 #include "base/file_path.h" |
9 #include "base/file_util_proxy.h" | 10 #include "base/file_util_proxy.h" |
10 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
11 #include "base/platform_file.h" | 12 #include "base/platform_file.h" |
12 #include "base/threading/thread_restrictions.h" | 13 #include "base/threading/thread_restrictions.h" |
13 #include "build/build_config.h" | 14 #include "build/build_config.h" |
14 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
15 #include "net/base/file_stream.h" | 16 #include "net/base/file_stream.h" |
16 #include "net/base/io_buffer.h" | 17 #include "net/base/io_buffer.h" |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 scoped_refptr<FileSystemURLRequestJob> job_; | 99 scoped_refptr<FileSystemURLRequestJob> job_; |
99 DISALLOW_COPY_AND_ASSIGN(CallbackDispatcher); | 100 DISALLOW_COPY_AND_ASSIGN(CallbackDispatcher); |
100 }; | 101 }; |
101 | 102 |
102 FileSystemURLRequestJob::FileSystemURLRequestJob( | 103 FileSystemURLRequestJob::FileSystemURLRequestJob( |
103 URLRequest* request, FileSystemContext* file_system_context, | 104 URLRequest* request, FileSystemContext* file_system_context, |
104 scoped_refptr<base::MessageLoopProxy> file_thread_proxy) | 105 scoped_refptr<base::MessageLoopProxy> file_thread_proxy) |
105 : URLRequestJob(request), | 106 : URLRequestJob(request), |
106 file_system_context_(file_system_context), | 107 file_system_context_(file_system_context), |
107 file_thread_proxy_(file_thread_proxy), | 108 file_thread_proxy_(file_thread_proxy), |
108 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), | 109 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), |
109 ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)), | |
110 ALLOW_THIS_IN_INITIALIZER_LIST( | 110 ALLOW_THIS_IN_INITIALIZER_LIST( |
111 io_callback_(this, &FileSystemURLRequestJob::DidRead)), | 111 io_callback_(this, &FileSystemURLRequestJob::DidRead)), |
112 stream_(NULL), | 112 stream_(NULL), |
113 is_directory_(false), | 113 is_directory_(false), |
114 remaining_bytes_(0) { | 114 remaining_bytes_(0) { |
115 } | 115 } |
116 | 116 |
117 FileSystemURLRequestJob::~FileSystemURLRequestJob() { | 117 FileSystemURLRequestJob::~FileSystemURLRequestJob() { |
118 // Since we use the two-arg constructor of FileStream, we need to call Close() | 118 // Since we use the two-arg constructor of FileStream, we need to call Close() |
119 // manually: ~FileStream won't call it for us. | 119 // manually: ~FileStream won't call it for us. |
120 if (stream_ != NULL) | 120 if (stream_ != NULL) |
121 stream_->Close(); | 121 stream_->Close(); |
122 } | 122 } |
123 | 123 |
124 void FileSystemURLRequestJob::Start() { | 124 void FileSystemURLRequestJob::Start() { |
125 MessageLoop::current()->PostTask(FROM_HERE, | 125 MessageLoop::current()->PostTask( |
126 method_factory_.NewRunnableMethod( | 126 FROM_HERE, |
127 &FileSystemURLRequestJob::StartAsync)); | 127 base::Bind(&FileSystemURLRequestJob::StartAsync, |
| 128 weak_factory_.GetWeakPtr())); |
128 } | 129 } |
129 | 130 |
130 void FileSystemURLRequestJob::Kill() { | 131 void FileSystemURLRequestJob::Kill() { |
131 if (stream_ != NULL) { | 132 if (stream_ != NULL) { |
132 stream_->Close(); | 133 stream_->Close(); |
133 stream_.reset(NULL); | 134 stream_.reset(NULL); |
134 } | 135 } |
135 URLRequestJob::Kill(); | 136 URLRequestJob::Kill(); |
136 method_factory_.RevokeAll(); | 137 weak_factory_.InvalidateWeakPtrs(); |
137 callback_factory_.RevokeAll(); | |
138 } | 138 } |
139 | 139 |
140 bool FileSystemURLRequestJob::ReadRawData(net::IOBuffer* dest, int dest_size, | 140 bool FileSystemURLRequestJob::ReadRawData(net::IOBuffer* dest, int dest_size, |
141 int *bytes_read) { | 141 int *bytes_read) { |
142 DCHECK_NE(dest_size, 0); | 142 DCHECK_NE(dest_size, 0); |
143 DCHECK(bytes_read); | 143 DCHECK(bytes_read); |
144 DCHECK_GE(remaining_bytes_, 0); | 144 DCHECK_GE(remaining_bytes_, 0); |
145 | 145 |
146 if (stream_ == NULL) | 146 if (stream_ == NULL) |
147 return false; | 147 return false; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 is_directory_ = file_info.is_directory; | 231 is_directory_ = file_info.is_directory; |
232 | 232 |
233 if (!byte_range_.ComputeBounds(file_info.size)) { | 233 if (!byte_range_.ComputeBounds(file_info.size)) { |
234 NotifyFailed(net::ERR_REQUEST_RANGE_NOT_SATISFIABLE); | 234 NotifyFailed(net::ERR_REQUEST_RANGE_NOT_SATISFIABLE); |
235 return; | 235 return; |
236 } | 236 } |
237 | 237 |
238 if (!is_directory_) { | 238 if (!is_directory_) { |
239 base::FileUtilProxy::CreateOrOpen( | 239 base::FileUtilProxy::CreateOrOpen( |
240 file_thread_proxy_, platform_path, kFileFlags, | 240 file_thread_proxy_, platform_path, kFileFlags, |
241 callback_factory_.NewCallback(&FileSystemURLRequestJob::DidOpen)); | 241 base::Bind(&FileSystemURLRequestJob::DidOpen, |
| 242 weak_factory_.GetWeakPtr())); |
242 } else { | 243 } else { |
243 NotifyHeadersComplete(); | 244 NotifyHeadersComplete(); |
244 } | 245 } |
245 } | 246 } |
246 | 247 |
247 void FileSystemURLRequestJob::DidOpen(base::PlatformFileError error_code, | 248 void FileSystemURLRequestJob::DidOpen(base::PlatformFileError error_code, |
248 base::PassPlatformFile file, | 249 base::PassPlatformFile file, |
249 bool created) { | 250 bool created) { |
250 if (error_code != base::PLATFORM_FILE_OK) { | 251 if (error_code != base::PLATFORM_FILE_OK) { |
251 NotifyFailed(error_code); | 252 NotifyFailed(error_code); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 } | 307 } |
307 | 308 |
308 return false; | 309 return false; |
309 } | 310 } |
310 | 311 |
311 void FileSystemURLRequestJob::NotifyFailed(int rv) { | 312 void FileSystemURLRequestJob::NotifyFailed(int rv) { |
312 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv)); | 313 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv)); |
313 } | 314 } |
314 | 315 |
315 } // namespace fileapi | 316 } // namespace fileapi |
OLD | NEW |