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

Unified Diff: chrome/browser/media_gallery/linux/read_mtp_file_worker.h

Issue 11348337: Move MTPDeviceDelegateImplLinux worker classes to its own files. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: '' Created 8 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/media_gallery/linux/read_mtp_file_worker.h
diff --git a/chrome/browser/media_gallery/linux/read_mtp_file_worker.h b/chrome/browser/media_gallery/linux/read_mtp_file_worker.h
new file mode 100644
index 0000000000000000000000000000000000000000..bbadbdb501ddf5fbcf0557b2604238a49dde4db0
--- /dev/null
+++ b/chrome/browser/media_gallery/linux/read_mtp_file_worker.h
@@ -0,0 +1,125 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_MEDIA_GALLERY_LINUX_READ_MTP_FILE_WORKER_H_
+#define CHROME_BROWSER_MEDIA_GALLERY_LINUX_READ_MTP_FILE_WORKER_H_
+
+#include <string>
+
+#include "base/file_path.h"
+#include "base/memory/ref_counted.h"
+#include "base/sequenced_task_runner_helpers.h"
+#include "base/synchronization/cancellation_flag.h"
+#include "chrome/browser/media_gallery/linux/mtp_device_operations_utils.h"
+
+namespace base {
+class SequencedTaskRunner;
+class WaitableEvent;
+}
+
+namespace chrome {
+
+typedef struct WorkerDeleter<class ReadMTPFileWorker> ReadMTPFileWorkerDeleter;
+
+// Worker class to read media device file data given a file |path|.
+class ReadMTPFileWorker
+ : public base::RefCountedThreadSafe<ReadMTPFileWorker,
+ ReadMTPFileWorkerDeleter> {
+ public:
+ // Constructed on |media_task_runner_| thread.
+ ReadMTPFileWorker(const std::string& handle,
+ const std::string& src_path,
+ uint32 total_size,
+ const FilePath& dest_path,
+ base::SequencedTaskRunner* task_runner,
+ base::WaitableEvent* task_completed_event,
+ base::WaitableEvent* shutdown_event);
+
+ // This function is invoked on |media_task_runner_| to post the task on UI
+ // thread. This blocks the |media_task_runner_| until the task is complete.
+ void Run();
+
+ bool Succeeded() const;
+
+ // Returns the |media_task_runner_| associated with this worker object.
+ // This function is exposed for WorkerDeleter struct to access the
+ // |media_task_runner_|.
+ base::SequencedTaskRunner* media_task_runner() const {
+ return media_task_runner_.get();
+ }
+
+ private:
+ friend struct WorkerDeleter<ReadMTPFileWorker>;
+ friend class base::DeleteHelper<ReadMTPFileWorker>;
+ friend class base::RefCountedThreadSafe<ReadMTPFileWorker,
+ ReadMTPFileWorkerDeleter>;
+
+ // Destructed via ReadMTPFileWorkerDeleter.
+ virtual ~ReadMTPFileWorker();
+
+ // Dispatches a request to MediaTransferProtocolManager to get the media file
+ // contents.
+ void DoWorkOnUIThread();
+
+ // Query callback for DoWorkOnUIThread(). On success, |data| has the media
+ // file contents. On failure, |error| is set to true. This function signals
+ // to unblock |media_task_runner_|.
+ void OnDidWorkOnUIThread(const std::string& data, bool error);
+
+ uint32 BytesToRead() const;
+
+ // The device unique identifier to query the device.
+ const std::string device_handle_;
+
+ // The media device file path.
+ const std::string src_path_;
+
+ // Number of bytes to read.
+ const uint32 total_bytes_;
+
+ // Where to write the data read from the device.
+ const FilePath dest_path_;
+
+ /****************************************************************************
+ * The variables below are accessed on both |media_task_runner_| and the UI
+ * thread. However, there's no concurrent access because the UI thread is in a
+ * blocked state when access occurs on |media_task_runner_|.
+ */
+
+ // Number of bytes read from the device.
+ uint32 bytes_read_;
+
+ // Temporary data storage.
+ std::string data_;
+
+ // Whether an error occurred during file transfer.
+ bool error_occurred_;
+
+ /***************************************************************************/
+
+ // A reference to |media_task_runner_| to destruct this object on the correct
+ // thread.
+ scoped_refptr<base::SequencedTaskRunner> media_task_runner_;
+
+ // |media_task_runner_| can wait on this event until the required operation
+ // is complete.
+ // TODO(kmadhusu): Remove this WaitableEvent after modifying the
+ // DeviceMediaFileUtil functions as asynchronous functions.
+ base::WaitableEvent* on_task_completed_event_;
+
+ // Stores a reference to waitable event associated with the shut down message.
+ base::WaitableEvent* on_shutdown_event_;
+
+ // Set to ignore the request results. This will be set when
+ // MTPDeviceDelegateImplLinux object is about to be deleted.
+ // |on_task_completed_event_| and |on_shutdown_event_| should not be
+ // dereferenced when this is set.
+ base::CancellationFlag cancel_tasks_flag_;
+
+ DISALLOW_COPY_AND_ASSIGN(ReadMTPFileWorker);
+};
+
+} // namespace chrome
+
+#endif // CHROME_BROWSER_MEDIA_GALLERY_LINUX_READ_MTP_FILE_WORKER_H_

Powered by Google App Engine
This is Rietveld 408576698