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.
5 #ifndef CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_SAFE_AUDIO_VIDEO_CHECKER_H_
6 #define CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_SAFE_AUDIO_VIDEO_CHECKER_H_
8 #include "base/basictypes.h"
9 #include "base/callback_forward.h"
10 #include "base/files/file.h"
11 #include "base/memory/weak_ptr.h"
12 #include "content/public/browser/utility_process_host_client.h"
13 #include "storage/browser/fileapi/copy_or_move_file_validator.h"
16 class UtilityProcessHost;
19 // Uses a utility process to validate a media file. If the callback returns
20 // File::FILE_OK, then the file appears to be a valid media file. This does
21 // not attempt to decode the entire file, which may take a considerable amount
22 // of time. This class may be constructed on any thread, but should run on the
24 class SafeAudioVideoChecker : public content::UtilityProcessHostClient {
26 // Takes responsibility for closing |file|.
27 SafeAudioVideoChecker(
29 const storage::CopyOrMoveFileValidator::ResultCallback& callback);
31 // Must be called on the IO thread.
42 virtual ~SafeAudioVideoChecker();
44 // Starts validation once the utility process has been started.
45 virtual void OnProcessStarted();
47 // Notification of the result from the utility process.
48 void OnCheckingFinished(bool valid);
50 // UtilityProcessHostClient implementation.
51 virtual void OnProcessCrashed(int exit_code) OVERRIDE;
52 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
58 const storage::CopyOrMoveFileValidator::ResultCallback callback_;
60 base::WeakPtr<content::UtilityProcessHost> utility_process_host_;
62 DISALLOW_COPY_AND_ASSIGN(SafeAudioVideoChecker);
65 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_SAFE_AUDIO_VIDEO_CHECKER_H_