| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 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_CHROMEOS_EXTENSIONS_FILE_MANAGER_ZIP_FILE_CREATOR_H_ | |
| 6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_ZIP_FILE_CREATOR_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/files/file_path.h" | |
| 11 #include "base/memory/ref_counted.h" | |
| 12 #include "base/platform_file.h" | |
| 13 #include "chrome/common/extensions/extension.h" | |
| 14 #include "content/public/browser/browser_thread.h" | |
| 15 #include "content/public/browser/utility_process_host_client.h" | |
| 16 | |
| 17 namespace file_manager { | |
| 18 | |
| 19 // ZipFileCreator creates a ZIP file from a specified list of files and | |
| 20 // directories under a common parent directory. This is done in a sandboxed | |
| 21 // subprocess to protect the browser process from handling arbitrary input data | |
| 22 // from untrusted sources. | |
| 23 // | |
| 24 // Lifetime management: | |
| 25 // | |
| 26 // This class is ref-counted by each call it makes to itself on another thread, | |
| 27 // and by UtilityProcessHost. | |
| 28 // | |
| 29 // Additionally, we hold a reference to our own client so that it lives at least | |
| 30 // long enough to receive the result of zip file creation. | |
| 31 class ZipFileCreator : public content::UtilityProcessHostClient { | |
| 32 public: | |
| 33 class Observer { | |
| 34 public: | |
| 35 virtual void OnZipDone(bool success) = 0; | |
| 36 | |
| 37 protected: | |
| 38 virtual ~Observer() {} | |
| 39 }; | |
| 40 | |
| 41 // Creates a zip file from the specified list of files and directories. | |
| 42 ZipFileCreator(Observer* observer, | |
| 43 const base::FilePath& src_dir, | |
| 44 const std::vector<base::FilePath>& src_relative_paths, | |
| 45 const base::FilePath& dest_file); | |
| 46 | |
| 47 // Start creating the zip file. The client is called with the results. | |
| 48 void Start(); | |
| 49 | |
| 50 private: | |
| 51 friend class ProcessHostClient; | |
| 52 | |
| 53 virtual ~ZipFileCreator(); | |
| 54 | |
| 55 // Opens a handle for the zip file, and proceeds to StartProcessOnIOThread. | |
| 56 void OpenFileHandleOnBlockingThreadPool(); | |
| 57 | |
| 58 // Starts the utility process that creates the zip file. | |
| 59 void StartProcessOnIOThread(base::PlatformFile dest_file); | |
| 60 | |
| 61 // UtilityProcessHostClient | |
| 62 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | |
| 63 virtual void OnProcessCrashed(int exit_code) OVERRIDE; | |
| 64 | |
| 65 // IPC message handlers. | |
| 66 void OnCreateZipFileSucceeded(); | |
| 67 void OnCreateZipFileFailed(); | |
| 68 | |
| 69 void ReportDone(bool success); | |
| 70 | |
| 71 // The observer's thread. This is the thread we respond on. | |
| 72 content::BrowserThread::ID thread_identifier_; | |
| 73 | |
| 74 // The observer. | |
| 75 Observer* observer_; | |
| 76 | |
| 77 // The source directory for input files. | |
| 78 base::FilePath src_dir_; | |
| 79 | |
| 80 // The list of source files paths to be included in the zip file. | |
| 81 // Entries are relative paths under directory |src_dir_|. | |
| 82 std::vector<base::FilePath> src_relative_paths_; | |
| 83 | |
| 84 // The output zip file. | |
| 85 base::FilePath dest_file_; | |
| 86 | |
| 87 // Whether we've received a response from the utility process yet. | |
| 88 bool got_response_; | |
| 89 }; | |
| 90 | |
| 91 } // namespace file_manager | |
| 92 | |
| 93 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_ZIP_FILE_CREATOR_H_ | |
| OLD | NEW |