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

Side by Side Diff: chrome/browser/chromeos/extensions/zip_file_creator.cc

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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 #include "chrome/browser/chromeos/extensions/zip_file_creator.h"
6
7 #include <set>
8
9 #include "base/bind.h"
10 #include "base/command_line.h"
11 #include "base/file_util.h"
12 #include "base/file_util_proxy.h"
13 #include "base/memory/scoped_handle.h"
14 #include "base/message_loop.h"
15 #include "base/path_service.h"
16 #include "chrome/common/chrome_paths.h"
17 #include "chrome/common/chrome_switches.h"
18 #include "chrome/common/chrome_utility_messages.h"
19 #include "chrome/common/extensions/extension_manifest_constants.h"
20 #include "chrome/common/extensions/extension_file_util.h"
21 #include "content/public/browser/browser_thread.h"
22 #include "content/public/browser/utility_process_host.h"
23 #include "grit/generated_resources.h"
24
25 using content::BrowserThread;
26 using content::UtilityProcessHost;
27
28 namespace extensions {
29
30 ZipFileCreator::ZipFileCreator(
31 Delegate* delegate,
32 const FilePath& src_dir,
33 const std::vector<FilePath>& src_relative_paths,
34 const FilePath& dest_file)
35 : thread_identifier_(BrowserThread::ID_COUNT),
36 delegate_(delegate),
37 src_dir_(src_dir),
38 src_relative_paths_(src_relative_paths),
39 dest_file_(dest_file) {
40 }
41
42 void ZipFileCreator::Start() {
43 // We assume that we are started on the thread that the client wants us to do
44 // file IO on.
45 CHECK(BrowserThread::GetCurrentThreadIdentifier(&thread_identifier_));
46 BrowserThread::PostTask(
47 BrowserThread::IO, FROM_HERE,
48 base::Bind(
49 &ZipFileCreator::StartProcessOnIOThread,
50 this));
51 }
52
53 ZipFileCreator::~ZipFileCreator() {
54 }
55
56 bool ZipFileCreator::OnMessageReceived(const IPC::Message& message) {
57 bool handled = true;
58 IPC_BEGIN_MESSAGE_MAP(ZipFileCreator, message)
59 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_CreateZipFile_Succeeded,
60 OnCreateZipFileSucceeded)
61 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_CreateZipFile_Failed,
62 OnCreateZipFileFailed)
63 IPC_MESSAGE_UNHANDLED(handled = false)
64 IPC_END_MESSAGE_MAP()
65 return handled;
66 }
67
68 void ZipFileCreator::OnProcessCrashed(int exit_code) {
69 // Don't report crashes if they happen after we got a response.
70 if (got_response_)
71 return;
72
73 // Utility process crashed while trying to create the zip file.
74 ReportFailure();
75 }
76
77 void ZipFileCreator::StartProcessOnIOThread() {
78 UtilityProcessHost* host = UtilityProcessHost::Create(
79 this, thread_identifier_);
80 host->Send(new ChromeUtilityMsg_CreateZipFile(src_dir_, src_relative_paths_,
81 dest_file_));
82 }
83
84 void ZipFileCreator::OnCreateZipFileSucceeded() {
85 // Skip check for unittests.
86 if (thread_identifier_ != BrowserThread::ID_COUNT)
87 CHECK(BrowserThread::CurrentlyOn(thread_identifier_));
88 got_response_ = true;
89
90 ReportSuccess();
91 }
92
93 void ZipFileCreator::OnCreateZipFileFailed() {
94 CHECK(BrowserThread::CurrentlyOn(thread_identifier_));
95 got_response_ = true;
96 ReportFailure();
97 }
98
99 void ZipFileCreator::ReportFailure() {
100 delegate_->OnZipDone(false);
101 }
102
103 void ZipFileCreator::ReportSuccess() {
104 delegate_->OnZipDone(true);
105 }
106
107 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698