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

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: Removed unused #include files, add TODO. 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>
8 #include <utility> 7 #include <utility>
9 8
10 #include "base/bind.h" 9 #include "base/bind.h"
11 #include "base/callback.h" 10 #include "base/callback.h"
12 #include "base/location.h"
13 #include "base/logging.h" 11 #include "base/logging.h"
14 #include "base/process/process_handle.h"
15 #include "base/single_thread_task_runner.h"
16 #include "base/threading/thread_task_runner_handle.h" 12 #include "base/threading/thread_task_runner_handle.h"
17 #include "chrome/common/chrome_utility_messages.h" 13 #include "base/time/time.h"
18 #include "chrome/common/extensions/chrome_utility_extensions_messages.h"
19 #include "chrome/grit/generated_resources.h" 14 #include "chrome/grit/generated_resources.h"
20 #include "content/public/browser/browser_thread.h" 15 #include "content/public/browser/browser_thread.h"
21 #include "content/public/browser/child_process_data.h"
22 #include "content/public/browser/utility_process_host.h" 16 #include "content/public/browser/utility_process_host.h"
23 #include "ipc/ipc_message_macros.h" 17 #include "services/service_manager/public/cpp/interface_provider.h"
24 #include "ipc/ipc_platform_file.h"
25 #include "ui/base/l10n/l10n_util.h" 18 #include "ui/base/l10n/l10n_util.h"
26 19
20 // TODO(noel): remove state_ once this code is all mojo.
27 SafeAudioVideoChecker::SafeAudioVideoChecker( 21 SafeAudioVideoChecker::SafeAudioVideoChecker(
28 base::File file, 22 base::File file,
29 const storage::CopyOrMoveFileValidator::ResultCallback& callback) 23 const storage::CopyOrMoveFileValidator::ResultCallback& callback)
30 : state_(INITIAL_STATE), file_(std::move(file)), callback_(callback) { 24 : state_(INITIAL_STATE), file_(std::move(file)), callback_(callback) {
31 DCHECK(!callback.is_null()); 25 DCHECK(!callback.is_null());
32 } 26 }
33 27
34 void SafeAudioVideoChecker::Start() { 28 void SafeAudioVideoChecker::Start() {
35 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 29 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
36 if (state_ != INITIAL_STATE) 30 if (state_ != INITIAL_STATE)
37 return; 31 return;
38 state_ = STARTED_STATE; 32 state_ = STARTED_STATE;
39 33
40 if (!file_.IsValid()) { 34 if (!file_.IsValid()) {
41 callback_.Run(base::File::FILE_ERROR_SECURITY); 35 callback_.Run(base::File::FILE_ERROR_SECURITY);
42 state_ = FINISHED_STATE; 36 state_ = FINISHED_STATE;
43 return; 37 return;
44 } 38 }
45 39
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( 40 utility_process_host_ = content::UtilityProcessHost::Create(
54 this, base::ThreadTaskRunnerHandle::Get())->AsWeakPtr(); 41 this, base::ThreadTaskRunnerHandle::Get())->AsWeakPtr();
55 utility_process_host_->SetName(l10n_util::GetStringUTF16( 42 utility_process_host_->SetName(l10n_util::GetStringUTF16(
56 IDS_UTILITY_PROCESS_MEDIA_FILE_CHECKER_NAME)); 43 IDS_UTILITY_PROCESS_MEDIA_FILE_CHECKER_NAME));
57 44
58 const int64_t kFileDecodeTimeInMS = 250; 45 utility_process_host_->Start();
59 utility_process_host_->Send(new ChromeUtilityMsg_CheckMediaFile( 46
60 kFileDecodeTimeInMS, file_for_transit)); 47 utility_process_host_->GetRemoteInterfaces()->GetInterface(&interface_);
48 interface_.set_connection_error_handler(
49 base::Bind(&SafeAudioVideoChecker::OnCheckingFinished, this, false));
50
51 constexpr base::TimeDelta kFileDecodeTime =
52 base::TimeDelta::FromMilliseconds(250);
53 interface_->CheckMediaFile(
54 kFileDecodeTime, std::move(file_),
55 base::Bind(&SafeAudioVideoChecker::OnCheckingFinished, this));
61 } 56 }
62 57
63 SafeAudioVideoChecker::~SafeAudioVideoChecker() {} 58 SafeAudioVideoChecker::~SafeAudioVideoChecker() {}
64 59
65 void SafeAudioVideoChecker::OnCheckingFinished(bool valid) { 60 void SafeAudioVideoChecker::OnCheckingFinished(bool valid) {
66 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 61 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
67 if (state_ != STARTED_STATE) 62 if (state_ != STARTED_STATE)
68 return; 63 return;
69 state_ = FINISHED_STATE; 64 state_ = FINISHED_STATE;
70 65
66 interface_.reset();
71 callback_.Run(valid ? base::File::FILE_OK : 67 callback_.Run(valid ? base::File::FILE_OK :
72 base::File::FILE_ERROR_SECURITY); 68 base::File::FILE_ERROR_SECURITY);
73 } 69 }
74 70
71 // TODO(noel): remove, use the utility process mojo host client.
75 void SafeAudioVideoChecker::OnProcessCrashed(int exit_code) { 72 void SafeAudioVideoChecker::OnProcessCrashed(int exit_code) {
76 OnCheckingFinished(false); 73 OnCheckingFinished(false);
77 } 74 }
78 75
76 // TODO(noel): remove, use the utility process mojo host client.
79 bool SafeAudioVideoChecker::OnMessageReceived(const IPC::Message& message) { 77 bool SafeAudioVideoChecker::OnMessageReceived(const IPC::Message& message) {
80 bool handled = true; 78 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 } 79 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698