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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/media_galleries/fileapi/safe_audio_video_checker.h" 5 #include "chrome/browser/media_galleries/fileapi/safe_audio_video_checker.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/logging.h"
12 #include "base/threading/thread_task_runner_handle.h"
13 #include "base/time/time.h" 11 #include "base/time/time.h"
14 #include "chrome/grit/generated_resources.h" 12 #include "chrome/grit/generated_resources.h"
15 #include "content/public/browser/browser_thread.h" 13 #include "content/public/browser/browser_thread.h"
16 #include "content/public/browser/utility_process_host.h"
17 #include "services/service_manager/public/cpp/interface_provider.h"
18 #include "ui/base/l10n/l10n_util.h" 14 #include "ui/base/l10n/l10n_util.h"
19 15
20 // TODO(noel): remove state_ once this code is all mojo.
21 SafeAudioVideoChecker::SafeAudioVideoChecker( 16 SafeAudioVideoChecker::SafeAudioVideoChecker(
22 base::File file, 17 base::File file,
23 const storage::CopyOrMoveFileValidator::ResultCallback& callback) 18 const storage::CopyOrMoveFileValidator::ResultCallback& callback)
24 : state_(INITIAL_STATE), file_(std::move(file)), callback_(callback) { 19 : file_(std::move(file)), callback_(callback) {
25 DCHECK(!callback.is_null()); 20 DCHECK(!callback_.is_null());
26 } 21 }
27 22
28 void SafeAudioVideoChecker::Start() { 23 void SafeAudioVideoChecker::Start() {
29 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 24 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
30 if (state_ != INITIAL_STATE)
31 return;
32 state_ = STARTED_STATE;
33 25
34 if (!file_.IsValid()) { 26 if (!file_.IsValid()) {
35 callback_.Run(base::File::FILE_ERROR_SECURITY); 27 callback_.Run(base::File::FILE_ERROR_SECURITY);
36 state_ = FINISHED_STATE;
37 return; 28 return;
38 } 29 }
39 30
40 utility_process_host_ = content::UtilityProcessHost::Create( 31 DCHECK(!utility_process_mojo_client_);
41 this, base::ThreadTaskRunnerHandle::Get())->AsWeakPtr();
42 utility_process_host_->SetName(l10n_util::GetStringUTF16(
43 IDS_UTILITY_PROCESS_MEDIA_FILE_CHECKER_NAME));
44 32
45 utility_process_host_->Start(); 33 const base::string16 utility_process_name =
34 l10n_util::GetStringUTF16(IDS_UTILITY_PROCESS_MEDIA_FILE_CHECKER_NAME);
46 35
47 utility_process_host_->GetRemoteInterfaces()->GetInterface(&interface_); 36 utility_process_mojo_client_.reset(
Lei Zhang 2017/03/11 00:44:19 nit for future CLs in general: foo_unique_ptr.rese
48 interface_.set_connection_error_handler( 37 new content::UtilityProcessMojoClient<extensions::mojom::MediaParser>(
49 base::Bind(&SafeAudioVideoChecker::OnCheckingFinished, this, false)); 38 utility_process_name));
39 utility_process_mojo_client_->set_error_callback(
40 base::Bind(&SafeAudioVideoChecker::CheckMediaFileDone, this, false));
50 41
51 constexpr base::TimeDelta kFileDecodeTime = 42 utility_process_mojo_client_->Start(); // Start the utility process.
52 base::TimeDelta::FromMilliseconds(250); 43
53 interface_->CheckMediaFile( 44 constexpr auto kFileDecodeTime = base::TimeDelta::FromMilliseconds(250);
45
46 utility_process_mojo_client_->service()->CheckMediaFile(
54 kFileDecodeTime, std::move(file_), 47 kFileDecodeTime, std::move(file_),
55 base::Bind(&SafeAudioVideoChecker::OnCheckingFinished, this)); 48 base::Bind(&SafeAudioVideoChecker::CheckMediaFileDone, this));
56 } 49 }
57 50
58 SafeAudioVideoChecker::~SafeAudioVideoChecker() {} 51 void SafeAudioVideoChecker::CheckMediaFileDone(bool valid) {
52 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
59 53
60 void SafeAudioVideoChecker::OnCheckingFinished(bool valid) { 54 utility_process_mojo_client_.reset(); // Terminate the utility process.
61 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 55 callback_.Run(valid ? base::File::FILE_OK : base::File::FILE_ERROR_SECURITY);
62 if (state_ != STARTED_STATE)
63 return;
64 state_ = FINISHED_STATE;
65
66 interface_.reset();
67 callback_.Run(valid ? base::File::FILE_OK :
68 base::File::FILE_ERROR_SECURITY);
69 } 56 }
70 57
71 // TODO(noel): remove, use the utility process mojo host client. 58 SafeAudioVideoChecker::~SafeAudioVideoChecker() = default;
72 void SafeAudioVideoChecker::OnProcessCrashed(int exit_code) {
73 OnCheckingFinished(false);
74 }
75
76 // TODO(noel): remove, use the utility process mojo host client.
77 bool SafeAudioVideoChecker::OnMessageReceived(const IPC::Message& message) {
78 return false;
79 }
OLDNEW
« 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