[sql] Remove _HAS_EXCEPTIONS=0 from build info.
[chromium-blink-merge.git] / chrome / browser / android / offline_pages / offline_page_mhtml_archiver.h
blob4f71ddad172f0752ca7f88a94bf2df998123b3ec
1 // Copyright 2015 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_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_MHTML_ARCHIVER_H_
6 #define CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_MHTML_ARCHIVER_H_
8 #include <map>
10 #include "base/callback.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/weak_ptr.h"
13 #include "components/offline_pages/offline_page_archiver.h"
15 namespace base {
16 class FilePath;
17 class SingleThreadTaskRunner;
18 } // namespace base
20 namespace content {
21 class WebContents;
22 } // namespace content
24 namespace offline_pages {
26 // Class implementing an offline page archiver using MHTML as an archive format.
28 // To generate an MHTML archiver for a given URL, a WebContents instance should
29 // have that URL loaded.
31 // Example:
32 // void SavePageOffline(content::WebContents* web_contents) {
33 // const GURL& url = web_contents->GetLastCommittedURL();
34 // scoped_ptr<OfflinePageMHTMLArchiver> archiver(
35 // new OfflinePageMHTMLArchiver(
36 // web_contents, archive_dir));
37 // // Callback is of type OfflinePageModel::SavePageCallback.
38 // model->SavePage(url, archiver.Pass(), callback);
39 // }
40 class OfflinePageMHTMLArchiver : public OfflinePageArchiver {
41 public:
42 OfflinePageMHTMLArchiver(content::WebContents* web_contents,
43 const base::FilePath& archive_dir);
44 ~OfflinePageMHTMLArchiver() override;
46 // OfflinePageArchiver implementation:
47 void CreateArchive(const CreateArchiveCallback& callback) override;
49 protected:
50 // Allows to overload the archiver for testing.
51 explicit OfflinePageMHTMLArchiver(const base::FilePath& archive_dir);
53 // Try to generate MHTML.
54 // Might be overridden for testing purpose.
55 virtual void GenerateMHTML();
57 // Actual call to generate MHTML.
58 // Might be overridden for testing purpose.
59 virtual void DoGenerateMHTML();
61 // Callback for Generating MHTML.
62 void OnGenerateMHTMLDone(const GURL& url,
63 const base::FilePath& file_path,
64 int64 file_size);
66 // Sends the result of archiving a page to the client that requested archive
67 // creation.
68 void ReportResult(ArchiverResult result,
69 const GURL& url,
70 const base::FilePath& file_path,
71 int64 file_size);
72 void ReportFailure(ArchiverResult result);
74 private:
75 // Path to the archive directory. It the path is empty, creation of the
76 // archive will fail.
77 const base::FilePath archive_dir_;
78 // Contents of the web page to be serialized. Not owned.
79 // TODO(fgorski): Add WebContentsObserver to know when the page navigates away
80 // or shuts down.
81 content::WebContents* web_contents_;
83 CreateArchiveCallback callback_;
85 base::WeakPtrFactory<OfflinePageMHTMLArchiver> weak_ptr_factory_;
87 DISALLOW_COPY_AND_ASSIGN(OfflinePageMHTMLArchiver);
90 } // namespace offline_pages
92 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_MHTML_ARCHIVER_H_