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 | 9 |
9 #include "base/bind.h" | 10 #include "base/bind.h" |
10 #include "base/callback.h" | 11 #include "base/callback.h" |
11 #include "base/location.h" | 12 #include "base/location.h" |
12 #include "base/logging.h" | 13 #include "base/logging.h" |
13 #include "base/process/process_handle.h" | 14 #include "base/process/process_handle.h" |
14 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
15 #include "base/thread_task_runner_handle.h" | 16 #include "base/thread_task_runner_handle.h" |
16 #include "chrome/common/chrome_utility_messages.h" | 17 #include "chrome/common/chrome_utility_messages.h" |
17 #include "chrome/common/extensions/chrome_utility_extensions_messages.h" | 18 #include "chrome/common/extensions/chrome_utility_extensions_messages.h" |
18 #include "chrome/grit/generated_resources.h" | 19 #include "chrome/grit/generated_resources.h" |
19 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
20 #include "content/public/browser/child_process_data.h" | 21 #include "content/public/browser/child_process_data.h" |
21 #include "content/public/browser/utility_process_host.h" | 22 #include "content/public/browser/utility_process_host.h" |
22 #include "ipc/ipc_message_macros.h" | 23 #include "ipc/ipc_message_macros.h" |
23 #include "ipc/ipc_platform_file.h" | 24 #include "ipc/ipc_platform_file.h" |
24 #include "ui/base/l10n/l10n_util.h" | 25 #include "ui/base/l10n/l10n_util.h" |
25 | 26 |
26 SafeAudioVideoChecker::SafeAudioVideoChecker( | 27 SafeAudioVideoChecker::SafeAudioVideoChecker( |
27 base::File file, | 28 base::File file, |
28 const storage::CopyOrMoveFileValidator::ResultCallback& callback) | 29 const storage::CopyOrMoveFileValidator::ResultCallback& callback) |
29 : state_(INITIAL_STATE), file_(file.Pass()), callback_(callback) { | 30 : state_(INITIAL_STATE), file_(std::move(file)), callback_(callback) { |
30 DCHECK(!callback.is_null()); | 31 DCHECK(!callback.is_null()); |
31 } | 32 } |
32 | 33 |
33 void SafeAudioVideoChecker::Start() { | 34 void SafeAudioVideoChecker::Start() { |
34 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 35 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
35 if (state_ != INITIAL_STATE) | 36 if (state_ != INITIAL_STATE) |
36 return; | 37 return; |
37 state_ = PINGED_STATE; | 38 state_ = PINGED_STATE; |
38 | 39 |
39 if (!file_.IsValid()) { | 40 if (!file_.IsValid()) { |
(...skipping 12 matching lines...) Expand all Loading... |
52 SafeAudioVideoChecker::~SafeAudioVideoChecker() {} | 53 SafeAudioVideoChecker::~SafeAudioVideoChecker() {} |
53 | 54 |
54 void SafeAudioVideoChecker::OnProcessStarted() { | 55 void SafeAudioVideoChecker::OnProcessStarted() { |
55 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 56 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
56 if (state_ != PINGED_STATE) | 57 if (state_ != PINGED_STATE) |
57 return; | 58 return; |
58 state_ = STARTED_STATE; | 59 state_ = STARTED_STATE; |
59 | 60 |
60 if (utility_process_host_->GetData().handle == base::kNullProcessHandle) | 61 if (utility_process_host_->GetData().handle == base::kNullProcessHandle) |
61 DLOG(ERROR) << "Child process handle is null"; | 62 DLOG(ERROR) << "Child process handle is null"; |
62 IPC::PlatformFileForTransit file_for_transit = | 63 IPC::PlatformFileForTransit file_for_transit = IPC::TakeFileHandleForProcess( |
63 IPC::TakeFileHandleForProcess(file_.Pass(), | 64 std::move(file_), utility_process_host_->GetData().handle); |
64 utility_process_host_->GetData().handle); | |
65 if (file_for_transit == IPC::InvalidPlatformFileForTransit()) { | 65 if (file_for_transit == IPC::InvalidPlatformFileForTransit()) { |
66 OnCheckingFinished(false /* valid? */); | 66 OnCheckingFinished(false /* valid? */); |
67 return; | 67 return; |
68 } | 68 } |
69 const int64_t kFileDecodeTimeInMS = 250; | 69 const int64_t kFileDecodeTimeInMS = 250; |
70 utility_process_host_->Send(new ChromeUtilityMsg_CheckMediaFile( | 70 utility_process_host_->Send(new ChromeUtilityMsg_CheckMediaFile( |
71 kFileDecodeTimeInMS, file_for_transit)); | 71 kFileDecodeTimeInMS, file_for_transit)); |
72 } | 72 } |
73 | 73 |
74 void SafeAudioVideoChecker::OnCheckingFinished(bool valid) { | 74 void SafeAudioVideoChecker::OnCheckingFinished(bool valid) { |
(...skipping 14 matching lines...) Expand all Loading... |
89 bool handled = true; | 89 bool handled = true; |
90 IPC_BEGIN_MESSAGE_MAP(SafeAudioVideoChecker, message) | 90 IPC_BEGIN_MESSAGE_MAP(SafeAudioVideoChecker, message) |
91 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_ProcessStarted, | 91 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_ProcessStarted, |
92 OnProcessStarted) | 92 OnProcessStarted) |
93 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_CheckMediaFile_Finished, | 93 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_CheckMediaFile_Finished, |
94 OnCheckingFinished) | 94 OnCheckingFinished) |
95 IPC_MESSAGE_UNHANDLED(handled = false) | 95 IPC_MESSAGE_UNHANDLED(handled = false) |
96 IPC_END_MESSAGE_MAP() | 96 IPC_END_MESSAGE_MAP() |
97 return handled; | 97 return handled; |
98 } | 98 } |
OLD | NEW |