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