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

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: Address Toni's comments for Patch Sets #13, #17 and #22. 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 Observer* observer,
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 observer_(observer),
37 src_dir_(src_dir),
38 src_relative_paths_(src_relative_paths),
39 dest_file_(dest_file) {
40 }
41
42 void ZipFileCreator::Start() {
43 CHECK(BrowserThread::GetCurrentThreadIdentifier(&thread_identifier_));
44 BrowserThread::PostTask(
45 BrowserThread::IO, FROM_HERE,
46 base::Bind(
47 &ZipFileCreator::StartProcessOnIOThread,
48 this));
49 }
50
51 ZipFileCreator::~ZipFileCreator() {
52 }
53
54 bool ZipFileCreator::OnMessageReceived(const IPC::Message& message) {
55 bool handled = true;
56 IPC_BEGIN_MESSAGE_MAP(ZipFileCreator, message)
57 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_CreateZipFile_Succeeded,
58 OnCreateZipFileSucceeded)
59 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_CreateZipFile_Failed,
60 OnCreateZipFileFailed)
61 IPC_MESSAGE_UNHANDLED(handled = false)
62 IPC_END_MESSAGE_MAP()
63 return handled;
64 }
65
66 void ZipFileCreator::OnProcessCrashed(int exit_code) {
67 // Don't report crashes if they happen after we got a response.
68 if (got_response_)
69 return;
70
71 // Utility process crashed while trying to create the zip file.
72 ReportDone(false);
73 }
74
75 void ZipFileCreator::StartProcessOnIOThread() {
76 UtilityProcessHost* host = UtilityProcessHost::Create(
77 this, thread_identifier_);
78 host->Send(new ChromeUtilityMsg_CreateZipFile(src_dir_, src_relative_paths_,
79 dest_file_));
80 }
81
82 void ZipFileCreator::OnCreateZipFileSucceeded() {
83 // Skip check for unittests.
84 if (thread_identifier_ != BrowserThread::ID_COUNT)
85 CHECK(BrowserThread::CurrentlyOn(thread_identifier_));
86 got_response_ = true;
87
88 ReportDone(true);
89 }
90
91 void ZipFileCreator::OnCreateZipFileFailed() {
tbarzic 2012/11/12 20:29:37 should there be if (thread_identifier_ != BrowserT
hshi1 2012/11/12 21:42:17 Done.
92 CHECK(BrowserThread::CurrentlyOn(thread_identifier_));
93 got_response_ = true;
94 ReportDone(false);
95 }
96
97 void ZipFileCreator::ReportDone(bool success) {
98 observer_->OnZipDone(success);
99 }
100
101 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698