| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/file_manager/zip_file_creator.h" | 5 #include "chrome/browser/chromeos/file_manager/zip_file_creator.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/threading/sequenced_worker_pool.h" | 12 #include "base/task_scheduler/post_task.h" |
| 13 #include "chrome/common/chrome_utility_messages.h" | 13 #include "chrome/common/chrome_utility_messages.h" |
| 14 #include "chrome/grit/generated_resources.h" | 14 #include "chrome/grit/generated_resources.h" |
| 15 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
| 16 #include "content/public/browser/utility_process_host.h" | 16 #include "content/public/browser/utility_process_host.h" |
| 17 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
| 18 | 18 |
| 19 using content::BrowserThread; | 19 using content::BrowserThread; |
| 20 using content::UtilityProcessHost; | 20 using content::UtilityProcessHost; |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 // Creates the destination zip file only if it does not already exist. | 24 // Creates the destination zip file only if it does not already exist. |
| 25 base::File OpenFileHandleOnBlockingThreadPool(const base::FilePath& zip_path) { | 25 base::File OpenFileHandleAsync(const base::FilePath& zip_path) { |
| 26 return base::File(zip_path, base::File::FLAG_CREATE | base::File::FLAG_WRITE); | 26 return base::File(zip_path, base::File::FLAG_CREATE | base::File::FLAG_WRITE); |
| 27 } | 27 } |
| 28 | 28 |
| 29 } // namespace | 29 } // namespace |
| 30 | 30 |
| 31 namespace file_manager { | 31 namespace file_manager { |
| 32 | 32 |
| 33 ZipFileCreator::ZipFileCreator( | 33 ZipFileCreator::ZipFileCreator( |
| 34 const ResultCallback& callback, | 34 const ResultCallback& callback, |
| 35 const base::FilePath& src_dir, | 35 const base::FilePath& src_dir, |
| 36 const std::vector<base::FilePath>& src_relative_paths, | 36 const std::vector<base::FilePath>& src_relative_paths, |
| 37 const base::FilePath& dest_file) | 37 const base::FilePath& dest_file) |
| 38 : callback_(callback), | 38 : callback_(callback), |
| 39 src_dir_(src_dir), | 39 src_dir_(src_dir), |
| 40 src_relative_paths_(src_relative_paths), | 40 src_relative_paths_(src_relative_paths), |
| 41 dest_file_(dest_file) { | 41 dest_file_(dest_file) { |
| 42 DCHECK(!callback_.is_null()); | 42 DCHECK(!callback_.is_null()); |
| 43 } | 43 } |
| 44 | 44 |
| 45 void ZipFileCreator::Start() { | 45 void ZipFileCreator::Start() { |
| 46 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 46 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 47 | 47 |
| 48 base::PostTaskAndReplyWithResult( | 48 base::PostTaskWithTraitsAndReplyWithResult( |
| 49 BrowserThread::GetBlockingPool(), | 49 FROM_HERE, base::TaskTraits().MayBlock(), |
| 50 FROM_HERE, | 50 base::Bind(&OpenFileHandleAsync, dest_file_), |
| 51 base::Bind(&OpenFileHandleOnBlockingThreadPool, dest_file_), | |
| 52 base::Bind(&ZipFileCreator::OnOpenFileHandle, this)); | 51 base::Bind(&ZipFileCreator::OnOpenFileHandle, this)); |
| 53 } | 52 } |
| 54 | 53 |
| 55 ZipFileCreator::~ZipFileCreator() { | 54 ZipFileCreator::~ZipFileCreator() { |
| 56 } | 55 } |
| 57 | 56 |
| 58 bool ZipFileCreator::OnMessageReceived(const IPC::Message& message) { | 57 bool ZipFileCreator::OnMessageReceived(const IPC::Message& message) { |
| 59 bool handled = true; | 58 bool handled = true; |
| 60 IPC_BEGIN_MESSAGE_MAP(ZipFileCreator, message) | 59 IPC_BEGIN_MESSAGE_MAP(ZipFileCreator, message) |
| 61 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_CreateZipFile_Succeeded, | 60 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_CreateZipFile_Succeeded, |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 | 110 |
| 112 void ZipFileCreator::ReportDone(bool success) { | 111 void ZipFileCreator::ReportDone(bool success) { |
| 113 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 112 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 114 | 113 |
| 115 // Guard against calling observer multiple times. | 114 // Guard against calling observer multiple times. |
| 116 if (!callback_.is_null()) | 115 if (!callback_.is_null()) |
| 117 base::ResetAndReturn(&callback_).Run(success); | 116 base::ResetAndReturn(&callback_).Run(success); |
| 118 } | 117 } |
| 119 | 118 |
| 120 } // namespace file_manager | 119 } // namespace file_manager |
| OLD | NEW |