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/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/browser/image_writer/image_writer.h" | |
14 #include "chrome/common/cancelable_task_tracker.h" | 15 #include "chrome/common/cancelable_task_tracker.h" |
15 #include "chrome/common/extensions/api/image_writer_private.h" | 16 #include "chrome/common/extensions/api/image_writer_private.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 base::RefCountedThreadSafe<Operation>, |
43 public ImageWriter::Delegate { | |
42 public: | 44 public: |
43 typedef base::Callback<void(bool, const std::string&)> StartWriteCallback; | 45 typedef base::Callback<void(bool, const std::string&)> StartWriteCallback; |
44 typedef base::Callback<void(bool, const std::string&)> CancelWriteCallback; | 46 typedef base::Callback<void(bool, const std::string&)> CancelWriteCallback; |
45 typedef std::string ExtensionId; | 47 typedef std::string ExtensionId; |
46 | 48 |
47 Operation(base::WeakPtr<OperationManager> manager, | 49 Operation(base::WeakPtr<OperationManager> manager, |
48 const ExtensionId& extension_id, | 50 const ExtensionId& extension_id, |
49 const std::string& storage_unit_id); | 51 const std::string& storage_unit_id); |
50 | 52 |
51 // Starts the operation. | 53 // Starts the operation. |
52 virtual void Start() = 0; | 54 virtual void Start() = 0; |
53 | 55 |
54 // Cancel the operation. This must be called to clean up internal state and | 56 // Cancel the operation. This must be called to clean up internal state and |
55 // cause the the operation to actually stop. It will not be destroyed until | 57 // cause the the operation to actually stop. It will not be destroyed until |
56 // all callbacks have completed. | 58 // all callbacks have completed. |
57 void Cancel(); | 59 void Cancel(); |
58 | 60 |
59 // Aborts the operation, cancelling it and generating an error. | 61 // Aborts the operation, cancelling it and generating an error. |
60 void Abort(); | 62 void Abort(); |
63 | |
64 virtual void OnWriteImageSucceeded() OVERRIDE; | |
jam
2013/11/21 19:36:41
nit: convention is to put add
// ImageWriter::Del
Drew Haven
2013/11/26 02:10:43
Done. I didn't realize you could put public metho
| |
65 virtual void OnWriteImageFailed(const std::string& message) OVERRIDE; | |
66 virtual void OnWriteImageProgress(int progress) OVERRIDE; | |
61 protected: | 67 protected: |
62 virtual ~Operation(); | 68 virtual ~Operation(); |
63 | 69 |
64 // Generates an error. | 70 // Generates an error. |
65 // |error_message| is used to create an OnWriteError event which is | 71 // |error_message| is used to create an OnWriteError event which is |
66 // sent to the extension | 72 // sent to the extension |
67 virtual void Error(const std::string& error_message); | 73 virtual void Error(const std::string& error_message); |
68 | 74 |
69 // Set |progress_| and send an event. Progress should be in the interval | 75 // Set |progress_| and send an event. Progress should be in the interval |
70 // [0,100] | 76 // [0,100] |
(...skipping 30 matching lines...) Expand all Loading... | |
101 base::WeakPtr<OperationManager> manager_; | 107 base::WeakPtr<OperationManager> manager_; |
102 const ExtensionId extension_id_; | 108 const ExtensionId extension_id_; |
103 | 109 |
104 base::FilePath image_path_; | 110 base::FilePath image_path_; |
105 const std::string storage_unit_id_; | 111 const std::string storage_unit_id_; |
106 private: | 112 private: |
107 friend class base::RefCountedThreadSafe<Operation>; | 113 friend class base::RefCountedThreadSafe<Operation>; |
108 | 114 |
109 // TODO(haven): Clean up these switches. http://crbug.com/292956 | 115 // TODO(haven): Clean up these switches. http://crbug.com/292956 |
110 #if defined(OS_LINUX) && !defined(CHROMEOS) | 116 #if defined(OS_LINUX) && !defined(CHROMEOS) |
111 void WriteRun(); | |
112 void WriteChunk(scoped_ptr<image_writer_utils::ImageReader> reader, | |
113 scoped_ptr<image_writer_utils::ImageWriter> writer, | |
114 int64 bytes_written); | |
115 bool WriteCleanUp(scoped_ptr<image_writer_utils::ImageReader> reader, | |
116 scoped_ptr<image_writer_utils::ImageWriter> writer); | |
117 void WriteComplete(); | |
118 | |
119 void VerifyWriteStage2(scoped_ptr<std::string> image_hash); | |
120 void VerifyWriteCompare(scoped_ptr<std::string> image_hash, | |
121 scoped_ptr<std::string> device_hash); | |
122 #endif | 117 #endif |
123 | 118 |
124 #if defined(OS_CHROMEOS) | 119 #if defined(OS_CHROMEOS) |
125 void StartWriteOnUIThread(); | 120 void StartWriteOnUIThread(); |
126 | 121 |
127 void OnBurnFinished(const std::string& target_path, | 122 void OnBurnFinished(const std::string& target_path, |
128 bool success, | 123 bool success, |
129 const std::string& error); | 124 const std::string& error); |
130 void OnBurnProgress(const std::string& target_path, | 125 void OnBurnProgress(const std::string& target_path, |
131 int64 num_bytes_burnt, | 126 int64 num_bytes_burnt, |
(...skipping 22 matching lines...) Expand all Loading... | |
154 | 149 |
155 // CleanUp operations that must be run. All these functions are run on the | 150 // CleanUp operations that must be run. All these functions are run on the |
156 // FILE thread. | 151 // FILE thread. |
157 std::vector<base::Closure> cleanup_functions_; | 152 std::vector<base::Closure> cleanup_functions_; |
158 }; | 153 }; |
159 | 154 |
160 } // namespace image_writer | 155 } // namespace image_writer |
161 } // namespace extensions | 156 } // namespace extensions |
162 | 157 |
163 #endif // CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_OPERATION_H_ | 158 #endif // CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_OPERATION_H_ |
OLD | NEW |