Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Unified Diff: chrome/browser/chromeos/extensions/zip_file_creator.h

Issue 11309014: File manager: support for zipping selected files. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Still missing unit test for ZipFileCreator. Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/extensions/zip_file_creator.h
diff --git a/chrome/browser/chromeos/extensions/zip_file_creator.h b/chrome/browser/chromeos/extensions/zip_file_creator.h
new file mode 100644
index 0000000000000000000000000000000000000000..f10692abf25dc9f87b816dbcaa0a60f965eb6bf7
--- /dev/null
+++ b/chrome/browser/chromeos/extensions/zip_file_creator.h
@@ -0,0 +1,96 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_ZIP_FILE_CREATOR_H_
+#define CHROME_BROWSER_CHROMEOS_EXTENSIONS_ZIP_FILE_CREATOR_H_
+
+#include <string>
+
+#include "base/file_path.h"
+#include "base/memory/ref_counted.h"
+#include "chrome/common/extensions/extension.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/utility_process_host_client.h"
+
+namespace extensions {
+
+// ZipFileCreator creates a ZIP file from a specified list of files and
+// directories under a common parent directory. This is done in a sandboxed
+// subprocess to protect the browser process from handling arbitrary input data
+// from untrusted sources.
+//
+// Lifetime management:
+//
+// This class is ref-counted by each call it makes to itself on another thread,
+// and by UtilityProcessHost.
+//
+// Additionally, we hold a reference to our own client so that it lives at least
+// long enough to receive the result of zip file creation.
+//
+//
+// 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.
+class ZipFileCreator : public content::UtilityProcessHostClient {
+ public:
+ class Delegate {
+ public:
+ virtual void OnZipDone(bool success) = 0;
+
+ protected:
+ virtual ~Delegate() {}
+ };
+
+ // Creates a zip file from the specified list of files and directories.
+ ZipFileCreator(Delegate* delegate,
+ const FilePath& src_dir,
+ const std::vector<FilePath>& src_relative_paths,
+ const FilePath& dest_file);
+
+ // Start creating the zip file. The client is called with the results.
+ void Start();
+
+ private:
+ class ProcessHostClient;
+
+ friend class ProcessHostClient;
+ friend class ZipFileCreatorTest;
+
+ virtual ~ZipFileCreator();
+
+ // Starts the utility process that creates the zip file.
+ void StartProcessOnIOThread();
+
+ // UtilityProcessHostClient
+ virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
+ virtual void OnProcessCrashed(int exit_code) OVERRIDE;
+
+ // IPC message handlers.
+ void OnCreateZipFileSucceeded();
+ void OnCreateZipFileFailed();
+
+ 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.
+ void ReportSuccess();
+
+ // Our delegate's thread. This is the thread we respond on.
+ content::BrowserThread::ID thread_identifier_;
+
+ // Our delegate.
+ Delegate* delegate_;
+
+ // The source directory for input files.
+ FilePath src_dir_;
+
+ // The list of source files paths to be included in the zip file.
+ // Entries are relative paths under directory |src_dir_|.
+ std::vector<FilePath> src_relative_paths_;
+
+ // The output zip file.
+ FilePath dest_file_;
+
+ // Whether we've received a response from the utility process yet.
+ bool got_response_;
+};
+
+} // namespace extensions
+
+#endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_ZIP_FILE_CREATOR_H_

Powered by Google App Engine
This is Rietveld 408576698