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

Side by Side Diff: chrome/browser/renderer_host/file_system_accessor.cc

Issue 338065: Add the ability for objects which derive from RefCountedThreadSafe to specify... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 }
OLDNEW
« 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