Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(99)

Side by Side Diff: chrome/browser/media_galleries/fileapi/safe_audio_video_checker.cc

Issue 20190002: Add a copy or move validator to that can handle support audio and video files. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix test file name Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/media_galleries/fileapi/safe_audio_video_checker.h"
6
7 #include "base/bind.h"
8 #include "base/callback.h"
9 #include "base/location.h"
10 #include "base/logging.h"
11 #include "base/process/process_handle.h"
12 #include "chrome/common/chrome_utility_messages.h"
13 #include "content/public/browser/child_process_data.h"
Lei Zhang 2013/08/08 00:08:02 not needed?
vandebo (ex-Chrome) 2013/08/08 17:34:01 It is, used on line 59 on this patch set and conte
14 #include "content/public/browser/utility_process_host.h"
15 #include "content/public/browser/browser_thread.h"
16 #include "ipc/ipc_message_macros.h"
17 #include "ipc/ipc_platform_file.h"
18
19 SafeAudioVideoChecker::SafeAudioVideoChecker(
20 const base::PlatformFile& file,
21 const fileapi::CopyOrMoveFileValidator::ResultCallback& callback)
22 : state_(INITIAL_STATE),
23 file_(file),
24 file_closer_(&file_),
25 callback_(callback) {
26 DCHECK(!callback.is_null());
27 }
28
29 void SafeAudioVideoChecker::Start() {
30 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
31 if (state_ != INITIAL_STATE)
32 return;
33 state_ = PINGED_STATE;
34
35 if (*file_closer_ && *file_closer_.get() == base::kInvalidPlatformFileValue) {
Lei Zhang 2013/08/08 00:08:02 *file_closer_ can't be NULL
vandebo (ex-Chrome) 2013/08/08 17:34:01 It can be... *file_closer_ <=> file_closer_.get(),
Lei Zhang 2013/08/08 18:18:07 But nobody calls file_closer_.reset() except the d
vandebo (ex-Chrome) 2013/08/08 23:14:11 SafeAudioVideoChecker::OnProcessStarted() calls fi
Lei Zhang 2013/08/08 23:16:21 After that, the |state_| check makes sure we'll ne
vandebo (ex-Chrome) 2013/08/08 23:18:24 In the current version of the code, yes.
Lei Zhang 2013/08/09 01:01:33 Then remove the check? Adjust accordingly if the c
vandebo (ex-Chrome) 2013/08/09 04:11:09 I'd rather leave it in. It doesn't cost much, is
36 callback_.Run(base::PLATFORM_FILE_ERROR_SECURITY);
37 state_ = FINISHED_STATE;
38 return;
39 }
40
41 utility_process_host_ = content::UtilityProcessHost::Create(
42 this, base::MessageLoopProxy::current())->AsWeakPtr();
43 utility_process_host_->EnableZygote();
44 utility_process_host_->Send(new ChromeUtilityMsg_StartupPing);
45 }
46
47 SafeAudioVideoChecker::~SafeAudioVideoChecker() {}
48
49 void SafeAudioVideoChecker::OnProcessStarted() {
50 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
51 if (state_ != PINGED_STATE)
52 return;
53 state_ = STARTED_STATE;
54
55 if (utility_process_host_->GetData().handle == base::kNullProcessHandle)
56 DLOG(ERROR) << "Child process handle is null";
57 IPC::PlatformFileForTransit file_for_transit =
58 IPC::GetFileHandleForProcess(*file_closer_.release(),
59 utility_process_host_->GetData().handle,
60 true /* close_source_handle */);
61 const int64 kFileDecodeTimeInMS = 250;
62 utility_process_host_->Send(new ChromeUtilityMsg_CheckMediaFile(
63 kFileDecodeTimeInMS, file_for_transit));
64 }
65
66 void SafeAudioVideoChecker::OnCheckingFinished(bool valid) {
67 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
68 if (state_ != STARTED_STATE)
69 return;
70 state_ = FINISHED_STATE;
71
72 callback_.Run(valid ? base::PLATFORM_FILE_OK
73 : base::PLATFORM_FILE_ERROR_SECURITY);
74 }
75
76 void SafeAudioVideoChecker::OnProcessCrashed(int exit_code) {
77 OnCheckingFinished(false);
78 }
79
80 bool SafeAudioVideoChecker::OnMessageReceived(const IPC::Message& message) {
81 bool handled = true;
82 IPC_BEGIN_MESSAGE_MAP(SafeAudioVideoChecker, message)
83 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_ProcessStarted,
84 OnProcessStarted)
85 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_CheckMediaFile_Finished,
86 OnCheckingFinished)
87 IPC_MESSAGE_UNHANDLED(handled = false)
88 IPC_END_MESSAGE_MAP()
89 return handled;
90 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698