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

Unified Diff: chrome/browser/extensions/api/image_writer_private/write_from_url_operation.h

Issue 170123002: Revert of Significantly cleans up the ImageWriter Operation class and subclasses. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 10 months 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/extensions/api/image_writer_private/write_from_url_operation.h
diff --git a/chrome/browser/extensions/api/image_writer_private/write_from_url_operation.h b/chrome/browser/extensions/api/image_writer_private/write_from_url_operation.h
index eb87b0c758f3a2486f358d8e6d6e55c47d240594..ee2374c3f0fff3223aa1d0ce52fc6052b6f306b0 100644
--- a/chrome/browser/extensions/api/image_writer_private/write_from_url_operation.h
+++ b/chrome/browser/extensions/api/image_writer_private/write_from_url_operation.h
@@ -5,13 +5,17 @@
#ifndef CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_WRITE_FROM_URL_OPERATION_H_
#define CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_WRITE_FROM_URL_OPERATION_H_
+#include "base/scoped_observer.h"
#include "chrome/browser/extensions/api/image_writer_private/operation.h"
-#include "net/url_request/url_fetcher_delegate.h"
+#include "content/public/browser/download_interrupt_reasons.h"
+#include "content/public/browser/download_item.h"
#include "url/gurl.h"
-namespace net {
-class URLFetcher;
-} // namespace net
+namespace content {
+
+class RenderViewHost;
+
+} // namespace content
namespace extensions {
namespace image_writer {
@@ -19,57 +23,44 @@
class OperationManager;
// Encapsulates a write of an image accessed via URL.
-class WriteFromUrlOperation : public Operation, public net::URLFetcherDelegate {
+class WriteFromUrlOperation : public Operation,
+ public content::DownloadItem::Observer {
public:
WriteFromUrlOperation(base::WeakPtr<OperationManager> manager,
const ExtensionId& extension_id,
- net::URLRequestContextGetter* request_context,
+ content::RenderViewHost* rvh,
GURL url,
const std::string& hash,
+ bool saveImageAsDownload,
const std::string& storage_unit_id);
- virtual void StartImpl() OVERRIDE;
+ virtual void Start() OVERRIDE;
+ private:
+ virtual ~WriteFromUrlOperation();
+ void CreateTempFile();
- protected:
- virtual ~WriteFromUrlOperation();
+ void DownloadStart();
+ void OnDownloadStarted(content::DownloadItem*,
+ content::DownloadInterruptReason interrupt_reason);
+ virtual void OnDownloadUpdated(content::DownloadItem* download) OVERRIDE;
+ void DownloadComplete();
+ void DownloadCleanUp();
- // Sets the image_path to the correct location to download to.
- void GetDownloadTarget(const base::Closure& continuation);
-
- // Downloads the |url| to the currently configured |image_path|. Should not
- // be called without calling |GetDownloadTarget| first.
- void Download(const base::Closure& continuation);
-
- // Verifies the download matches |hash|. If the hash is empty, this stage is
- // skipped.
- void VerifyDownload(const base::Closure& continuation);
-
- private:
- // Destroys the URLFetcher. The URLFetcher needs to be destroyed on the same
- // thread it was created on. The Operation may be deleted on the UI thread
- // and so we must first delete the URLFetcher on the FILE thread.
- void DestroyUrlFetcher();
-
- // URLFetcherDelegate implementation.
- virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
- virtual void OnURLFetchDownloadProgress(const net::URLFetcher* source,
- int64 current,
- int64 total) OVERRIDE;
- virtual void OnURLFetchUploadProgress(const net::URLFetcher* source,
- int64 current,
- int64 total) OVERRIDE;
-
- void VerifyDownloadCompare(const base::Closure& continuation,
- const std::string& download_hash);
- void VerifyDownloadComplete(const base::Closure& continuation);
+ void VerifyDownloadStart();
+ void VerifyDownloadRun();
+ void VerifyDownloadCompare(scoped_ptr<std::string> download_hash);
+ void VerifyDownloadComplete();
// Arguments
- net::URLRequestContextGetter* request_context_;
+ content::RenderViewHost* rvh_;
GURL url_;
const std::string hash_;
+ const bool saveImageAsDownload_;
// Local state
- scoped_ptr<net::URLFetcher> url_fetcher_;
- base::Closure download_continuation_;
+ scoped_ptr<base::FilePath> tmp_file_;
+ bool download_stopped_;
+ content::DownloadItem* download_;
+ base::FilePath download_path_;
};
} // namespace image_writer

Powered by Google App Engine
This is Rietveld 408576698