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. | |
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. | |
tbarzic
2012/11/10 03:40:56
Is this still true?
hshi1
2012/11/12 20:12:12
You're right, removed.
| |
33 class ZipFileCreator : public content::UtilityProcessHostClient { | |
34 public: | |
35 class Delegate { | |
36 public: | |
37 virtual void OnZipDone(bool success) = 0; | |
38 | |
39 protected: | |
40 virtual ~Delegate() {} | |
41 }; | |
42 | |
43 // Creates a zip file from the specified list of files and directories. | |
44 ZipFileCreator(Delegate* delegate, | |
45 const FilePath& src_dir, | |
46 const std::vector<FilePath>& src_relative_paths, | |
47 const FilePath& dest_file); | |
48 | |
49 // Start creating the zip file. The client is called with the results. | |
50 void Start(); | |
51 | |
52 private: | |
53 class ProcessHostClient; | |
54 | |
55 friend class ProcessHostClient; | |
56 friend class ZipFileCreatorTest; | |
57 | |
58 virtual ~ZipFileCreator(); | |
59 | |
60 // Starts the utility process that creates the zip file. | |
61 void StartProcessOnIOThread(); | |
62 | |
63 // UtilityProcessHostClient | |
64 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | |
65 virtual void OnProcessCrashed(int exit_code) OVERRIDE; | |
66 | |
67 // IPC message handlers. | |
68 void OnCreateZipFileSucceeded(); | |
69 void OnCreateZipFileFailed(); | |
70 | |
71 void ReportFailure(); | |
tbarzic
2012/11/10 03:40:56
similar to delegate methods,
these could be merged
hshi1
2012/11/12 20:12:12
Done.
| |
72 void ReportSuccess(); | |
73 | |
74 // Our delegate's thread. This is the thread we respond on. | |
75 content::BrowserThread::ID thread_identifier_; | |
76 | |
77 // Our delegate. | |
78 Delegate* delegate_; | |
79 | |
80 // The source directory for input files. | |
81 FilePath src_dir_; | |
82 | |
83 // The list of source files paths to be included in the zip file. | |
84 // Entries are relative paths under directory |src_dir_|. | |
85 std::vector<FilePath> src_relative_paths_; | |
86 | |
87 // The output zip file. | |
88 FilePath dest_file_; | |
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_CHROMEOS_EXTENSIONS_ZIP_FILE_CREATOR_H_ | |
OLD | NEW |