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

Side by Side Diff: chrome/browser/media_galleries/fileapi/safe_audio_video_checker.cc

Issue 2751663002: Safe audio video checker: create mojo client with MakeUnique<> (Closed)
Patch Set: Created 3 years, 9 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 | « no previous file | 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/time/time.h" 11 #include "base/time/time.h"
12 #include "chrome/grit/generated_resources.h" 12 #include "chrome/grit/generated_resources.h"
13 #include "content/public/browser/browser_thread.h" 13 #include "content/public/browser/browser_thread.h"
14 #include "ui/base/l10n/l10n_util.h" 14 #include "ui/base/l10n/l10n_util.h"
15 15
16 SafeAudioVideoChecker::SafeAudioVideoChecker( 16 SafeAudioVideoChecker::SafeAudioVideoChecker(
17 base::File file, 17 base::File file,
18 const storage::CopyOrMoveFileValidator::ResultCallback& callback) 18 const storage::CopyOrMoveFileValidator::ResultCallback& callback)
19 : file_(std::move(file)), callback_(callback) { 19 : file_(std::move(file)), callback_(callback) {
20 DCHECK(!callback_.is_null()); 20 DCHECK(callback_);
21 } 21 }
22 22
23 void SafeAudioVideoChecker::Start() { 23 void SafeAudioVideoChecker::Start() {
24 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 24 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
25 25
26 if (!file_.IsValid()) { 26 if (!file_.IsValid()) {
27 callback_.Run(base::File::FILE_ERROR_SECURITY); 27 callback_.Run(base::File::FILE_ERROR_SECURITY);
28 return; 28 return;
29 } 29 }
30 30
31 DCHECK(!utility_process_mojo_client_); 31 DCHECK(!utility_process_mojo_client_);
32 32
33 const base::string16 utility_process_name = 33 utility_process_mojo_client_ = base::MakeUnique<
34 l10n_util::GetStringUTF16(IDS_UTILITY_PROCESS_MEDIA_FILE_CHECKER_NAME); 34 content::UtilityProcessMojoClient<extensions::mojom::MediaParser>>(
35 35 l10n_util::GetStringUTF16(IDS_UTILITY_PROCESS_MEDIA_FILE_CHECKER_NAME));
36 utility_process_mojo_client_.reset(
37 new content::UtilityProcessMojoClient<extensions::mojom::MediaParser>(
38 utility_process_name));
39 utility_process_mojo_client_->set_error_callback( 36 utility_process_mojo_client_->set_error_callback(
40 base::Bind(&SafeAudioVideoChecker::CheckMediaFileDone, this, false)); 37 base::Bind(&SafeAudioVideoChecker::CheckMediaFileDone, this, false));
41 38
42 utility_process_mojo_client_->Start(); // Start the utility process. 39 utility_process_mojo_client_->Start(); // Start the utility process.
43 40
44 constexpr auto kFileDecodeTime = base::TimeDelta::FromMilliseconds(250); 41 constexpr auto kFileDecodeTime = base::TimeDelta::FromMilliseconds(250);
45 42
46 utility_process_mojo_client_->service()->CheckMediaFile( 43 utility_process_mojo_client_->service()->CheckMediaFile(
47 kFileDecodeTime, std::move(file_), 44 kFileDecodeTime, std::move(file_),
48 base::Bind(&SafeAudioVideoChecker::CheckMediaFileDone, this)); 45 base::Bind(&SafeAudioVideoChecker::CheckMediaFileDone, this));
49 } 46 }
50 47
51 void SafeAudioVideoChecker::CheckMediaFileDone(bool valid) { 48 void SafeAudioVideoChecker::CheckMediaFileDone(bool valid) {
52 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 49 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
53 50
54 utility_process_mojo_client_.reset(); // Terminate the utility process. 51 utility_process_mojo_client_.reset(); // Terminate the utility process.
55 callback_.Run(valid ? base::File::FILE_OK : base::File::FILE_ERROR_SECURITY); 52 callback_.Run(valid ? base::File::FILE_OK : base::File::FILE_ERROR_SECURITY);
56 } 53 }
57 54
58 SafeAudioVideoChecker::~SafeAudioVideoChecker() = default; 55 SafeAudioVideoChecker::~SafeAudioVideoChecker() = default;
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698