OLD | NEW |
(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 #ifndef CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_SAFE_AUDIO_VIDEO_CHECKER_H_ |
| 6 #define CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_SAFE_AUDIO_VIDEO_CHECKER_H_ |
| 7 |
| 8 #include "base/basictypes.h" |
| 9 #include "base/callback_forward.h" |
| 10 #include "base/files/scoped_platform_file_closer.h" |
| 11 #include "base/memory/weak_ptr.h" |
| 12 #include "base/platform_file.h" |
| 13 #include "content/public/browser/utility_process_host_client.h" |
| 14 #include "webkit/browser/fileapi/copy_or_move_file_validator.h" |
| 15 |
| 16 namespace content { |
| 17 class UtilityProcessHost; |
| 18 } |
| 19 |
| 20 // Uses a utility process to validate a media file. If the callback returns |
| 21 // PLATFORM_FILE_OK, then the file appears to be a valid media file. This does |
| 22 // not attempt to decode the entire file, which may take a considerable amount |
| 23 // of time. This class may be constructed on any thread, but should run on the |
| 24 // IO thread. |
| 25 class SafeAudioVideoChecker : public content::UtilityProcessHostClient { |
| 26 public: |
| 27 // Takes responsibility for closing |file|. |
| 28 SafeAudioVideoChecker( |
| 29 const base::PlatformFile& file, |
| 30 const fileapi::CopyOrMoveFileValidator::ResultCallback& callback); |
| 31 |
| 32 // Must be called on the IO thread. |
| 33 void Start(); |
| 34 |
| 35 private: |
| 36 enum State { |
| 37 INITIAL_STATE, |
| 38 PINGED_STATE, |
| 39 STARTED_STATE, |
| 40 FINISHED_STATE |
| 41 }; |
| 42 |
| 43 virtual ~SafeAudioVideoChecker(); |
| 44 |
| 45 // Starts validation once the utility process has been started. |
| 46 virtual void OnProcessStarted(); |
| 47 |
| 48 // Notification of the result from the utility process. |
| 49 void OnCheckingFinished(bool valid); |
| 50 |
| 51 // UtilityProcessHostClient implementation. |
| 52 virtual void OnProcessCrashed(int exit_code) OVERRIDE; |
| 53 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 54 |
| 55 State state_; |
| 56 |
| 57 // This should be accessed through |file_closer_| to ensure it hasn't already |
| 58 // been closed. |
| 59 base::PlatformFile file_; |
| 60 |
| 61 // Ensures that |file_| is closed if the utility process is not started for |
| 62 // some reason. |
| 63 base::ScopedPlatformFileCloser file_closer_; |
| 64 |
| 65 const fileapi::CopyOrMoveFileValidator::ResultCallback callback_; |
| 66 |
| 67 base::WeakPtr<content::UtilityProcessHost> utility_process_host_; |
| 68 |
| 69 DISALLOW_COPY_AND_ASSIGN(SafeAudioVideoChecker); |
| 70 }; |
| 71 |
| 72 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_SAFE_AUDIO_VIDEO_CHECKER_H_ |
OLD | NEW |