OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "base/file_util_proxy.h" | 5 #include "base/file_util_proxy.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/message_loop_proxy.h" | 8 #include "base/message_loop_proxy.h" |
9 | 9 |
| 10 // TODO(jianli): Move the code from anonymous namespace to base namespace so |
| 11 // that all of the base:: prefixes would be unnecessary. |
10 namespace { | 12 namespace { |
11 | 13 |
12 class MessageLoopRelay | 14 class MessageLoopRelay |
13 : public base::RefCountedThreadSafe<MessageLoopRelay> { | 15 : public base::RefCountedThreadSafe<MessageLoopRelay> { |
14 public: | 16 public: |
15 MessageLoopRelay() | 17 MessageLoopRelay() |
16 : origin_message_loop_proxy_( | 18 : origin_message_loop_proxy_( |
17 base::MessageLoopProxy::CreateForCurrentThread()), | 19 base::MessageLoopProxy::CreateForCurrentThread()), |
18 error_code_(base::PLATFORM_FILE_OK) { | 20 error_code_(base::PLATFORM_FILE_OK) { |
19 } | 21 } |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 virtual void RunWork() { | 200 virtual void RunWork() { |
199 if (!file_util::Delete(file_path_, recursive_)) | 201 if (!file_util::Delete(file_path_, recursive_)) |
200 set_error_code(base::PLATFORM_FILE_ERROR); | 202 set_error_code(base::PLATFORM_FILE_ERROR); |
201 } | 203 } |
202 | 204 |
203 private: | 205 private: |
204 FilePath file_path_; | 206 FilePath file_path_; |
205 bool recursive_; | 207 bool recursive_; |
206 }; | 208 }; |
207 | 209 |
| 210 class RelayGetFileInfo : public MessageLoopRelay { |
| 211 public: |
| 212 RelayGetFileInfo(const FilePath& file_path, |
| 213 base::FileUtilProxy::GetFileInfoCallback* callback) |
| 214 : callback_(callback), |
| 215 file_path_(file_path), |
| 216 exists_(false) { |
| 217 DCHECK(callback); |
| 218 } |
| 219 |
| 220 protected: |
| 221 virtual void RunWork() { |
| 222 exists_ = file_util::GetFileInfo(file_path_, &file_info_); |
| 223 } |
| 224 |
| 225 virtual void RunCallback() { |
| 226 callback_->Run(exists_, file_info_); |
| 227 delete callback_; |
| 228 } |
| 229 |
| 230 private: |
| 231 base::FileUtilProxy::GetFileInfoCallback* callback_; |
| 232 FilePath file_path_; |
| 233 bool exists_; |
| 234 file_util::FileInfo file_info_; |
| 235 }; |
| 236 |
208 bool Start(const tracked_objects::Location& from_here, | 237 bool Start(const tracked_objects::Location& from_here, |
209 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, | 238 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, |
210 scoped_refptr<MessageLoopRelay> relay) { | 239 scoped_refptr<MessageLoopRelay> relay) { |
211 return relay->Start(message_loop_proxy, from_here); | 240 return relay->Start(message_loop_proxy, from_here); |
212 } | 241 } |
213 | 242 |
214 } // namespace | 243 } // namespace |
215 | 244 |
216 namespace base { | 245 namespace base { |
217 | 246 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 | 279 |
251 // static | 280 // static |
252 bool FileUtilProxy::RecursiveDelete( | 281 bool FileUtilProxy::RecursiveDelete( |
253 scoped_refptr<MessageLoopProxy> message_loop_proxy, | 282 scoped_refptr<MessageLoopProxy> message_loop_proxy, |
254 const FilePath& file_path, | 283 const FilePath& file_path, |
255 StatusCallback* callback) { | 284 StatusCallback* callback) { |
256 return Start(FROM_HERE, message_loop_proxy, | 285 return Start(FROM_HERE, message_loop_proxy, |
257 new RelayDelete(file_path, true, callback)); | 286 new RelayDelete(file_path, true, callback)); |
258 } | 287 } |
259 | 288 |
| 289 // static |
| 290 bool FileUtilProxy::GetFileInfo( |
| 291 scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 292 const FilePath& file_path, |
| 293 GetFileInfoCallback* callback) { |
| 294 return Start(FROM_HERE, message_loop_proxy, |
| 295 new RelayGetFileInfo(file_path, callback)); |
| 296 } |
| 297 |
260 } // namespace base | 298 } // namespace base |
OLD | NEW |