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_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 "chrome/browser/extensions/api/image_writer_private/operation.h" | 8 #include "chrome/browser/extensions/api/image_writer_private/operation.h" |
9 #include "net/url_request/url_fetcher_delegate.h" | 9 #include "net/url_request/url_fetcher_delegate.h" |
10 #include "url/gurl.h" | 10 #include "url/gurl.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 | 21 |
22 // Encapsulates a write of an image accessed via URL. | 22 // Encapsulates a write of an image accessed via URL. |
23 class WriteFromUrlOperation : public Operation, public net::URLFetcherDelegate { | 23 class WriteFromUrlOperation : public Operation, public net::URLFetcherDelegate { |
24 public: | 24 public: |
25 WriteFromUrlOperation(base::WeakPtr<OperationManager> manager, | 25 WriteFromUrlOperation(base::WeakPtr<OperationManager> manager, |
26 const ExtensionId& extension_id, | 26 const ExtensionId& extension_id, |
27 net::URLRequestContextGetter* request_context, | 27 net::URLRequestContextGetter* request_context, |
28 GURL url, | 28 GURL url, |
29 const std::string& hash, | 29 const std::string& hash, |
30 const std::string& storage_unit_id); | 30 const std::string& storage_unit_id); |
31 virtual void StartImpl() OVERRIDE; | 31 virtual void StartImpl() override; |
32 | 32 |
33 protected: | 33 protected: |
34 virtual ~WriteFromUrlOperation(); | 34 virtual ~WriteFromUrlOperation(); |
35 | 35 |
36 // Sets the image_path to the correct location to download to. | 36 // Sets the image_path to the correct location to download to. |
37 void GetDownloadTarget(const base::Closure& continuation); | 37 void GetDownloadTarget(const base::Closure& continuation); |
38 | 38 |
39 // Downloads the |url| to the currently configured |image_path|. Should not | 39 // Downloads the |url| to the currently configured |image_path|. Should not |
40 // be called without calling |GetDownloadTarget| first. | 40 // be called without calling |GetDownloadTarget| first. |
41 void Download(const base::Closure& continuation); | 41 void Download(const base::Closure& continuation); |
42 | 42 |
43 // Verifies the download matches |hash|. If the hash is empty, this stage is | 43 // Verifies the download matches |hash|. If the hash is empty, this stage is |
44 // skipped. | 44 // skipped. |
45 void VerifyDownload(const base::Closure& continuation); | 45 void VerifyDownload(const base::Closure& continuation); |
46 | 46 |
47 private: | 47 private: |
48 // Destroys the URLFetcher. The URLFetcher needs to be destroyed on the same | 48 // Destroys the URLFetcher. The URLFetcher needs to be destroyed on the same |
49 // thread it was created on. The Operation may be deleted on the UI thread | 49 // thread it was created on. The Operation may be deleted on the UI thread |
50 // and so we must first delete the URLFetcher on the FILE thread. | 50 // and so we must first delete the URLFetcher on the FILE thread. |
51 void DestroyUrlFetcher(); | 51 void DestroyUrlFetcher(); |
52 | 52 |
53 // URLFetcherDelegate implementation. | 53 // URLFetcherDelegate implementation. |
54 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 54 virtual void OnURLFetchComplete(const net::URLFetcher* source) override; |
55 virtual void OnURLFetchDownloadProgress(const net::URLFetcher* source, | 55 virtual void OnURLFetchDownloadProgress(const net::URLFetcher* source, |
56 int64 current, | 56 int64 current, |
57 int64 total) OVERRIDE; | 57 int64 total) override; |
58 virtual void OnURLFetchUploadProgress(const net::URLFetcher* source, | 58 virtual void OnURLFetchUploadProgress(const net::URLFetcher* source, |
59 int64 current, | 59 int64 current, |
60 int64 total) OVERRIDE; | 60 int64 total) override; |
61 | 61 |
62 void VerifyDownloadCompare(const base::Closure& continuation, | 62 void VerifyDownloadCompare(const base::Closure& continuation, |
63 const std::string& download_hash); | 63 const std::string& download_hash); |
64 void VerifyDownloadComplete(const base::Closure& continuation); | 64 void VerifyDownloadComplete(const base::Closure& continuation); |
65 | 65 |
66 // Arguments | 66 // Arguments |
67 net::URLRequestContextGetter* request_context_; | 67 net::URLRequestContextGetter* request_context_; |
68 GURL url_; | 68 GURL url_; |
69 const std::string hash_; | 69 const std::string hash_; |
70 | 70 |
71 // Local state | 71 // Local state |
72 scoped_ptr<net::URLFetcher> url_fetcher_; | 72 scoped_ptr<net::URLFetcher> url_fetcher_; |
73 base::Closure download_continuation_; | 73 base::Closure download_continuation_; |
74 }; | 74 }; |
75 | 75 |
76 } // namespace image_writer | 76 } // namespace image_writer |
77 } // namespace extensions | 77 } // namespace extensions |
78 | 78 |
79 #endif // CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_WRITE_FROM_URL_OPE
RATION_H_ | 79 #endif // CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_WRITE_FROM_URL_OPE
RATION_H_ |
OLD | NEW |