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