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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_WRITE_FROM_URL_OPERATION_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_WRITE_FROM_URL_OPERATION_H_
8 #include "chrome/browser/extensions/api/image_writer_private/operation.h"
9 #include "net/url_request/url_fetcher_delegate.h"
14 class URLRequestContextGetter
;
17 namespace extensions
{
18 namespace image_writer
{
20 class OperationManager
;
22 // Encapsulates a write of an image accessed via URL.
23 class WriteFromUrlOperation
: public Operation
, public net::URLFetcherDelegate
{
25 WriteFromUrlOperation(base::WeakPtr
<OperationManager
> manager
,
26 const ExtensionId
& extension_id
,
27 net::URLRequestContextGetter
* request_context
,
29 const std::string
& hash
,
30 const std::string
& storage_unit_id
);
31 void StartImpl() override
;
34 ~WriteFromUrlOperation() override
;
36 // Sets the image_path to the correct location to download to.
37 void GetDownloadTarget(const base::Closure
& continuation
);
39 // Downloads the |url| to the currently configured |image_path|. Should not
40 // be called without calling |GetDownloadTarget| first.
41 void Download(const base::Closure
& continuation
);
43 // Verifies the download matches |hash|. If the hash is empty, this stage is
45 void VerifyDownload(const base::Closure
& continuation
);
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
50 // and so we must first delete the URLFetcher on the FILE thread.
51 void DestroyUrlFetcher();
53 // URLFetcherDelegate implementation.
54 void OnURLFetchComplete(const net::URLFetcher
* source
) override
;
55 void OnURLFetchDownloadProgress(const net::URLFetcher
* source
,
57 int64 total
) override
;
58 void OnURLFetchUploadProgress(const net::URLFetcher
* source
,
60 int64 total
) override
;
62 void VerifyDownloadCompare(const base::Closure
& continuation
,
63 const std::string
& download_hash
);
64 void VerifyDownloadComplete(const base::Closure
& continuation
);
67 net::URLRequestContextGetter
* request_context_
;
69 const std::string hash_
;
72 scoped_ptr
<net::URLFetcher
> url_fetcher_
;
73 base::Closure download_continuation_
;
76 } // namespace image_writer
77 } // namespace extensions
79 #endif // CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_WRITE_FROM_URL_OPERATION_H_