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

Unified Diff: chrome/browser/chromeos/extensions/file_manager/private_api_file_system.cc

Issue 875513006: Files.app: Implement md5 hashing over file streams. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address feedback. Move I/O onto the IO thread. Created 5 years, 11 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
« no previous file with comments | « no previous file | chrome/browser/drive/drive_api_util.h » ('j') | chrome/browser/drive/drive_api_util.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
}
« no previous file with comments | « no previous file | chrome/browser/drive/drive_api_util.h » ('j') | chrome/browser/drive/drive_api_util.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698