| Index: chrome/browser/chromeos/extensions/zip_file_creator.cc
|
| diff --git a/chrome/browser/chromeos/extensions/zip_file_creator.cc b/chrome/browser/chromeos/extensions/zip_file_creator.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..3a188bc89b18c7f9cb2706e99cf610ccd29068de
|
| --- /dev/null
|
| +++ b/chrome/browser/chromeos/extensions/zip_file_creator.cc
|
| @@ -0,0 +1,112 @@
|
| +// 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.
|
| +
|
| +#include "chrome/browser/chromeos/extensions/zip_file_creator.h"
|
| +
|
| +#include <set>
|
| +
|
| +#include "base/bind.h"
|
| +#include "base/command_line.h"
|
| +#include "base/file_util.h"
|
| +#include "base/file_util_proxy.h"
|
| +#include "base/memory/scoped_handle.h"
|
| +#include "base/message_loop.h"
|
| +#include "base/path_service.h"
|
| +#include "chrome/common/chrome_paths.h"
|
| +#include "chrome/common/chrome_switches.h"
|
| +#include "chrome/common/chrome_utility_messages.h"
|
| +#include "chrome/common/extensions/extension_manifest_constants.h"
|
| +#include "chrome/common/extensions/extension_file_util.h"
|
| +#include "content/public/browser/browser_thread.h"
|
| +#include "content/public/browser/utility_process_host.h"
|
| +#include "grit/generated_resources.h"
|
| +
|
| +using content::BrowserThread;
|
| +using content::UtilityProcessHost;
|
| +
|
| +namespace extensions {
|
| +
|
| +ZipFileCreator::ZipFileCreator(
|
| + Delegate* delegate,
|
| + const FilePath& dir_path,
|
| + const FilePath& dest_path,
|
| + const std::vector<FilePath>& file_paths)
|
| + : thread_identifier_(BrowserThread::ID_COUNT),
|
| + delegate_(delegate),
|
| + dir_path_(dir_path),
|
| + dest_path_(dest_path),
|
| + file_paths_(file_paths) {
|
| +}
|
| +
|
| +void ZipFileCreator::Start() {
|
| + // We assume that we are started on the thread that the client wants us to do
|
| + // file IO on.
|
| + CHECK(BrowserThread::GetCurrentThreadIdentifier(&thread_identifier_));
|
| +
|
| + // The utility process will have access to the directory passed to
|
| + // ZipFileCreator. TODO: determine the directory.
|
| + BrowserThread::PostTask(
|
| + BrowserThread::IO, FROM_HERE,
|
| + base::Bind(
|
| + &ZipFileCreator::StartProcessOnIOThread,
|
| + this));
|
| +}
|
| +
|
| +ZipFileCreator::~ZipFileCreator() {
|
| +}
|
| +
|
| +bool ZipFileCreator::OnMessageReceived(const IPC::Message& message) {
|
| + bool handled = true;
|
| + IPC_BEGIN_MESSAGE_MAP(ZipFileCreator, message)
|
| + IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_CreateZipFile_Succeeded,
|
| + OnCreateZipFileSucceeded)
|
| + IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_CreateZipFile_Failed,
|
| + OnCreateZipFileFailed)
|
| + IPC_MESSAGE_UNHANDLED(handled = false)
|
| + IPC_END_MESSAGE_MAP()
|
| + return handled;
|
| +}
|
| +
|
| +void ZipFileCreator::OnProcessCrashed(int exit_code) {
|
| + // Don't report crashes if they happen after we got a response.
|
| + if (got_response_)
|
| + return;
|
| +
|
| + // Utility process crashed while trying to install.
|
| + ReportFailure();
|
| +}
|
| +
|
| +void ZipFileCreator::StartProcessOnIOThread() {
|
| + UtilityProcessHost* host = UtilityProcessHost::Create(
|
| + this, thread_identifier_);
|
| + // Grant the subprocess access to some directory.
|
| + // host->SetExposedDir(temp_crx_path.DirName());
|
| + host->Send(new ChromeUtilityMsg_CreateZipFile(dir_path_, dest_path_,
|
| + file_paths_));
|
| +}
|
| +
|
| +void ZipFileCreator::OnCreateZipFileSucceeded() {
|
| + // Skip check for unittests.
|
| + if (thread_identifier_ != BrowserThread::ID_COUNT)
|
| + CHECK(BrowserThread::CurrentlyOn(thread_identifier_));
|
| + got_response_ = true;
|
| +
|
| + ReportSuccess();
|
| +}
|
| +
|
| +void ZipFileCreator::OnCreateZipFileFailed() {
|
| + CHECK(BrowserThread::CurrentlyOn(thread_identifier_));
|
| + got_response_ = true;
|
| + ReportFailure();
|
| +}
|
| +
|
| +void ZipFileCreator::ReportFailure() {
|
| + delegate_->OnZipFailure();
|
| +}
|
| +
|
| +void ZipFileCreator::ReportSuccess() {
|
| + delegate_->OnZipSuccess();
|
| +}
|
| +
|
| +} // namespace extensions
|
|
|