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

Unified Diff: chrome/browser/media_galleries/fileapi/safe_audio_video_checker.cc

Issue 2644313002: SafeAudioVideoChecker: use UtilityProcessMojoClient (Closed)
Patch Set: Comments and other minor clean-up. Created 3 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 | « chrome/browser/media_galleries/fileapi/safe_audio_video_checker.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/media_galleries/fileapi/safe_audio_video_checker.cc
diff --git a/chrome/browser/media_galleries/fileapi/safe_audio_video_checker.cc b/chrome/browser/media_galleries/fileapi/safe_audio_video_checker.cc
index f13242b160a4d275ec34c42d56f18135c56279cc..f6bd328674f2a7ed27514dc01d1ad99b329e096a 100644
--- a/chrome/browser/media_galleries/fileapi/safe_audio_video_checker.cc
+++ b/chrome/browser/media_galleries/fileapi/safe_audio_video_checker.cc
@@ -8,72 +8,51 @@
#include "base/bind.h"
#include "base/callback.h"
-#include "base/logging.h"
-#include "base/threading/thread_task_runner_handle.h"
#include "base/time/time.h"
#include "chrome/grit/generated_resources.h"
#include "content/public/browser/browser_thread.h"
-#include "content/public/browser/utility_process_host.h"
-#include "services/service_manager/public/cpp/interface_provider.h"
#include "ui/base/l10n/l10n_util.h"
-// TODO(noel): remove state_ once this code is all mojo.
SafeAudioVideoChecker::SafeAudioVideoChecker(
base::File file,
const storage::CopyOrMoveFileValidator::ResultCallback& callback)
- : state_(INITIAL_STATE), file_(std::move(file)), callback_(callback) {
- DCHECK(!callback.is_null());
+ : file_(std::move(file)), callback_(callback) {
+ DCHECK(!callback_.is_null());
}
void SafeAudioVideoChecker::Start() {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
- if (state_ != INITIAL_STATE)
- return;
- state_ = STARTED_STATE;
if (!file_.IsValid()) {
callback_.Run(base::File::FILE_ERROR_SECURITY);
- state_ = FINISHED_STATE;
return;
}
- utility_process_host_ = content::UtilityProcessHost::Create(
- this, base::ThreadTaskRunnerHandle::Get())->AsWeakPtr();
- utility_process_host_->SetName(l10n_util::GetStringUTF16(
- IDS_UTILITY_PROCESS_MEDIA_FILE_CHECKER_NAME));
+ DCHECK(!utility_process_mojo_client_);
+
+ const base::string16 utility_process_name =
+ l10n_util::GetStringUTF16(IDS_UTILITY_PROCESS_MEDIA_FILE_CHECKER_NAME);
- utility_process_host_->Start();
+ utility_process_mojo_client_.reset(
Lei Zhang 2017/03/11 00:44:19 nit for future CLs in general: foo_unique_ptr.rese
+ new content::UtilityProcessMojoClient<extensions::mojom::MediaParser>(
+ utility_process_name));
+ utility_process_mojo_client_->set_error_callback(
+ base::Bind(&SafeAudioVideoChecker::CheckMediaFileDone, this, false));
- utility_process_host_->GetRemoteInterfaces()->GetInterface(&interface_);
- interface_.set_connection_error_handler(
- base::Bind(&SafeAudioVideoChecker::OnCheckingFinished, this, false));
+ utility_process_mojo_client_->Start(); // Start the utility process.
- constexpr base::TimeDelta kFileDecodeTime =
- base::TimeDelta::FromMilliseconds(250);
- interface_->CheckMediaFile(
+ constexpr auto kFileDecodeTime = base::TimeDelta::FromMilliseconds(250);
+
+ utility_process_mojo_client_->service()->CheckMediaFile(
kFileDecodeTime, std::move(file_),
- base::Bind(&SafeAudioVideoChecker::OnCheckingFinished, this));
+ base::Bind(&SafeAudioVideoChecker::CheckMediaFileDone, this));
}
-SafeAudioVideoChecker::~SafeAudioVideoChecker() {}
-
-void SafeAudioVideoChecker::OnCheckingFinished(bool valid) {
+void SafeAudioVideoChecker::CheckMediaFileDone(bool valid) {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
- if (state_ != STARTED_STATE)
- return;
- state_ = FINISHED_STATE;
-
- interface_.reset();
- callback_.Run(valid ? base::File::FILE_OK :
- base::File::FILE_ERROR_SECURITY);
-}
-// TODO(noel): remove, use the utility process mojo host client.
-void SafeAudioVideoChecker::OnProcessCrashed(int exit_code) {
- OnCheckingFinished(false);
+ utility_process_mojo_client_.reset(); // Terminate the utility process.
+ callback_.Run(valid ? base::File::FILE_OK : base::File::FILE_ERROR_SECURITY);
}
-// TODO(noel): remove, use the utility process mojo host client.
-bool SafeAudioVideoChecker::OnMessageReceived(const IPC::Message& message) {
- return false;
-}
+SafeAudioVideoChecker::~SafeAudioVideoChecker() = default;
« no previous file with comments | « chrome/browser/media_galleries/fileapi/safe_audio_video_checker.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698