Chromium Code Reviews| Index: chrome/browser/chromeos/extensions/file_manager/private_api_file_system.cc |
| diff --git a/chrome/browser/chromeos/extensions/file_manager/private_api_file_system.cc b/chrome/browser/chromeos/extensions/file_manager/private_api_file_system.cc |
| index b7b52fac6cfea2125c6d5f1404114165293f3e4c..bcf2034bf8b441dc58efb9b21514c24b4bb9c53f 100644 |
| --- a/chrome/browser/chromeos/extensions/file_manager/private_api_file_system.cc |
| +++ b/chrome/browser/chromeos/extensions/file_manager/private_api_file_system.cc |
| @@ -34,6 +34,7 @@ |
| #include "content/public/browser/render_view_host.h" |
| #include "content/public/common/url_constants.h" |
| #include "net/base/escape.h" |
| +#include "storage/browser/blob/file_stream_reader.h" |
| #include "storage/browser/fileapi/file_system_context.h" |
| #include "storage/browser/fileapi/file_system_file_util.h" |
| #include "storage/browser/fileapi/file_system_operation_context.h" |
| @@ -719,7 +720,7 @@ bool FileManagerPrivateComputeChecksumFunction::RunAsync() { |
| EXTENSION_FUNCTION_VALIDATE(params); |
| if (params->file_url.empty()) { |
| - // TODO(kenobi): call SetError() |
| + SetError("File URL must be provided"); |
| return false; |
| } |
| @@ -730,20 +731,39 @@ bool FileManagerPrivateComputeChecksumFunction::RunAsync() { |
| storage::FileSystemURL file_url( |
| file_system_context->CrackURL(GURL(params->file_url))); |
| if (!file_url.is_valid()) { |
| - // TODO(kenobi): Call SetError() |
| + SetError("File URL was invalid"); |
| return false; |
| } |
| - BrowserThread::PostTaskAndReplyWithResult( |
| - BrowserThread::FILE, FROM_HERE, |
| - base::Bind(&drive::util::GetMd5Digest, file_url.path()), |
| - base::Bind(&FileManagerPrivateComputeChecksumFunction::Respond, this)); |
| + scoped_ptr<storage::FileStreamReader> reader = |
| + file_system_context->CreateFileStreamReader( |
| + file_url, 0, storage::kMaximumLength, base::Time()); |
| + |
| + scoped_refptr<drive::util::FileStreamMd5Digester> digester( |
|
mtomasz
2015/02/02 23:47:07
You don't need to make it a ref counter class. We
Ben Kwa
2015/02/03 06:28:54
So, you're suggesting making the FileStreamMd5Dige
mtomasz
2015/02/03 10:36:53
We use members for that, as the FileManagerPrivate
Ben Kwa
2015/02/03 16:32:19
OK, done.
|
| + new drive::util::FileStreamMd5Digester()); |
| + BrowserThread::PostTask( |
| + BrowserThread::IO, FROM_HERE, |
| + base::Bind(&drive::util::FileStreamMd5Digester::GetMd5Digest, digester, |
| + base::Passed(&reader), |
| + base::Bind(&FileManagerPrivateComputeChecksumFunction::Respond, |
| + this))); |
| return true; |
| } |
| void FileManagerPrivateComputeChecksumFunction::Respond( |
| const std::string& hash) { |
| + if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
|
mtomasz
2015/02/02 23:47:07
This is a little bit hacky. Each method should be
Ben Kwa
2015/02/03 06:28:54
I don't think I can use PostTaskAndReply, because
mtomasz
2015/02/03 10:36:53
You're right. I'd suggest to repost then in an ano
Ben Kwa
2015/02/03 16:32:19
Done.
|
| + // If not called from the UI thread, repost to the UI thread. The only |
| + // other thread that this should be getting called from is the IO thread. |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| + BrowserThread::PostTask( |
| + BrowserThread::UI, FROM_HERE, |
| + base::Bind(&FileManagerPrivateComputeChecksumFunction::Respond, this, |
| + hash)); |
| + return; |
| + } |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| SetResult(new base::StringValue(hash)); |
| SendResponse(true); |
| } |