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 "webkit/fileapi/file_system_dir_url_request_job.h" | 5 #include "webkit/fileapi/file_system_dir_url_request_job.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 FilePath relative_path; | 34 FilePath relative_path; |
35 GURL unused_url; | 35 GURL unused_url; |
36 FileSystemType unused_type; | 36 FileSystemType unused_type; |
37 CrackFileSystemURL(url, &unused_url, &unused_type, &relative_path); | 37 CrackFileSystemURL(url, &unused_url, &unused_type, &relative_path); |
38 return relative_path; | 38 return relative_path; |
39 } | 39 } |
40 | 40 |
41 class FileSystemDirURLRequestJob::CallbackDispatcher | 41 class FileSystemDirURLRequestJob::CallbackDispatcher |
42 : public FileSystemCallbackDispatcher { | 42 : public FileSystemCallbackDispatcher { |
43 public: | 43 public: |
44 explicit CallbackDispatcher(FileSystemDirURLRequestJob* job) | 44 // An instance of this class must be created by Create() |
45 : job_(job) { | 45 // (so that we do not leak ownership). |
46 DCHECK(job_); | 46 static scoped_ptr<FileSystemCallbackDispatcher> Create( |
| 47 FileSystemDirURLRequestJob* job) { |
| 48 return scoped_ptr<FileSystemCallbackDispatcher>( |
| 49 new CallbackDispatcher(job)); |
47 } | 50 } |
48 | 51 |
49 // fileapi::FileSystemCallbackDispatcher overrides. | 52 // fileapi::FileSystemCallbackDispatcher overrides. |
50 virtual void DidSucceed() OVERRIDE { | 53 virtual void DidSucceed() OVERRIDE { |
51 NOTREACHED(); | 54 NOTREACHED(); |
52 } | 55 } |
53 | 56 |
54 virtual void DidReadMetadata(const base::PlatformFileInfo& file_info, | 57 virtual void DidReadMetadata(const base::PlatformFileInfo& file_info, |
55 const FilePath& platform_path) OVERRIDE { | 58 const FilePath& platform_path) OVERRIDE { |
56 NOTREACHED(); | 59 NOTREACHED(); |
(...skipping 15 matching lines...) Expand all Loading... |
72 } | 75 } |
73 | 76 |
74 virtual void DidFail(base::PlatformFileError error_code) OVERRIDE { | 77 virtual void DidFail(base::PlatformFileError error_code) OVERRIDE { |
75 int rv = net::ERR_FILE_NOT_FOUND; | 78 int rv = net::ERR_FILE_NOT_FOUND; |
76 if (error_code == base::PLATFORM_FILE_ERROR_INVALID_URL) | 79 if (error_code == base::PLATFORM_FILE_ERROR_INVALID_URL) |
77 rv = net::ERR_INVALID_URL; | 80 rv = net::ERR_INVALID_URL; |
78 job_->NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv)); | 81 job_->NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv)); |
79 } | 82 } |
80 | 83 |
81 private: | 84 private: |
| 85 explicit CallbackDispatcher(FileSystemDirURLRequestJob* job) : job_(job) { |
| 86 DCHECK(job_); |
| 87 } |
| 88 |
82 // TODO(adamk): Get rid of the need for refcounting here by | 89 // TODO(adamk): Get rid of the need for refcounting here by |
83 // allowing FileSystemOperations to be cancelled. | 90 // allowing FileSystemOperations to be cancelled. |
84 scoped_refptr<FileSystemDirURLRequestJob> job_; | 91 scoped_refptr<FileSystemDirURLRequestJob> job_; |
85 DISALLOW_COPY_AND_ASSIGN(CallbackDispatcher); | 92 DISALLOW_COPY_AND_ASSIGN(CallbackDispatcher); |
86 }; | 93 }; |
87 | 94 |
88 FileSystemDirURLRequestJob::FileSystemDirURLRequestJob( | 95 FileSystemDirURLRequestJob::FileSystemDirURLRequestJob( |
89 URLRequest* request, FileSystemContext* file_system_context, | 96 URLRequest* request, FileSystemContext* file_system_context, |
90 scoped_refptr<base::MessageLoopProxy> file_thread_proxy) | 97 scoped_refptr<base::MessageLoopProxy> file_thread_proxy) |
91 : URLRequestJob(request), | 98 : URLRequestJob(request), |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 | 175 |
169 if (has_more) { | 176 if (has_more) { |
170 GetNewOperation()->ReadDirectory(request_->url()); | 177 GetNewOperation()->ReadDirectory(request_->url()); |
171 } else { | 178 } else { |
172 set_expected_content_size(data_.size()); | 179 set_expected_content_size(data_.size()); |
173 NotifyHeadersComplete(); | 180 NotifyHeadersComplete(); |
174 } | 181 } |
175 } | 182 } |
176 | 183 |
177 FileSystemOperation* FileSystemDirURLRequestJob::GetNewOperation() { | 184 FileSystemOperation* FileSystemDirURLRequestJob::GetNewOperation() { |
178 return new FileSystemOperation(new CallbackDispatcher(this), | 185 return new FileSystemOperation(CallbackDispatcher::Create(this), |
179 file_thread_proxy_, | 186 file_thread_proxy_, |
180 file_system_context_); | 187 file_system_context_); |
181 } | 188 } |
182 | 189 |
183 } // namespace fileapi | 190 } // namespace fileapi |
OLD | NEW |