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 "base/scoped_observer.h"
9 #include "chrome/browser/extensions/api/image_writer_private/operation.h"
10 #include "content/public/browser/download_item.h"
11 #include "net/base/net_errors.h"
18 } // namespace content
20 namespace extensions {
21 namespace image_writer {
23 class OperationManager;
25 // Encapsulates a write of an image accessed via URL.
26 class WriteFromUrlOperation : public Operation,
27 public content::DownloadItem::Observer {
29 WriteFromUrlOperation(base::WeakPtr<OperationManager> manager,
30 const ExtensionId& extension_id,
31 content::RenderViewHost* rvh,
33 const std::string& hash,
34 bool saveImageAsDownload,
35 const std::string& storage_unit_id);
36 virtual void Start() OVERRIDE;
38 virtual ~WriteFromUrlOperation();
39 void CreateTempFile();
42 void OnDownloadStarted(content::DownloadItem*, net::Error);
43 virtual void OnDownloadUpdated(content::DownloadItem* download) OVERRIDE;
44 void DownloadComplete();
45 void DownloadCleanUp();
47 void VerifyDownloadStart();
48 void VerifyDownloadRun();
49 void VerifyDownloadCompare(scoped_ptr<std::string> download_hash);
50 void VerifyDownloadComplete();
53 content::RenderViewHost* rvh_;
55 const std::string hash_;
56 const bool saveImageAsDownload_;
59 scoped_ptr<base::FilePath> tmp_file_;
60 bool download_stopped_;
61 content::DownloadItem* download_;
62 base::FilePath download_path_;
65 } // namespace image_writer
66 } // namespace extensions
68 #endif // CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_WRITE_FROM_URL_OPERATION_H_