summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/api/image_writer_private/operation.h
diff options
context:
space:
mode:
authorhaven@google.com <haven@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-21 03:59:32 +0000
committerhaven@google.com <haven@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-21 03:59:32 +0000
commit22c4f736fb51b5ebafb15f93aa431ca1a46868ca (patch)
treee61e298d480e4653174a56499a2616d68e811b75 /chrome/browser/extensions/api/image_writer_private/operation.h
parent3427a9c9c714562fbc800a741e70244f1c767d2b (diff)
downloadchromium_src-22c4f736fb51b5ebafb15f93aa431ca1a46868ca.zip
chromium_src-22c4f736fb51b5ebafb15f93aa431ca1a46868ca.tar.gz
chromium_src-22c4f736fb51b5ebafb15f93aa431ca1a46868ca.tar.bz2
Implements Image Writer API for ChromeOS.
BUG=279327 Review URL: https://chromiumcodereview.appspot.com/23785007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@224553 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/api/image_writer_private/operation.h')
-rw-r--r--chrome/browser/extensions/api/image_writer_private/operation.h75
1 files changed, 47 insertions, 28 deletions
diff --git a/chrome/browser/extensions/api/image_writer_private/operation.h b/chrome/browser/extensions/api/image_writer_private/operation.h
index 5cc06f2..17a88e9 100644
--- a/chrome/browser/extensions/api/image_writer_private/operation.h
+++ b/chrome/browser/extensions/api/image_writer_private/operation.h
@@ -8,6 +8,7 @@
#include "base/callback.h"
#include "base/md5.h"
#include "base/memory/ref_counted_memory.h"
+#include "base/memory/weak_ptr.h"
#include "base/timer/timer.h"
#include "chrome/browser/extensions/api/image_writer_private/image_writer_utils.h"
#include "chrome/common/cancelable_task_tracker.h"
@@ -16,14 +17,14 @@
namespace image_writer_api = extensions::api::image_writer_private;
namespace base {
-
class FilePath;
-
-} // namespace base
+} // namespace base
namespace extensions {
namespace image_writer {
+const int kProgressComplete = 100;
+
class OperationManager;
// Encapsulates an operation being run on behalf of the
@@ -43,7 +44,7 @@ class Operation
typedef base::Callback<void(bool, const std::string&)> CancelWriteCallback;
typedef std::string ExtensionId;
- Operation(OperationManager* manager,
+ Operation(base::WeakPtr<OperationManager> manager,
const ExtensionId& extension_id,
const std::string& storage_unit_id);
@@ -52,12 +53,11 @@ class Operation
// Cancel the operation. This must be called to clean up internal state and
// cause the the operation to actually stop. It will not be destroyed until
- // all callbacks have completed. This method may be overridden to provide
- // subclass cancelling. It should still call the superclass method.
- virtual void Cancel();
+ // all callbacks have completed.
+ void Cancel();
// Aborts the operation, cancelling it and generating an error.
- virtual void Abort();
+ void Abort();
protected:
virtual ~Operation();
@@ -65,12 +65,21 @@ class Operation
// |error_message| is used to create an OnWriteError event which is
// sent to the extension
virtual void Error(const std::string& error_message);
- // Sends a progress notification.
- void SendProgress();
+
+ // Set |progress_| and send an event. Progress should be in the interval
+ // [0,100]
+ void SetProgress(int progress);
+ // Change to a new |stage_| and set |progress_| to zero.
+ void SetStage(image_writer_api::Stage stage);
// Can be queried to safely determine if the operation has been cancelled.
bool IsCancelled();
+ // Adds a callback that will be called during clean-up, whether the operation
+ // is aborted, encounters and error, or finishes successfully. These
+ // functions will be run on the FILE thread.
+ void AddCleanUpFunction(base::Closure);
+
void UnzipStart(scoped_ptr<base::FilePath> zip_file);
void WriteStart();
void VerifyWriteStart();
@@ -89,34 +98,21 @@ class Operation
int progress_scale,
const base::Callback<void(scoped_ptr<std::string>)>& callback);
- OperationManager* manager_;
+ base::WeakPtr<OperationManager> manager_;
const ExtensionId extension_id_;
- // This field is owned by the UI thread.
- image_writer_api::Stage stage_;
-
- // The amount of work completed for the current stage as a percentage. This
- // variable may be modified by both the FILE and UI threads, but it is only
- // modified by the basic activity flow of the operation which is logically
- // single threaded. Progress events will read this variable from the UI
- // thread which has the potential to read a value newer than when the event
- // was posted. However, the stage is never advanced except on the UI thread
- // and so will be later in the queue than those progress events. Thus
- // progress events may report higher progress numbers than when queued, but
- // will never report the wrong stage and appear to move backwards.
- int progress_;
-
base::FilePath image_path_;
const std::string storage_unit_id_;
private:
friend class base::RefCountedThreadSafe<Operation>;
+ // TODO(haven): Clean up these switches. http://crbug.com/292956
#if defined(OS_LINUX) && !defined(CHROMEOS)
void WriteRun();
void WriteChunk(scoped_ptr<image_writer_utils::ImageReader> reader,
scoped_ptr<image_writer_utils::ImageWriter> writer,
int64 bytes_written);
- bool WriteCleanup(scoped_ptr<image_writer_utils::ImageReader> reader,
+ bool WriteCleanUp(scoped_ptr<image_writer_utils::ImageReader> reader,
scoped_ptr<image_writer_utils::ImageWriter> writer);
void WriteComplete();
@@ -125,6 +121,18 @@ class Operation
scoped_ptr<std::string> device_hash);
#endif
+#if defined(OS_CHROMEOS)
+ void StartWriteOnUIThread();
+
+ void OnBurnFinished(const std::string& target_path,
+ bool success,
+ const std::string& error);
+ void OnBurnProgress(const std::string& target_path,
+ int64 num_bytes_burnt,
+ int64 total_size);
+ void OnBurnError();
+#endif
+
void MD5Chunk(scoped_ptr<image_writer_utils::ImageReader> reader,
int64 bytes_processed,
int64 bytes_total,
@@ -132,13 +140,24 @@ class Operation
int progress_scale,
const base::Callback<void(scoped_ptr<std::string>)>& callback);
+ // Runs all cleanup functions.
+ void CleanUp();
+
+ // |stage_| and |progress_| are owned by the FILE thread, use |SetStage| and
+ // |SetProgress| to update. Progress should be in the interval [0,100]
+ image_writer_api::Stage stage_;
+ int progress_;
+
// MD5 contexts don't play well with smart pointers. Just going to allocate
// memory here. This requires that we only do one MD5 sum at a time.
base::MD5Context md5_context_;
+ // CleanUp operations that must be run. All these functions are run on the
+ // FILE thread.
+ std::vector<base::Closure> cleanup_functions_;
};
-} // namespace image_writer
-} // namespace extensions
+} // namespace image_writer
+} // namespace extensions
#endif // CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_OPERATION_H_