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.
5 #ifndef CHROME_BROWSER_CHROMEOS_FILE_MANAGER_ZIP_FILE_CREATOR_H_
6 #define CHROME_BROWSER_CHROMEOS_FILE_MANAGER_ZIP_FILE_CREATOR_H_
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"
17 namespace file_manager {
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.
24 // Lifetime management:
26 // This class is ref-counted by each call it makes to itself on another thread,
27 // and by UtilityProcessHost.
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 {
35 virtual void OnZipDone(bool success) = 0;
38 virtual ~Observer() {}
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);
47 // Start creating the zip file. The client is called with the results.
51 friend class ProcessHostClient;
53 virtual ~ZipFileCreator();
55 // Opens a handle for the zip file, and proceeds to StartProcessOnIOThread.
56 void OpenFileHandleOnBlockingThreadPool();
58 // Starts the utility process that creates the zip file.
59 void StartProcessOnIOThread(base::PlatformFile dest_file);
61 // UtilityProcessHostClient
62 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
63 virtual void OnProcessCrashed(int exit_code) OVERRIDE;
65 // IPC message handlers.
66 void OnCreateZipFileSucceeded();
67 void OnCreateZipFileFailed();
69 void ReportDone(bool success);
71 // The observer's thread. This is the thread we respond on.
72 content::BrowserThread::ID thread_identifier_;
77 // The source directory for input files.
78 base::FilePath src_dir_;
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_;
84 // The output zip file.
85 base::FilePath dest_file_;
87 // Whether we've received a response from the utility process yet.
91 } // namespace file_manager
93 #endif // CHROME_BROWSER_CHROMEOS_FILE_MANAGER_ZIP_FILE_CREATOR_H_