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

Side by Side Diff: chrome/browser/extensions/api/image_writer_private/operation.h

Issue 92873003: Adds asynchronous unzip functions to ZipReader (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Uses the correct target for directory test. Created 6 years, 11 months 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
« no previous file with comments | « no previous file | chrome/browser/extensions/api/image_writer_private/operation.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #ifndef CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_OPERATION_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_OPERATION_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_OPERATION_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_OPERATION_H_
7 7
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/md5.h" 9 #include "base/md5.h"
10 #include "base/memory/ref_counted_memory.h" 10 #include "base/memory/ref_counted_memory.h"
11 #include "base/memory/weak_ptr.h" 11 #include "base/memory/weak_ptr.h"
12 #include "base/timer/timer.h" 12 #include "base/timer/timer.h"
13 #include "chrome/browser/extensions/api/image_writer_private/image_writer_utils. h" 13 #include "chrome/browser/extensions/api/image_writer_private/image_writer_utils. h"
14 #include "chrome/common/cancelable_task_tracker.h" 14 #include "chrome/common/cancelable_task_tracker.h"
15 #include "chrome/common/extensions/api/image_writer_private.h" 15 #include "chrome/common/extensions/api/image_writer_private.h"
16 #include "third_party/zlib/google/zip_reader.h"
16 17
17 namespace image_writer_api = extensions::api::image_writer_private; 18 namespace image_writer_api = extensions::api::image_writer_private;
18 19
19 namespace base { 20 namespace base {
20 class FilePath; 21 class FilePath;
21 } // namespace base 22 } // namespace base
22 23
23 namespace extensions { 24 namespace extensions {
24 namespace image_writer { 25 namespace image_writer {
25 26
26 const int kProgressComplete = 100; 27 const int kProgressComplete = 100;
27 28
28 class OperationManager; 29 class OperationManager;
29 30
30 // Encapsulates an operation being run on behalf of the 31 // Encapsulates an operation being run on behalf of the
31 // OperationManager. Construction of the operation does not start 32 // OperationManager. Construction of the operation does not start
32 // anything. The operation's Start method should be called to start it, and 33 // anything. The operation's Start method should be called to start it, and
33 // then the Cancel method will stop it. The operation will call back to the 34 // then the Cancel method will stop it. The operation will call back to the
34 // OperationManager periodically or on any significant event. 35 // OperationManager periodically or on any significant event.
35 // 36 //
36 // Each stage of the operation is generally divided into three phases: Start, 37 // Each stage of the operation is generally divided into three phases: Start,
37 // Run, Complete. Start and Complete run on the UI thread and are responsible 38 // Run, Complete. Start and Complete run on the UI thread and are responsible
38 // for advancing to the next stage and other UI interaction. The Run phase does 39 // for advancing to the next stage and other UI interaction. The Run phase does
39 // the work on the FILE thread and calls SendProgress or Error as appropriate. 40 // the work on the FILE thread and calls SendProgress or Error as appropriate.
40 class Operation 41 class Operation : public base::RefCountedThreadSafe<Operation> {
41 : public base::RefCountedThreadSafe<Operation> {
42 public: 42 public:
43 typedef base::Callback<void(bool, const std::string&)> StartWriteCallback; 43 typedef base::Callback<void(bool, const std::string&)> StartWriteCallback;
44 typedef base::Callback<void(bool, const std::string&)> CancelWriteCallback; 44 typedef base::Callback<void(bool, const std::string&)> CancelWriteCallback;
45 typedef std::string ExtensionId; 45 typedef std::string ExtensionId;
46 46
47 Operation(base::WeakPtr<OperationManager> manager, 47 Operation(base::WeakPtr<OperationManager> manager,
48 const ExtensionId& extension_id, 48 const ExtensionId& extension_id,
49 const std::string& storage_unit_id); 49 const std::string& storage_unit_id);
50 50
51 // Starts the operation. 51 // Starts the operation.
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 136
137 void OnBurnFinished(const std::string& target_path, 137 void OnBurnFinished(const std::string& target_path,
138 bool success, 138 bool success,
139 const std::string& error); 139 const std::string& error);
140 void OnBurnProgress(const std::string& target_path, 140 void OnBurnProgress(const std::string& target_path,
141 int64 num_bytes_burnt, 141 int64 num_bytes_burnt,
142 int64 total_size); 142 int64 total_size);
143 void OnBurnError(); 143 void OnBurnError();
144 #endif 144 #endif
145 145
146 // Incrementally calculates the MD5 sum of a file.
146 void MD5Chunk(scoped_ptr<image_writer_utils::ImageReader> reader, 147 void MD5Chunk(scoped_ptr<image_writer_utils::ImageReader> reader,
147 int64 bytes_processed, 148 int64 bytes_processed,
148 int64 bytes_total, 149 int64 bytes_total,
149 int progress_offset, 150 int progress_offset,
150 int progress_scale, 151 int progress_scale,
151 const base::Callback<void(scoped_ptr<std::string>)>& callback); 152 const base::Callback<void(scoped_ptr<std::string>)>& callback);
152 153
154 // Callbacks for zip::ZipReader.
155 void OnUnzipSuccess();
156 void OnUnzipFailure();
157 void OnUnzipProgress(int64 total_bytes, int64 progress_bytes);
158
153 // Runs all cleanup functions. 159 // Runs all cleanup functions.
154 void CleanUp(); 160 void CleanUp();
155 161
156 // |stage_| and |progress_| are owned by the FILE thread, use |SetStage| and 162 // |stage_| and |progress_| are owned by the FILE thread, use |SetStage| and
157 // |SetProgress| to update. Progress should be in the interval [0,100] 163 // |SetProgress| to update. Progress should be in the interval [0,100]
158 image_writer_api::Stage stage_; 164 image_writer_api::Stage stage_;
159 int progress_; 165 int progress_;
160 166
161 // MD5 contexts don't play well with smart pointers. Just going to allocate 167 // MD5 contexts don't play well with smart pointers. Just going to allocate
162 // memory here. This requires that we only do one MD5 sum at a time. 168 // memory here. This requires that we only do one MD5 sum at a time.
163 base::MD5Context md5_context_; 169 base::MD5Context md5_context_;
164 170
171 // Zip reader for unzip operations.
172 zip::ZipReader zip_reader_;
173
165 // CleanUp operations that must be run. All these functions are run on the 174 // CleanUp operations that must be run. All these functions are run on the
166 // FILE thread. 175 // FILE thread.
167 std::vector<base::Closure> cleanup_functions_; 176 std::vector<base::Closure> cleanup_functions_;
168 }; 177 };
169 178
170 } // namespace image_writer 179 } // namespace image_writer
171 } // namespace extensions 180 } // namespace extensions
172 181
173 #endif // CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_OPERATION_H_ 182 #endif // CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_OPERATION_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/api/image_writer_private/operation.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698