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_EXTENSIONS_ZIP_FILE_CREATOR_H_ | |
| 6 #define CHROME_BROWSER_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. | |
| 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 // | |
| 31 // | |
| 32 // NOTE: This class should only be used on the file thread. | |
| 33 class ZipFileCreator : public content::UtilityProcessHostClient { | |
| 34 public: | |
| 35 class Delegate { | |
|
tbarzic
2012/11/06 19:41:25
Looks like this class reacts on events from the Zi
hshi1
2012/11/12 20:12:12
Done.
| |
| 36 public: | |
| 37 virtual void OnZipSuccess() = 0; | |
| 38 virtual void OnZipFailure() = 0; | |
| 39 | |
| 40 protected: | |
| 41 virtual ~Delegate() {} | |
| 42 }; | |
| 43 | |
| 44 // Creates a zip file from the specified list of files and directories. | |
| 45 ZipFileCreator(Delegate* delegate, | |
| 46 const FilePath& dir_path, | |
| 47 const FilePath& dest_path, | |
| 48 const std::vector<FilePath>& file_paths); | |
| 49 | |
| 50 // Start creating the zip file. The client is called with the results. | |
| 51 void Start(); | |
| 52 | |
| 53 private: | |
| 54 class ProcessHostClient; | |
| 55 | |
| 56 friend class ProcessHostClient; | |
| 57 friend class ZipFileCreatorTest; | |
| 58 | |
| 59 virtual ~ZipFileCreator(); | |
| 60 | |
| 61 // Starts the utility process that creates the zip file. | |
| 62 void StartProcessOnIOThread(); | |
| 63 | |
| 64 // UtilityProcessHostClient | |
| 65 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | |
| 66 virtual void OnProcessCrashed(int exit_code) OVERRIDE; | |
| 67 | |
| 68 // IPC message handlers. | |
| 69 void OnCreateZipFileSucceeded(); | |
| 70 void OnCreateZipFileFailed(); | |
| 71 | |
| 72 void ReportFailure(); | |
| 73 void ReportSuccess(); | |
| 74 | |
| 75 // Our delegate's thread. This is the thread we respond on. | |
|
tbarzic
2012/11/06 19:41:25
"The delegate's thread" sounds better to me, but y
hshi1
2012/11/12 20:12:12
Done.
| |
| 76 content::BrowserThread::ID thread_identifier_; | |
| 77 | |
| 78 // Our delegate. | |
| 79 Delegate* delegate_; | |
| 80 | |
| 81 // The common parent directory for the input and output files. | |
| 82 FilePath dir_path_; | |
| 83 | |
| 84 // The output zip file. | |
| 85 FilePath dest_path_; | |
| 86 | |
| 87 // The list of files and directories. | |
| 88 std::vector<FilePath> file_paths_; | |
| 89 | |
| 90 // Whether we've received a response from the utility process yet. | |
| 91 bool got_response_; | |
| 92 }; | |
| 93 | |
| 94 } // namespace extensions | |
| 95 | |
| 96 #endif // CHROME_BROWSER_EXTENSIONS_ZIP_FILE_CREATOR_H_ | |
| OLD | NEW |