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

Side by Side Diff: chrome/browser/extensions/api/image_writer_private/write_from_url_operation.h

Issue 149313003: Significantly cleans up the ImageWriter Operation class and subclasses. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixes compilation errors. 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 unified diff | Download patch
OLDNEW
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_WRITE_FROM_URL_OPERAT ION_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_WRITE_FROM_URL_OPERAT ION_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_WRITE_FROM_URL_OPERAT ION_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_WRITE_FROM_URL_OPERAT ION_H_
7 7
8 #include "base/scoped_observer.h"
9 #include "chrome/browser/extensions/api/image_writer_private/operation.h" 8 #include "chrome/browser/extensions/api/image_writer_private/operation.h"
10 #include "content/public/browser/download_interrupt_reasons.h" 9 #include "net/url_request/url_fetcher_delegate.h"
11 #include "content/public/browser/download_item.h"
12 #include "url/gurl.h" 10 #include "url/gurl.h"
13 11
14 namespace content { 12 namespace net {
15 13 class URLFetcher;
16 class RenderViewHost; 14 } // namespace net
17
18 } // namespace content
19 15
20 namespace extensions { 16 namespace extensions {
21 namespace image_writer { 17 namespace image_writer {
22 18
23 class OperationManager; 19 class OperationManager;
24 20
25 // Encapsulates a write of an image accessed via URL. 21 // Encapsulates a write of an image accessed via URL.
26 class WriteFromUrlOperation : public Operation, 22 class WriteFromUrlOperation : public Operation,
27 public content::DownloadItem::Observer { 23 public net::URLFetcherDelegate {
28 public: 24 public:
29 WriteFromUrlOperation(base::WeakPtr<OperationManager> manager, 25 WriteFromUrlOperation(base::WeakPtr<OperationManager> manager,
30 const ExtensionId& extension_id, 26 const ExtensionId& extension_id,
31 content::RenderViewHost* rvh, 27 net::URLRequestContextGetter* request_context,
32 GURL url, 28 GURL url,
33 const std::string& hash, 29 const std::string& hash,
34 bool saveImageAsDownload, 30 bool saveImageAsDownload,
35 const std::string& storage_unit_id); 31 const std::string& storage_unit_id);
36 virtual void Start() OVERRIDE; 32 virtual void Start() OVERRIDE;
33
34 protected:
35 virtual ~WriteFromUrlOperation();
36
37 // Sets the image_path to the correct location to download to.
38 void GetDownloadTarget(const base::Closure& continuation);
39
40 // Downloads the |url| to the currently configured |image_path|. Should not
41 // be called without calling |GetDownloadTarget| first.
42 void Download(const base::Closure& continuation);
43
44 // Verifies the download matches |hash|. If the hash is empty, this stage is
45 // skipped.
46 void VerifyDownload(const base::Closure& continuation);
47
37 private: 48 private:
38 virtual ~WriteFromUrlOperation(); 49 // URLFetcherDelegate implementation.
39 void CreateTempFile(); 50 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
51 virtual void OnURLFetchDownloadProgress(const net::URLFetcher* source,
52 int64 current,
53 int64 total) OVERRIDE;
54 virtual void OnURLFetchUploadProgress(const net::URLFetcher* source,
55 int64 current,
56 int64 total) OVERRIDE;
40 57
41 void DownloadStart();
42 void OnDownloadStarted(content::DownloadItem*,
43 content::DownloadInterruptReason interrupt_reason);
44 virtual void OnDownloadUpdated(content::DownloadItem* download) OVERRIDE;
45 void DownloadComplete();
46 void DownloadCleanUp();
47 58
48 void VerifyDownloadStart(); 59 void VerifyDownloadRun(const base::Closure& continuation);
49 void VerifyDownloadRun(); 60 void VerifyDownloadCompare(const base::Closure& continuation,
50 void VerifyDownloadCompare(scoped_ptr<std::string> download_hash); 61 const std::string& download_hash);
51 void VerifyDownloadComplete(); 62 void VerifyDownloadComplete(const base::Closure& continuation);
52 63
53 // Arguments 64 // Arguments
54 content::RenderViewHost* rvh_; 65 net::URLRequestContextGetter* request_context_;
55 GURL url_; 66 GURL url_;
56 const std::string hash_; 67 const std::string hash_;
57 const bool saveImageAsDownload_; 68 const bool saveImageAsDownload_;
58 69
59 // Local state 70 // Local state
60 scoped_ptr<base::FilePath> tmp_file_; 71 scoped_ptr<net::URLFetcher> url_fetcher_;
61 bool download_stopped_; 72 base::Closure download_continuation_;
62 content::DownloadItem* download_;
63 base::FilePath download_path_;
64 }; 73 };
65 74
66 } // namespace image_writer 75 } // namespace image_writer
67 } // namespace extensions 76 } // namespace extensions
68 77
69 #endif // CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_WRITE_FROM_URL_OPE RATION_H_ 78 #endif // CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_WRITE_FROM_URL_OPE RATION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698