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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/process/process_handle.h" | 11 #include "base/process/process_handle.h" |
12 #include "chrome/common/chrome_utility_messages.h" | 12 #include "chrome/common/chrome_utility_messages.h" |
13 #include "chrome/common/extensions/chrome_utility_extensions_messages.h" | 13 #include "chrome/common/extensions/chrome_utility_extensions_messages.h" |
| 14 #include "chrome/grit/generated_resources.h" |
14 #include "content/public/browser/child_process_data.h" | 15 #include "content/public/browser/child_process_data.h" |
15 #include "content/public/browser/utility_process_host.h" | 16 #include "content/public/browser/utility_process_host.h" |
16 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
17 #include "ipc/ipc_message_macros.h" | 18 #include "ipc/ipc_message_macros.h" |
18 #include "ipc/ipc_platform_file.h" | 19 #include "ipc/ipc_platform_file.h" |
| 20 #include "ui/base/l10n/l10n_util.h" |
19 | 21 |
20 SafeAudioVideoChecker::SafeAudioVideoChecker( | 22 SafeAudioVideoChecker::SafeAudioVideoChecker( |
21 base::File file, | 23 base::File file, |
22 const storage::CopyOrMoveFileValidator::ResultCallback& callback) | 24 const storage::CopyOrMoveFileValidator::ResultCallback& callback) |
23 : state_(INITIAL_STATE), file_(file.Pass()), callback_(callback) { | 25 : state_(INITIAL_STATE), file_(file.Pass()), callback_(callback) { |
24 DCHECK(!callback.is_null()); | 26 DCHECK(!callback.is_null()); |
25 } | 27 } |
26 | 28 |
27 void SafeAudioVideoChecker::Start() { | 29 void SafeAudioVideoChecker::Start() { |
28 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 30 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
29 if (state_ != INITIAL_STATE) | 31 if (state_ != INITIAL_STATE) |
30 return; | 32 return; |
31 state_ = PINGED_STATE; | 33 state_ = PINGED_STATE; |
32 | 34 |
33 if (!file_.IsValid()) { | 35 if (!file_.IsValid()) { |
34 callback_.Run(base::File::FILE_ERROR_SECURITY); | 36 callback_.Run(base::File::FILE_ERROR_SECURITY); |
35 state_ = FINISHED_STATE; | 37 state_ = FINISHED_STATE; |
36 return; | 38 return; |
37 } | 39 } |
38 | 40 |
39 utility_process_host_ = content::UtilityProcessHost::Create( | 41 utility_process_host_ = content::UtilityProcessHost::Create( |
40 this, base::MessageLoopProxy::current())->AsWeakPtr(); | 42 this, base::MessageLoopProxy::current())->AsWeakPtr(); |
| 43 utility_process_host_->SetName(l10n_util::GetStringUTF16( |
| 44 IDS_UTILITY_PROCESS_MEDIA_FILE_CHECKER_NAME)); |
41 utility_process_host_->Send(new ChromeUtilityMsg_StartupPing); | 45 utility_process_host_->Send(new ChromeUtilityMsg_StartupPing); |
42 } | 46 } |
43 | 47 |
44 SafeAudioVideoChecker::~SafeAudioVideoChecker() {} | 48 SafeAudioVideoChecker::~SafeAudioVideoChecker() {} |
45 | 49 |
46 void SafeAudioVideoChecker::OnProcessStarted() { | 50 void SafeAudioVideoChecker::OnProcessStarted() { |
47 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 51 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
48 if (state_ != PINGED_STATE) | 52 if (state_ != PINGED_STATE) |
49 return; | 53 return; |
50 state_ = STARTED_STATE; | 54 state_ = STARTED_STATE; |
(...skipping 30 matching lines...) Expand all Loading... |
81 bool handled = true; | 85 bool handled = true; |
82 IPC_BEGIN_MESSAGE_MAP(SafeAudioVideoChecker, message) | 86 IPC_BEGIN_MESSAGE_MAP(SafeAudioVideoChecker, message) |
83 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_ProcessStarted, | 87 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_ProcessStarted, |
84 OnProcessStarted) | 88 OnProcessStarted) |
85 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_CheckMediaFile_Finished, | 89 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_CheckMediaFile_Finished, |
86 OnCheckingFinished) | 90 OnCheckingFinished) |
87 IPC_MESSAGE_UNHANDLED(handled = false) | 91 IPC_MESSAGE_UNHANDLED(handled = false) |
88 IPC_END_MESSAGE_MAP() | 92 IPC_END_MESSAGE_MAP() |
89 return handled; | 93 return handled; |
90 } | 94 } |
OLD | NEW |