OLD | NEW |
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/task/cancelable_task_tracker.h" | 12 #include "base/task/cancelable_task_tracker.h" |
13 #include "base/timer/timer.h" | 13 #include "base/timer/timer.h" |
14 #include "chrome/browser/extensions/api/image_writer_private/image_writer_utils.
h" | 14 #include "chrome/browser/extensions/api/image_writer_private/image_writer_utils.
h" |
| 15 #include "chrome/browser/image_writer_client.h" |
15 #include "chrome/common/extensions/api/image_writer_private.h" | 16 #include "chrome/common/extensions/api/image_writer_private.h" |
16 #include "third_party/zlib/google/zip_reader.h" | 17 #include "third_party/zlib/google/zip_reader.h" |
17 | 18 |
18 namespace image_writer_api = extensions::api::image_writer_private; | 19 namespace image_writer_api = extensions::api::image_writer_private; |
19 | 20 |
20 namespace base { | 21 namespace base { |
21 class FilePath; | 22 class FilePath; |
22 } // namespace base | 23 } // namespace base |
23 | 24 |
24 namespace extensions { | 25 namespace extensions { |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 | 110 |
110 base::FilePath image_path_; | 111 base::FilePath image_path_; |
111 const std::string storage_unit_id_; | 112 const std::string storage_unit_id_; |
112 | 113 |
113 // Whether or not to run the final verification step. | 114 // Whether or not to run the final verification step. |
114 bool verify_write_; | 115 bool verify_write_; |
115 | 116 |
116 private: | 117 private: |
117 friend class base::RefCountedThreadSafe<Operation>; | 118 friend class base::RefCountedThreadSafe<Operation>; |
118 | 119 |
119 // TODO(haven): Clean up these switches. http://crbug.com/292956 | |
120 #if defined(OS_LINUX) && !defined(CHROMEOS) | |
121 void WriteRun(); | |
122 void WriteChunk(scoped_ptr<image_writer_utils::ImageReader> reader, | |
123 scoped_ptr<image_writer_utils::ImageWriter> writer, | |
124 int64 bytes_written); | |
125 bool WriteCleanUp(scoped_ptr<image_writer_utils::ImageReader> reader, | |
126 scoped_ptr<image_writer_utils::ImageWriter> writer); | |
127 void WriteComplete(); | |
128 | |
129 void VerifyWriteStage2(scoped_ptr<std::string> image_hash); | |
130 void VerifyWriteCompare(scoped_ptr<std::string> image_hash, | |
131 scoped_ptr<std::string> device_hash); | |
132 #endif | |
133 | |
134 #if defined(OS_CHROMEOS) | 120 #if defined(OS_CHROMEOS) |
135 void StartWriteOnUIThread(); | 121 void StartWriteOnUIThread(); |
136 | 122 |
137 void OnBurnFinished(const std::string& target_path, | 123 void OnBurnFinished(const std::string& target_path, |
138 bool success, | 124 bool success, |
139 const std::string& error); | 125 const std::string& error); |
140 void OnBurnProgress(const std::string& target_path, | 126 void OnBurnProgress(const std::string& target_path, |
141 int64 num_bytes_burnt, | 127 int64 num_bytes_burnt, |
142 int64 total_size); | 128 int64 total_size); |
143 void OnBurnError(); | 129 void OnBurnError(); |
144 #endif | 130 #endif |
145 | 131 |
| 132 #if !defined(OS_CHROMEOS) |
| 133 // Ensures the client is started. This may be called many times but will only |
| 134 // instantiate one client which should exist for the lifetime of |
| 135 void StartImageWriterClient(); |
| 136 |
| 137 // Stops the client. This must be called to ensure the utility process can |
| 138 // shutdown. |
| 139 void StopImageWriterClient(); |
| 140 |
| 141 // Reports progress from the client, transforming from bytes to percentage. |
| 142 virtual void WriteImageProgress(int64 total_bytes, int64 curr_bytes); |
| 143 |
| 144 scoped_refptr<ImageWriterClient> image_writer_client_; |
| 145 #endif |
| 146 |
146 // Incrementally calculates the MD5 sum of a file. | 147 // Incrementally calculates the MD5 sum of a file. |
147 void MD5Chunk(scoped_ptr<image_writer_utils::ImageReader> reader, | 148 void MD5Chunk(scoped_ptr<image_writer_utils::ImageReader> reader, |
148 int64 bytes_processed, | 149 int64 bytes_processed, |
149 int64 bytes_total, | 150 int64 bytes_total, |
150 int progress_offset, | 151 int progress_offset, |
151 int progress_scale, | 152 int progress_scale, |
152 const base::Callback<void(scoped_ptr<std::string>)>& callback); | 153 const base::Callback<void(scoped_ptr<std::string>)>& callback); |
153 | 154 |
154 // Callbacks for zip::ZipReader. | 155 // Callbacks for zip::ZipReader. |
155 void OnUnzipSuccess(); | 156 void OnUnzipSuccess(); |
(...skipping 17 matching lines...) Expand all Loading... |
173 | 174 |
174 // CleanUp operations that must be run. All these functions are run on the | 175 // CleanUp operations that must be run. All these functions are run on the |
175 // FILE thread. | 176 // FILE thread. |
176 std::vector<base::Closure> cleanup_functions_; | 177 std::vector<base::Closure> cleanup_functions_; |
177 }; | 178 }; |
178 | 179 |
179 } // namespace image_writer | 180 } // namespace image_writer |
180 } // namespace extensions | 181 } // namespace extensions |
181 | 182 |
182 #endif // CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_OPERATION_H_ | 183 #endif // CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_OPERATION_H_ |
OLD | NEW |