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

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: Fixes callback types and removes unnecessary message posting. Created 7 years 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
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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 133
134 void OnBurnFinished(const std::string& target_path, 134 void OnBurnFinished(const std::string& target_path,
135 bool success, 135 bool success,
136 const std::string& error); 136 const std::string& error);
137 void OnBurnProgress(const std::string& target_path, 137 void OnBurnProgress(const std::string& target_path,
138 int64 num_bytes_burnt, 138 int64 num_bytes_burnt,
139 int64 total_size); 139 int64 total_size);
140 void OnBurnError(); 140 void OnBurnError();
141 #endif 141 #endif
142 142
143 // Incrementally calculates the MD5 sum of a file.
143 void MD5Chunk(scoped_ptr<image_writer_utils::ImageReader> reader, 144 void MD5Chunk(scoped_ptr<image_writer_utils::ImageReader> reader,
144 int64 bytes_processed, 145 int64 bytes_processed,
145 int64 bytes_total, 146 int64 bytes_total,
146 int progress_offset, 147 int progress_offset,
147 int progress_scale, 148 int progress_scale,
148 const base::Callback<void(scoped_ptr<std::string>)>& callback); 149 const base::Callback<void(scoped_ptr<std::string>)>& callback);
149 150
151 // Callbacks for zip::ZipReader.
152 void OnUnzipSuccess();
153 void OnUnzipFailure();
154 void OnUnzipProgress(int64 total_bytes, int64 progress_bytes);
155
150 // Runs all cleanup functions. 156 // Runs all cleanup functions.
151 void CleanUp(); 157 void CleanUp();
152 158
153 // |stage_| and |progress_| are owned by the FILE thread, use |SetStage| and 159 // |stage_| and |progress_| are owned by the FILE thread, use |SetStage| and
154 // |SetProgress| to update. Progress should be in the interval [0,100] 160 // |SetProgress| to update. Progress should be in the interval [0,100]
155 image_writer_api::Stage stage_; 161 image_writer_api::Stage stage_;
156 int progress_; 162 int progress_;
157 163
158 // MD5 contexts don't play well with smart pointers. Just going to allocate 164 // MD5 contexts don't play well with smart pointers. Just going to allocate
159 // memory here. This requires that we only do one MD5 sum at a time. 165 // memory here. This requires that we only do one MD5 sum at a time.
160 base::MD5Context md5_context_; 166 base::MD5Context md5_context_;
161 167
168 // Zip reader for unzip operations.
169 zip::ZipReader zip_reader_;
170
162 // CleanUp operations that must be run. All these functions are run on the 171 // CleanUp operations that must be run. All these functions are run on the
163 // FILE thread. 172 // FILE thread.
164 std::vector<base::Closure> cleanup_functions_; 173 std::vector<base::Closure> cleanup_functions_;
165 }; 174 };
166 175
167 } // namespace image_writer 176 } // namespace image_writer
168 } // namespace extensions 177 } // namespace extensions
169 178
170 #endif // CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_OPERATION_H_ 179 #endif // CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_OPERATION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698