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

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

Issue 2639503002: Convert utility process CheckMediaFile IPC to mojo (Closed)
Patch Set: Build fix: IPC::Send is now used on #ifdef WIN and OSX only. 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
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 <stdint.h> 7 #include <stdint.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/location.h" 12 #include "base/location.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/process/process_handle.h" 14 #include "base/process/process_handle.h"
15 #include "base/single_thread_task_runner.h" 15 #include "base/single_thread_task_runner.h"
16 #include "base/threading/thread_task_runner_handle.h" 16 #include "base/threading/thread_task_runner_handle.h"
17 #include "chrome/common/chrome_utility_messages.h" 17 #include "chrome/common/chrome_utility_messages.h"
18 #include "chrome/common/extensions/chrome_utility_extensions_messages.h" 18 #include "chrome/common/extensions/chrome_utility_extensions_messages.h"
19 #include "chrome/grit/generated_resources.h" 19 #include "chrome/grit/generated_resources.h"
20 #include "content/public/browser/browser_thread.h" 20 #include "content/public/browser/browser_thread.h"
21 #include "content/public/browser/child_process_data.h" 21 #include "content/public/browser/child_process_data.h"
22 #include "content/public/browser/utility_process_host.h" 22 #include "content/public/browser/utility_process_host.h"
23 #include "ipc/ipc_message_macros.h" 23 #include "ipc/ipc_message_macros.h"
24 #include "ipc/ipc_platform_file.h" 24 #include "ipc/ipc_platform_file.h"
25 #include "services/service_manager/public/cpp/interface_provider.h"
25 #include "ui/base/l10n/l10n_util.h" 26 #include "ui/base/l10n/l10n_util.h"
26 27
27 SafeAudioVideoChecker::SafeAudioVideoChecker( 28 SafeAudioVideoChecker::SafeAudioVideoChecker(
28 base::File file, 29 base::File file,
29 const storage::CopyOrMoveFileValidator::ResultCallback& callback) 30 const storage::CopyOrMoveFileValidator::ResultCallback& callback)
30 : state_(INITIAL_STATE), file_(std::move(file)), callback_(callback) { 31 : state_(INITIAL_STATE), file_(std::move(file)), callback_(callback) {
31 DCHECK(!callback.is_null()); 32 DCHECK(!callback.is_null());
32 } 33 }
33 34
34 void SafeAudioVideoChecker::Start() { 35 void SafeAudioVideoChecker::Start() {
35 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 36 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
36 if (state_ != INITIAL_STATE) 37 if (state_ != INITIAL_STATE)
37 return; 38 return;
38 state_ = STARTED_STATE; 39 state_ = STARTED_STATE;
39 40
40 if (!file_.IsValid()) { 41 if (!file_.IsValid()) {
41 callback_.Run(base::File::FILE_ERROR_SECURITY); 42 callback_.Run(base::File::FILE_ERROR_SECURITY);
42 state_ = FINISHED_STATE; 43 state_ = FINISHED_STATE;
43 return; 44 return;
44 } 45 }
45 46
46 IPC::PlatformFileForTransit file_for_transit =
47 IPC::TakePlatformFileForTransit(std::move(file_));
48 if (file_for_transit == IPC::InvalidPlatformFileForTransit()) {
49 OnCheckingFinished(false /* valid? */);
50 return;
51 }
52
53 utility_process_host_ = content::UtilityProcessHost::Create( 47 utility_process_host_ = content::UtilityProcessHost::Create(
54 this, base::ThreadTaskRunnerHandle::Get())->AsWeakPtr(); 48 this, base::ThreadTaskRunnerHandle::Get())->AsWeakPtr();
55 utility_process_host_->SetName(l10n_util::GetStringUTF16( 49 utility_process_host_->SetName(l10n_util::GetStringUTF16(
56 IDS_UTILITY_PROCESS_MEDIA_FILE_CHECKER_NAME)); 50 IDS_UTILITY_PROCESS_MEDIA_FILE_CHECKER_NAME));
57 51
52 utility_process_host_->Start();
53
54 utility_process_host_->GetRemoteInterfaces()->GetInterface(&interface_);
55 interface_.set_connection_error_handler(
56 base::Bind(&SafeAudioVideoChecker::OnCheckingFinished, this, false));
57
58 const int64_t kFileDecodeTimeInMS = 250; 58 const int64_t kFileDecodeTimeInMS = 250;
Sam McNally 2017/01/18 07:09:09 constexpr base::TimeDelta kFileDecodeTime = base::
Noel Gordon 2017/01/19 06:33:11 That worked well. Done.
59 utility_process_host_->Send(new ChromeUtilityMsg_CheckMediaFile( 59 interface_->CheckMediaFile(
60 kFileDecodeTimeInMS, file_for_transit)); 60 kFileDecodeTimeInMS, std::move(file_),
61 base::Bind(&SafeAudioVideoChecker::OnCheckingFinished, this));
61 } 62 }
62 63
63 SafeAudioVideoChecker::~SafeAudioVideoChecker() {} 64 SafeAudioVideoChecker::~SafeAudioVideoChecker() {}
64 65
65 void SafeAudioVideoChecker::OnCheckingFinished(bool valid) { 66 void SafeAudioVideoChecker::OnCheckingFinished(bool valid) {
66 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 67 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
67 if (state_ != STARTED_STATE) 68 if (state_ != STARTED_STATE)
68 return; 69 return;
69 state_ = FINISHED_STATE; 70 state_ = FINISHED_STATE;
70 71
72 interface_.reset();
71 callback_.Run(valid ? base::File::FILE_OK : 73 callback_.Run(valid ? base::File::FILE_OK :
72 base::File::FILE_ERROR_SECURITY); 74 base::File::FILE_ERROR_SECURITY);
73 } 75 }
74 76
75 void SafeAudioVideoChecker::OnProcessCrashed(int exit_code) { 77 void SafeAudioVideoChecker::OnProcessCrashed(int exit_code) {
76 OnCheckingFinished(false); 78 OnCheckingFinished(false);
77 } 79 }
78 80
79 bool SafeAudioVideoChecker::OnMessageReceived(const IPC::Message& message) { 81 bool SafeAudioVideoChecker::OnMessageReceived(const IPC::Message& message) {
80 bool handled = true; 82 return false;
81 IPC_BEGIN_MESSAGE_MAP(SafeAudioVideoChecker, message)
82 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_CheckMediaFile_Finished,
83 OnCheckingFinished)
84 IPC_MESSAGE_UNHANDLED(handled = false)
85 IPC_END_MESSAGE_MAP()
86 return handled;
87 } 83 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698