| 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" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 base::File file, | 28 base::File file, |
| 29 const storage::CopyOrMoveFileValidator::ResultCallback& callback) | 29 const storage::CopyOrMoveFileValidator::ResultCallback& callback) |
| 30 : state_(INITIAL_STATE), file_(std::move(file)), callback_(callback) { | 30 : state_(INITIAL_STATE), file_(std::move(file)), callback_(callback) { |
| 31 DCHECK(!callback.is_null()); | 31 DCHECK(!callback.is_null()); |
| 32 } | 32 } |
| 33 | 33 |
| 34 void SafeAudioVideoChecker::Start() { | 34 void SafeAudioVideoChecker::Start() { |
| 35 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 35 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 36 if (state_ != INITIAL_STATE) | 36 if (state_ != INITIAL_STATE) |
| 37 return; | 37 return; |
| 38 state_ = PINGED_STATE; | 38 state_ = STARTED_STATE; |
| 39 | 39 |
| 40 if (!file_.IsValid()) { | 40 if (!file_.IsValid()) { |
| 41 callback_.Run(base::File::FILE_ERROR_SECURITY); | 41 callback_.Run(base::File::FILE_ERROR_SECURITY); |
| 42 state_ = FINISHED_STATE; | 42 state_ = FINISHED_STATE; |
| 43 return; | 43 return; |
| 44 } | 44 } |
| 45 | 45 |
| 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 |
| 46 utility_process_host_ = content::UtilityProcessHost::Create( | 53 utility_process_host_ = content::UtilityProcessHost::Create( |
| 47 this, base::ThreadTaskRunnerHandle::Get())->AsWeakPtr(); | 54 this, base::ThreadTaskRunnerHandle::Get())->AsWeakPtr(); |
| 48 utility_process_host_->SetName(l10n_util::GetStringUTF16( | 55 utility_process_host_->SetName(l10n_util::GetStringUTF16( |
| 49 IDS_UTILITY_PROCESS_MEDIA_FILE_CHECKER_NAME)); | 56 IDS_UTILITY_PROCESS_MEDIA_FILE_CHECKER_NAME)); |
| 50 utility_process_host_->Send(new ChromeUtilityMsg_StartupPing); | |
| 51 } | |
| 52 | 57 |
| 53 SafeAudioVideoChecker::~SafeAudioVideoChecker() {} | |
| 54 | |
| 55 void SafeAudioVideoChecker::OnProcessStarted() { | |
| 56 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | |
| 57 if (state_ != PINGED_STATE) | |
| 58 return; | |
| 59 state_ = STARTED_STATE; | |
| 60 | |
| 61 IPC::PlatformFileForTransit file_for_transit = | |
| 62 IPC::TakePlatformFileForTransit(std::move(file_)); | |
| 63 if (file_for_transit == IPC::InvalidPlatformFileForTransit()) { | |
| 64 OnCheckingFinished(false /* valid? */); | |
| 65 return; | |
| 66 } | |
| 67 const int64_t kFileDecodeTimeInMS = 250; | 58 const int64_t kFileDecodeTimeInMS = 250; |
| 68 utility_process_host_->Send(new ChromeUtilityMsg_CheckMediaFile( | 59 utility_process_host_->Send(new ChromeUtilityMsg_CheckMediaFile( |
| 69 kFileDecodeTimeInMS, file_for_transit)); | 60 kFileDecodeTimeInMS, file_for_transit)); |
| 70 } | 61 } |
| 71 | 62 |
| 63 SafeAudioVideoChecker::~SafeAudioVideoChecker() {} |
| 64 |
| 72 void SafeAudioVideoChecker::OnCheckingFinished(bool valid) { | 65 void SafeAudioVideoChecker::OnCheckingFinished(bool valid) { |
| 73 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 66 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 74 if (state_ != STARTED_STATE) | 67 if (state_ != STARTED_STATE) |
| 75 return; | 68 return; |
| 76 state_ = FINISHED_STATE; | 69 state_ = FINISHED_STATE; |
| 77 | 70 |
| 78 callback_.Run(valid ? base::File::FILE_OK : | 71 callback_.Run(valid ? base::File::FILE_OK : |
| 79 base::File::FILE_ERROR_SECURITY); | 72 base::File::FILE_ERROR_SECURITY); |
| 80 } | 73 } |
| 81 | 74 |
| 82 void SafeAudioVideoChecker::OnProcessCrashed(int exit_code) { | 75 void SafeAudioVideoChecker::OnProcessCrashed(int exit_code) { |
| 83 OnCheckingFinished(false); | 76 OnCheckingFinished(false); |
| 84 } | 77 } |
| 85 | 78 |
| 86 bool SafeAudioVideoChecker::OnMessageReceived(const IPC::Message& message) { | 79 bool SafeAudioVideoChecker::OnMessageReceived(const IPC::Message& message) { |
| 87 bool handled = true; | 80 bool handled = true; |
| 88 IPC_BEGIN_MESSAGE_MAP(SafeAudioVideoChecker, message) | 81 IPC_BEGIN_MESSAGE_MAP(SafeAudioVideoChecker, message) |
| 89 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_ProcessStarted, | |
| 90 OnProcessStarted) | |
| 91 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_CheckMediaFile_Finished, | 82 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_CheckMediaFile_Finished, |
| 92 OnCheckingFinished) | 83 OnCheckingFinished) |
| 93 IPC_MESSAGE_UNHANDLED(handled = false) | 84 IPC_MESSAGE_UNHANDLED(handled = false) |
| 94 IPC_END_MESSAGE_MAP() | 85 IPC_END_MESSAGE_MAP() |
| 95 return handled; | 86 return handled; |
| 96 } | 87 } |
| OLD | NEW |