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_interrupt_reasons.h"
11 #include "content/public/browser/download_item.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*,
43 content::DownloadInterruptReason interrupt_reason);
44 virtual void OnDownloadUpdated(content::DownloadItem* download) OVERRIDE;
45 void DownloadComplete();
46 void DownloadCleanUp();
48 void VerifyDownloadStart();
49 void VerifyDownloadRun();
50 void VerifyDownloadCompare(scoped_ptr<std::string> download_hash);
51 void VerifyDownloadComplete();
54 content::RenderViewHost* rvh_;
56 const std::string hash_;
57 const bool saveImageAsDownload_;
60 scoped_ptr<base::FilePath> tmp_file_;
61 bool download_stopped_;
62 content::DownloadItem* download_;
63 base::FilePath download_path_;
66 } // namespace image_writer
67 } // namespace extensions
69 #endif // CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_WRITE_FROM_URL_OPERATION_H_