OLD | NEW |
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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/renderer_host/file_system_accessor.h" | 5 #include "chrome/browser/renderer_host/file_system_accessor.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "chrome/browser/chrome_thread.h" | 9 #include "chrome/browser/chrome_thread.h" |
10 | 10 |
11 FileSystemAccessor::FileSystemAccessor(void* param, FileSizeCallback* callback) | 11 FileSystemAccessor::FileSystemAccessor(void* param, FileSizeCallback* callback) |
12 : param_(param), callback_(callback) { | 12 : param_(param), callback_(callback) { |
13 caller_loop_ = MessageLoop::current(); | 13 caller_loop_ = MessageLoop::current(); |
14 } | 14 } |
15 | 15 |
16 FileSystemAccessor::~FileSystemAccessor() { | 16 FileSystemAccessor::~FileSystemAccessor() { |
17 } | 17 } |
18 | 18 |
19 void FileSystemAccessor::RequestFileSize(const FilePath& path, | 19 void FileSystemAccessor::RequestFileSize(const FilePath& path, |
20 void* param, | 20 void* param, |
21 FileSizeCallback* callback) { | 21 FileSizeCallback* callback) { |
22 // Getting file size could take long time if it lives on a network share, | 22 // Getting file size could take long time if it lives on a network share, |
23 // so run it on FILE thread. | 23 // so run it on FILE thread. |
24 ChromeThread::GetMessageLoop(ChromeThread::FILE)->PostTask( | 24 ChromeThread::PostTask( |
25 FROM_HERE, | 25 ChromeThread::FILE, FROM_HERE, |
26 NewRunnableMethod(new FileSystemAccessor(param, callback), | 26 NewRunnableMethod(new FileSystemAccessor(param, callback), |
27 &FileSystemAccessor::GetFileSize, path)); | 27 &FileSystemAccessor::GetFileSize, path)); |
28 } | 28 } |
29 | 29 |
30 void FileSystemAccessor::GetFileSize(const FilePath& path) { | 30 void FileSystemAccessor::GetFileSize(const FilePath& path) { |
31 int64 result; | 31 int64 result; |
32 // Set result to -1 if failed to get file size. | 32 // Set result to -1 if failed to get file size. |
33 if (!file_util::GetFileSize(path, &result)) | 33 if (!file_util::GetFileSize(path, &result)) |
34 result = -1; | 34 result = -1; |
35 | 35 |
36 // Pass the result back to the caller thread. | 36 // Pass the result back to the caller thread. |
37 caller_loop_->PostTask( | 37 caller_loop_->PostTask( |
38 FROM_HERE, | 38 FROM_HERE, |
39 NewRunnableMethod(this, &FileSystemAccessor::GetFileSizeCompleted, result)); | 39 NewRunnableMethod(this, &FileSystemAccessor::GetFileSizeCompleted, result)); |
40 } | 40 } |
41 | 41 |
42 void FileSystemAccessor::GetFileSizeCompleted(int64 result) { | 42 void FileSystemAccessor::GetFileSizeCompleted(int64 result) { |
43 callback_->Run(result, param_); | 43 callback_->Run(result, param_); |
44 } | 44 } |
OLD | NEW |