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

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: Cleanup 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
41 : public base::RefCountedThreadSafe<Operation> { 42 : public zip::ZipReader::Listener {
42 public: 43 public:
43 typedef base::Callback<void(bool, const std::string&)> StartWriteCallback; 44 typedef base::Callback<void(bool, const std::string&)> StartWriteCallback;
44 typedef base::Callback<void(bool, const std::string&)> CancelWriteCallback; 45 typedef base::Callback<void(bool, const std::string&)> CancelWriteCallback;
45 typedef std::string ExtensionId; 46 typedef std::string ExtensionId;
46 47
47 Operation(base::WeakPtr<OperationManager> manager, 48 Operation(base::WeakPtr<OperationManager> manager,
48 const ExtensionId& extension_id, 49 const ExtensionId& extension_id,
49 const std::string& storage_unit_id); 50 const std::string& storage_unit_id);
50 51
51 // Starts the operation. 52 // Starts the operation.
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 127
127 void OnBurnFinished(const std::string& target_path, 128 void OnBurnFinished(const std::string& target_path,
128 bool success, 129 bool success,
129 const std::string& error); 130 const std::string& error);
130 void OnBurnProgress(const std::string& target_path, 131 void OnBurnProgress(const std::string& target_path,
131 int64 num_bytes_burnt, 132 int64 num_bytes_burnt,
132 int64 total_size); 133 int64 total_size);
133 void OnBurnError(); 134 void OnBurnError();
134 #endif 135 #endif
135 136
137 // Incrementally calculates the MD5 sum of a file.
136 void MD5Chunk(scoped_ptr<image_writer_utils::ImageReader> reader, 138 void MD5Chunk(scoped_ptr<image_writer_utils::ImageReader> reader,
137 int64 bytes_processed, 139 int64 bytes_processed,
138 int64 bytes_total, 140 int64 bytes_total,
139 int progress_offset, 141 int progress_offset,
140 int progress_scale, 142 int progress_scale,
141 const base::Callback<void(scoped_ptr<std::string>)>& callback); 143 const base::Callback<void(scoped_ptr<std::string>)>& callback);
142 144
145 // Implementation of zip::ZipReader::Listener
146 virtual void OnUnzipProgress(int progress) OVERRIDE;
147 virtual void OnUnzipSuccess() OVERRIDE;
148 virtual void OnUnzipFailed() OVERRIDE;
149
143 // Runs all cleanup functions. 150 // Runs all cleanup functions.
144 void CleanUp(); 151 void CleanUp();
145 152
146 // |stage_| and |progress_| are owned by the FILE thread, use |SetStage| and 153 // |stage_| and |progress_| are owned by the FILE thread, use |SetStage| and
147 // |SetProgress| to update. Progress should be in the interval [0,100] 154 // |SetProgress| to update. Progress should be in the interval [0,100]
148 image_writer_api::Stage stage_; 155 image_writer_api::Stage stage_;
149 int progress_; 156 int progress_;
150 157
151 // MD5 contexts don't play well with smart pointers. Just going to allocate 158 // MD5 contexts don't play well with smart pointers. Just going to allocate
152 // memory here. This requires that we only do one MD5 sum at a time. 159 // memory here. This requires that we only do one MD5 sum at a time.
153 base::MD5Context md5_context_; 160 base::MD5Context md5_context_;
154 161
162 // Zip reader for unzip operations.
163 zip::ZipReader zip_reader_;
164
155 // CleanUp operations that must be run. All these functions are run on the 165 // CleanUp operations that must be run. All these functions are run on the
156 // FILE thread. 166 // FILE thread.
157 std::vector<base::Closure> cleanup_functions_; 167 std::vector<base::Closure> cleanup_functions_;
158 }; 168 };
159 169
160 } // namespace image_writer 170 } // namespace image_writer
161 } // namespace extensions 171 } // namespace extensions
162 172
163 #endif // CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_OPERATION_H_ 173 #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') | third_party/zlib/google/zip_reader.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698