Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(298)

Unified Diff: chrome/browser/renderer_host/file_system_accessor.cc

Issue 131082: Add getFileSize support to chromium... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/renderer_host/file_system_accessor.cc
===================================================================
--- chrome/browser/renderer_host/file_system_accessor.cc (revision 0)
+++ chrome/browser/renderer_host/file_system_accessor.cc (revision 0)
@@ -0,0 +1,44 @@
+// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/renderer_host/file_system_accessor.h"
+
+#include "base/file_util.h"
+#include "base/message_loop.h"
+#include "chrome/browser/chrome_thread.h"
+
+FileSystemAccessor::FileSystemAccessor(void* param, FileSizeCallback* callback)
+ : param_(param), callback_(callback) {
+ caller_loop_ = MessageLoop::current();
+}
+
+FileSystemAccessor::~FileSystemAccessor() {
+}
+
+void FileSystemAccessor::RequestFileSize(const FilePath& path,
+ void* param,
+ FileSizeCallback* callback) {
+ // Getting file size could take long time if it lives on a network share,
+ // so run it on FILE thread.
+ ChromeThread::GetMessageLoop(ChromeThread::FILE)->PostTask(
+ FROM_HERE,
+ NewRunnableMethod(new FileSystemAccessor(param, callback),
+ &FileSystemAccessor::GetFileSize, path));
+}
+
+void FileSystemAccessor::GetFileSize(const FilePath& path) {
+ int64 result;
+ // Set result to -1 if failed to get file size.
+ if (!file_util::GetFileSize(path, &result))
+ result = -1;
+
+ // Pass the result back to the caller thread.
+ caller_loop_->PostTask(
+ FROM_HERE,
+ NewRunnableMethod(this, &FileSystemAccessor::GetFileSizeCompleted, result));
+}
+
+void FileSystemAccessor::GetFileSizeCompleted(int64 result) {
+ callback_->Run(result, param_);
+}
Property changes on: chrome\browser\renderer_host\file_system_accessor.cc
___________________________________________________________________
Added: svn:eol-style
+ LF
« no previous file with comments | « chrome/browser/renderer_host/file_system_accessor.h ('k') | chrome/browser/renderer_host/file_system_accessor_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698