Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(255)

Side by Side Diff: chrome/browser/offline_pages/offline_page_mhtml_archiver.h

Issue 1236403003: [Offline pages] Moving browser code to android path (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Narrowing the move to archiver only due to another patch moving the rest ot components Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #ifndef CHROME_BROWSER_OFFLINE_PAGES_OFFLINE_PAGE_MHTML_ARCHIVER_H_
6 #define CHROME_BROWSER_OFFLINE_PAGES_OFFLINE_PAGE_MHTML_ARCHIVER_H_
7
8 #include <map>
9
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"
14
15 namespace base {
16 class FilePath;
17 class SingleThreadTaskRunner;
18 } // namespace base
19
20 namespace content {
21 class WebContents;
22 } // namespace content
23
24 namespace offline_pages {
25 class TestMHTMLArchiver;
26
27 // Class implementing an offline page archiver using MHTML as an archive format.
28 //
29 // To generate an MHTML archiver for a given URL, a WebContents instance should
30 // have that URL loaded.
31 //
32 // Example:
33 // void SavePageOffline(content::WebContents* web_contents) {
34 // const GURL& url = web_contents->GetLastCommittedURL();
35 // scoped_ptr<OfflinePageMHTMLArchiver> archiver(
36 // new OfflinePageMHTMLArchiver(
37 // web_contents, archiver_dir, task_runner));
38 // // Callback is of type OfflinePageModel::SavePageCallback.
39 // model->SavePage(url, archiver.Pass(), callback);
40 // }
41 class OfflinePageMHTMLArchiver : public OfflinePageArchiver {
42 public:
43 OfflinePageMHTMLArchiver(
44 content::WebContents* web_contents,
45 const base::FilePath& file_path,
46 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner);
47 ~OfflinePageMHTMLArchiver() override;
48
49 // OfflinePageArchiver implementation:
50 void CreateArchive(const CreateArchiveCallback& callback) override;
51
52 private:
53 friend class offline_pages::TestMHTMLArchiver;
54
55 // Allows to overload the archiver for testing.
56 OfflinePageMHTMLArchiver(
57 const base::FilePath& file_path,
58 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner);
59
60 // Sends the result of archiving a page to the client that requested archive
61 // creation.
62 void ReportResult(ArchiverResult result,
63 const GURL& url,
64 const base::string16& title,
65 int64 file_size);
66 void ReportFailure(ArchiverResult result);
67
68 // Checks that |web_contents_| is still valid.
69 virtual bool IsWebContentsValid() const;
70 // Actual call to generate MHTML.
71 virtual void GenerateMHTML();
72 // Callback for Generating MHTML.
73 void OnGenerateMHTMLDone(const GURL& url,
74 const base::string16& title,
75 int64 file_size);
76
77 // Path to the archive file.
78 const base::FilePath file_path_;
79 // Contents of the web page to be serialized. Not owned.
80 // TODO(fgorski): Add WebContentsObserver to know when the page navigates away
81 // or shuts down.
82 content::WebContents* web_contents_;
83
84 CreateArchiveCallback callback_;
85
86 // Task runner, which will be used to post the callback.
87 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
88
89 base::WeakPtrFactory<OfflinePageMHTMLArchiver> weak_ptr_factory_;
90
91 DISALLOW_COPY_AND_ASSIGN(OfflinePageMHTMLArchiver);
92 };
93
94 } // namespace offline_pages
95
96 #endif // CHROME_BROWSER_OFFLINE_PAGES_OFFLINE_PAGE_MHTML_ARCHIVER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698