Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "base/time/time.h" | |
| 17 #include "chrome/common/chrome_utility_messages.h" | 18 #include "chrome/common/chrome_utility_messages.h" |
| 18 #include "chrome/common/extensions/chrome_utility_extensions_messages.h" | 19 #include "chrome/common/extensions/chrome_utility_extensions_messages.h" |
| 19 #include "chrome/grit/generated_resources.h" | 20 #include "chrome/grit/generated_resources.h" |
| 20 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
| 21 #include "content/public/browser/child_process_data.h" | 22 #include "content/public/browser/child_process_data.h" |
| 22 #include "content/public/browser/utility_process_host.h" | 23 #include "content/public/browser/utility_process_host.h" |
| 23 #include "ipc/ipc_message_macros.h" | 24 #include "ipc/ipc_message_macros.h" |
| 24 #include "ipc/ipc_platform_file.h" | 25 #include "ipc/ipc_platform_file.h" |
|
Noel Gordon
2017/01/20 00:50:23
We should probably clean up here: let me removed t
| |
| 26 #include "services/service_manager/public/cpp/interface_provider.h" | |
| 25 #include "ui/base/l10n/l10n_util.h" | 27 #include "ui/base/l10n/l10n_util.h" |
| 26 | 28 |
| 27 SafeAudioVideoChecker::SafeAudioVideoChecker( | 29 SafeAudioVideoChecker::SafeAudioVideoChecker( |
| 28 base::File file, | 30 base::File file, |
| 29 const storage::CopyOrMoveFileValidator::ResultCallback& callback) | 31 const storage::CopyOrMoveFileValidator::ResultCallback& callback) |
| 30 : state_(INITIAL_STATE), file_(std::move(file)), callback_(callback) { | 32 : state_(INITIAL_STATE), file_(std::move(file)), callback_(callback) { |
| 31 DCHECK(!callback.is_null()); | 33 DCHECK(!callback.is_null()); |
| 32 } | 34 } |
| 33 | 35 |
| 34 void SafeAudioVideoChecker::Start() { | 36 void SafeAudioVideoChecker::Start() { |
| 35 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 37 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 36 if (state_ != INITIAL_STATE) | 38 if (state_ != INITIAL_STATE) |
| 37 return; | 39 return; |
| 38 state_ = STARTED_STATE; | 40 state_ = STARTED_STATE; |
| 39 | 41 |
| 40 if (!file_.IsValid()) { | 42 if (!file_.IsValid()) { |
| 41 callback_.Run(base::File::FILE_ERROR_SECURITY); | 43 callback_.Run(base::File::FILE_ERROR_SECURITY); |
| 42 state_ = FINISHED_STATE; | 44 state_ = FINISHED_STATE; |
| 43 return; | 45 return; |
| 44 } | 46 } |
| 45 | 47 |
| 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( | 48 utility_process_host_ = content::UtilityProcessHost::Create( |
| 54 this, base::ThreadTaskRunnerHandle::Get())->AsWeakPtr(); | 49 this, base::ThreadTaskRunnerHandle::Get())->AsWeakPtr(); |
| 55 utility_process_host_->SetName(l10n_util::GetStringUTF16( | 50 utility_process_host_->SetName(l10n_util::GetStringUTF16( |
| 56 IDS_UTILITY_PROCESS_MEDIA_FILE_CHECKER_NAME)); | 51 IDS_UTILITY_PROCESS_MEDIA_FILE_CHECKER_NAME)); |
| 57 | 52 |
| 58 const int64_t kFileDecodeTimeInMS = 250; | 53 utility_process_host_->Start(); |
| 59 utility_process_host_->Send(new ChromeUtilityMsg_CheckMediaFile( | 54 |
| 60 kFileDecodeTimeInMS, file_for_transit)); | 55 utility_process_host_->GetRemoteInterfaces()->GetInterface(&interface_); |
| 56 interface_.set_connection_error_handler( | |
| 57 base::Bind(&SafeAudioVideoChecker::OnCheckingFinished, this, false)); | |
| 58 | |
| 59 constexpr base::TimeDelta kFileDecodeTime = | |
| 60 base::TimeDelta::FromMilliseconds(250); | |
| 61 interface_->CheckMediaFile( | |
| 62 kFileDecodeTime, std::move(file_), | |
| 63 base::Bind(&SafeAudioVideoChecker::OnCheckingFinished, this)); | |
| 61 } | 64 } |
| 62 | 65 |
| 63 SafeAudioVideoChecker::~SafeAudioVideoChecker() {} | 66 SafeAudioVideoChecker::~SafeAudioVideoChecker() {} |
| 64 | 67 |
| 65 void SafeAudioVideoChecker::OnCheckingFinished(bool valid) { | 68 void SafeAudioVideoChecker::OnCheckingFinished(bool valid) { |
| 66 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 69 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 67 if (state_ != STARTED_STATE) | 70 if (state_ != STARTED_STATE) |
| 68 return; | 71 return; |
| 69 state_ = FINISHED_STATE; | 72 state_ = FINISHED_STATE; |
| 70 | 73 |
| 74 interface_.reset(); | |
| 71 callback_.Run(valid ? base::File::FILE_OK : | 75 callback_.Run(valid ? base::File::FILE_OK : |
| 72 base::File::FILE_ERROR_SECURITY); | 76 base::File::FILE_ERROR_SECURITY); |
| 73 } | 77 } |
| 74 | 78 |
| 75 void SafeAudioVideoChecker::OnProcessCrashed(int exit_code) { | 79 void SafeAudioVideoChecker::OnProcessCrashed(int exit_code) { |
| 76 OnCheckingFinished(false); | 80 OnCheckingFinished(false); |
| 77 } | 81 } |
| 78 | 82 |
| 79 bool SafeAudioVideoChecker::OnMessageReceived(const IPC::Message& message) { | 83 bool SafeAudioVideoChecker::OnMessageReceived(const IPC::Message& message) { |
| 80 bool handled = true; | 84 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 } | 85 } |
| OLD | NEW |