| 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> |
| 8 |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/callback.h" | 10 #include "base/callback.h" |
| 9 #include "base/location.h" | 11 #include "base/location.h" |
| 10 #include "base/logging.h" | 12 #include "base/logging.h" |
| 11 #include "base/process/process_handle.h" | 13 #include "base/process/process_handle.h" |
| 12 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
| 13 #include "base/thread_task_runner_handle.h" | 15 #include "base/thread_task_runner_handle.h" |
| 14 #include "chrome/common/chrome_utility_messages.h" | 16 #include "chrome/common/chrome_utility_messages.h" |
| 15 #include "chrome/common/extensions/chrome_utility_extensions_messages.h" | 17 #include "chrome/common/extensions/chrome_utility_extensions_messages.h" |
| 16 #include "chrome/grit/generated_resources.h" | 18 #include "chrome/grit/generated_resources.h" |
| 19 #include "content/public/browser/browser_thread.h" |
| 17 #include "content/public/browser/child_process_data.h" | 20 #include "content/public/browser/child_process_data.h" |
| 18 #include "content/public/browser/utility_process_host.h" | 21 #include "content/public/browser/utility_process_host.h" |
| 19 #include "content/public/browser/browser_thread.h" | |
| 20 #include "ipc/ipc_message_macros.h" | 22 #include "ipc/ipc_message_macros.h" |
| 21 #include "ipc/ipc_platform_file.h" | 23 #include "ipc/ipc_platform_file.h" |
| 22 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
| 23 | 25 |
| 24 SafeAudioVideoChecker::SafeAudioVideoChecker( | 26 SafeAudioVideoChecker::SafeAudioVideoChecker( |
| 25 base::File file, | 27 base::File file, |
| 26 const storage::CopyOrMoveFileValidator::ResultCallback& callback) | 28 const storage::CopyOrMoveFileValidator::ResultCallback& callback) |
| 27 : state_(INITIAL_STATE), file_(file.Pass()), callback_(callback) { | 29 : state_(INITIAL_STATE), file_(file.Pass()), callback_(callback) { |
| 28 DCHECK(!callback.is_null()); | 30 DCHECK(!callback.is_null()); |
| 29 } | 31 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 57 | 59 |
| 58 if (utility_process_host_->GetData().handle == base::kNullProcessHandle) | 60 if (utility_process_host_->GetData().handle == base::kNullProcessHandle) |
| 59 DLOG(ERROR) << "Child process handle is null"; | 61 DLOG(ERROR) << "Child process handle is null"; |
| 60 IPC::PlatformFileForTransit file_for_transit = | 62 IPC::PlatformFileForTransit file_for_transit = |
| 61 IPC::TakeFileHandleForProcess(file_.Pass(), | 63 IPC::TakeFileHandleForProcess(file_.Pass(), |
| 62 utility_process_host_->GetData().handle); | 64 utility_process_host_->GetData().handle); |
| 63 if (file_for_transit == IPC::InvalidPlatformFileForTransit()) { | 65 if (file_for_transit == IPC::InvalidPlatformFileForTransit()) { |
| 64 OnCheckingFinished(false /* valid? */); | 66 OnCheckingFinished(false /* valid? */); |
| 65 return; | 67 return; |
| 66 } | 68 } |
| 67 const int64 kFileDecodeTimeInMS = 250; | 69 const int64_t kFileDecodeTimeInMS = 250; |
| 68 utility_process_host_->Send(new ChromeUtilityMsg_CheckMediaFile( | 70 utility_process_host_->Send(new ChromeUtilityMsg_CheckMediaFile( |
| 69 kFileDecodeTimeInMS, file_for_transit)); | 71 kFileDecodeTimeInMS, file_for_transit)); |
| 70 } | 72 } |
| 71 | 73 |
| 72 void SafeAudioVideoChecker::OnCheckingFinished(bool valid) { | 74 void SafeAudioVideoChecker::OnCheckingFinished(bool valid) { |
| 73 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 75 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 74 if (state_ != STARTED_STATE) | 76 if (state_ != STARTED_STATE) |
| 75 return; | 77 return; |
| 76 state_ = FINISHED_STATE; | 78 state_ = FINISHED_STATE; |
| 77 | 79 |
| 78 callback_.Run(valid ? base::File::FILE_OK : | 80 callback_.Run(valid ? base::File::FILE_OK : |
| 79 base::File::FILE_ERROR_SECURITY); | 81 base::File::FILE_ERROR_SECURITY); |
| 80 } | 82 } |
| 81 | 83 |
| 82 void SafeAudioVideoChecker::OnProcessCrashed(int exit_code) { | 84 void SafeAudioVideoChecker::OnProcessCrashed(int exit_code) { |
| 83 OnCheckingFinished(false); | 85 OnCheckingFinished(false); |
| 84 } | 86 } |
| 85 | 87 |
| 86 bool SafeAudioVideoChecker::OnMessageReceived(const IPC::Message& message) { | 88 bool SafeAudioVideoChecker::OnMessageReceived(const IPC::Message& message) { |
| 87 bool handled = true; | 89 bool handled = true; |
| 88 IPC_BEGIN_MESSAGE_MAP(SafeAudioVideoChecker, message) | 90 IPC_BEGIN_MESSAGE_MAP(SafeAudioVideoChecker, message) |
| 89 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_ProcessStarted, | 91 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_ProcessStarted, |
| 90 OnProcessStarted) | 92 OnProcessStarted) |
| 91 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_CheckMediaFile_Finished, | 93 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_CheckMediaFile_Finished, |
| 92 OnCheckingFinished) | 94 OnCheckingFinished) |
| 93 IPC_MESSAGE_UNHANDLED(handled = false) | 95 IPC_MESSAGE_UNHANDLED(handled = false) |
| 94 IPC_END_MESSAGE_MAP() | 96 IPC_END_MESSAGE_MAP() |
| 95 return handled; | 97 return handled; |
| 96 } | 98 } |
| OLD | NEW |