Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / chromeos / file_manager / zip_file_creator.h
blob5b07e69da70366eaf6fae56b513685733937d891
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_
8 #include "base/callback.h"
9 #include "base/files/file.h"
10 #include "base/files/file_path.h"
11 #include "content/public/browser/utility_process_host_client.h"
13 namespace file_manager {
15 // ZipFileCreator creates a ZIP file from a specified list of files and
16 // directories under a common parent directory. This is done in a sandboxed
17 // subprocess to protect the browser process from handling arbitrary input data
18 // from untrusted sources.
20 // The class is ref-counted and its ownership is passed around internal callback
21 // objects and finally to UtilityProcessHost. After the job finishes, the host
22 // releases the ref-pointer and then ZipFileCreator is automatically deleted.
23 class ZipFileCreator : public content::UtilityProcessHostClient {
24 public:
25 typedef base::Callback<void(bool)> ResultCallback;
27 // Creates a zip file from the specified list of files and directories.
28 ZipFileCreator(const ResultCallback& callback,
29 const base::FilePath& src_dir,
30 const std::vector<base::FilePath>& src_relative_paths,
31 const base::FilePath& dest_file);
33 // Starts creating the zip file. Must be called from the UI thread.
34 // The result will be passed to |callback|. After the task is finished and
35 // |callback| is run, ZipFileCreator instance is deleted.
36 void Start();
38 private:
39 friend class ProcessHostClient;
41 ~ZipFileCreator() override;
43 // Called after the file handle is opened on blocking pool.
44 void OnOpenFileHandle(base::File file);
46 // Starts the utility process that creates the zip file.
47 void StartProcessOnIOThread(base::File dest_file);
49 // UtilityProcessHostClient
50 bool OnMessageReceived(const IPC::Message& message) override;
51 void OnProcessCrashed(int exit_code) override;
53 // IPC message handlers.
54 void OnCreateZipFileSucceeded();
55 void OnCreateZipFileFailed();
57 void ReportDone(bool success);
59 // The callback.
60 ResultCallback callback_;
62 // The source directory for input files.
63 base::FilePath src_dir_;
65 // The list of source files paths to be included in the zip file.
66 // Entries are relative paths under directory |src_dir_|.
67 std::vector<base::FilePath> src_relative_paths_;
69 // The output zip file.
70 base::FilePath dest_file_;
73 } // namespace file_manager
75 #endif // CHROME_BROWSER_CHROMEOS_FILE_MANAGER_ZIP_FILE_CREATOR_H_