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

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: Remove the unused function (ZipSelectionFilter). 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& dir_path,
33 const FilePath& dest_path,
34 const std::vector<FilePath>& file_paths)
35 : thread_identifier_(BrowserThread::ID_COUNT),
36 delegate_(delegate),
37 dir_path_(dir_path),
38 dest_path_(dest_path),
39 file_paths_(file_paths) {
40 }
41
42 void ZipFileCreator::Start() {
43 // We assume that we are started on the thread that the client wants us to do
tbarzic 2012/11/06 19:41:25 maybe it would be easier to use the class if this
hshi1 2012/11/10 02:29:11 Maybe the comments aren't clear, but this function
tbarzic 2012/11/10 03:40:56 ah, ok.. Is there a reason this is called on file
hshi1 2012/11/12 20:12:12 Done.
44 // file IO on.
45 CHECK(BrowserThread::GetCurrentThreadIdentifier(&thread_identifier_));
46
47 // The utility process will have access to the directory passed to
48 // ZipFileCreator. TODO: determine the directory.
49 BrowserThread::PostTask(
50 BrowserThread::IO, FROM_HERE,
51 base::Bind(
52 &ZipFileCreator::StartProcessOnIOThread,
53 this));
54 }
55
56 ZipFileCreator::~ZipFileCreator() {
57 }
58
59 bool ZipFileCreator::OnMessageReceived(const IPC::Message& message) {
60 bool handled = true;
61 IPC_BEGIN_MESSAGE_MAP(ZipFileCreator, message)
62 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_CreateZipFile_Succeeded,
63 OnCreateZipFileSucceeded)
64 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_CreateZipFile_Failed,
65 OnCreateZipFileFailed)
66 IPC_MESSAGE_UNHANDLED(handled = false)
67 IPC_END_MESSAGE_MAP()
68 return handled;
69 }
70
71 void ZipFileCreator::OnProcessCrashed(int exit_code) {
72 // Don't report crashes if they happen after we got a response.
73 if (got_response_)
74 return;
75
76 // Utility process crashed while trying to install.
77 ReportFailure();
78 }
79
80 void ZipFileCreator::StartProcessOnIOThread() {
81 UtilityProcessHost* host = UtilityProcessHost::Create(
82 this, thread_identifier_);
83 // Grant the subprocess access to some directory.
84 // host->SetExposedDir(temp_crx_path.DirName());
tbarzic 2012/11/06 19:41:25 Is this commented out intentionally? If so, it wou
hshi1 2012/11/10 02:29:11 Done.
85 host->Send(new ChromeUtilityMsg_CreateZipFile(dir_path_, dest_path_,
86 file_paths_));
87 }
88
89 void ZipFileCreator::OnCreateZipFileSucceeded() {
90 // Skip check for unittests.
91 if (thread_identifier_ != BrowserThread::ID_COUNT)
92 CHECK(BrowserThread::CurrentlyOn(thread_identifier_));
93 got_response_ = true;
94
95 ReportSuccess();
96 }
97
98 void ZipFileCreator::OnCreateZipFileFailed() {
99 CHECK(BrowserThread::CurrentlyOn(thread_identifier_));
100 got_response_ = true;
101 ReportFailure();
102 }
103
104 void ZipFileCreator::ReportFailure() {
105 delegate_->OnZipFailure();
106 }
107
108 void ZipFileCreator::ReportSuccess() {
109 delegate_->OnZipSuccess();
110 }
111
112 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698