OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_TEST_ARCHIVER_H_ | 5 #ifndef COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_TEST_ARCHIVER_H_ |
6 #define COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_TEST_ARCHIVER_H_ | 6 #define COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_TEST_ARCHIVER_H_ |
7 | 7 |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
11 #include "components/offline_pages/offline_page_archiver.h" | 11 #include "components/offline_pages/offline_page_archiver.h" |
12 | 12 |
13 class GURL; | 13 class GURL; |
14 | 14 |
15 namespace base { | 15 namespace base { |
16 class FilePath; | 16 class FilePath; |
17 } // namespace | 17 } // namespace |
18 | 18 |
19 namespace offline_pages { | 19 namespace offline_pages { |
20 | 20 |
21 // A test archiver class, which allows for testing offline pages without a need | 21 // A test archiver class, which allows for testing offline pages without a need |
22 // for an actual web contents. | 22 // for an actual web contents. |
23 class OfflinePageTestArchiver : public OfflinePageArchiver { | 23 class OfflinePageTestArchiver : public OfflinePageArchiver { |
24 public: | 24 public: |
| 25 // TODO(fgorski): Try refactoring the observer out and replace it with a |
| 26 // callback, or completely remove the call to |SetLastPathCreatedByArchiver|. |
25 class Observer { | 27 class Observer { |
26 public: | 28 public: |
27 virtual ~Observer() {} | 29 virtual ~Observer() {} |
28 virtual void SetLastPathCreatedByArchiver( | 30 virtual void SetLastPathCreatedByArchiver( |
29 const base::FilePath& file_path) = 0; | 31 const base::FilePath& file_path) = 0; |
30 }; | 32 }; |
31 | 33 |
32 OfflinePageTestArchiver( | 34 OfflinePageTestArchiver( |
33 Observer* observer, | 35 Observer* observer, |
34 const GURL& url, | 36 const GURL& url, |
35 ArchiverResult result, | 37 ArchiverResult result, |
36 int64 size_to_report, | 38 int64 size_to_report, |
37 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner); | 39 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner); |
38 ~OfflinePageTestArchiver() override; | 40 ~OfflinePageTestArchiver() override; |
39 | 41 |
40 // OfflinePageArchiver implementation: | 42 // OfflinePageArchiver implementation: |
41 void CreateArchive(const base::FilePath& archives_dir, | 43 void CreateArchive(const base::FilePath& archives_dir, |
42 const CreateArchiveCallback& callback) override; | 44 const CreateArchiveCallback& callback) override; |
43 | 45 |
44 // Completes the creation of archive. Should be used with |set_delayed| set to | 46 // Completes the creation of archive. Should be used with |set_delayed| set to |
45 // ture. | 47 // ture. |
46 void CompleteCreateArchive(); | 48 void CompleteCreateArchive(); |
47 | 49 |
48 // When set to true, |CompleteCreateArchive| should be called explicitly for | 50 // When set to true, |CompleteCreateArchive| should be called explicitly for |
49 // the process to finish. | 51 // the process to finish. |
| 52 // TODO(fgorski): See if we can move this to the constructor. |
50 void set_delayed(bool delayed) { delayed_ = delayed; } | 53 void set_delayed(bool delayed) { delayed_ = delayed; } |
51 | 54 |
| 55 // Allows to explicitly specify a file name for the tests. |
| 56 // TODO(fgorski): See if we can move this to the constructor. |
| 57 void set_filename(const base::FilePath& filename) { filename_ = filename; } |
| 58 |
52 bool create_archive_called() const { return create_archive_called_; } | 59 bool create_archive_called() const { return create_archive_called_; } |
53 | 60 |
54 private: | 61 private: |
55 // Not owned. Outlives OfflinePageTestArchiver. | 62 // Not owned. Outlives OfflinePageTestArchiver. |
56 Observer* observer_; | 63 Observer* observer_; |
57 GURL url_; | 64 GURL url_; |
58 base::FilePath archives_dir_; | 65 base::FilePath archives_dir_; |
| 66 base::FilePath filename_; |
59 ArchiverResult result_; | 67 ArchiverResult result_; |
60 int64 size_to_report_; | 68 int64 size_to_report_; |
61 bool create_archive_called_; | 69 bool create_archive_called_; |
62 bool delayed_; | 70 bool delayed_; |
63 CreateArchiveCallback callback_; | 71 CreateArchiveCallback callback_; |
64 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 72 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
65 | 73 |
66 DISALLOW_COPY_AND_ASSIGN(OfflinePageTestArchiver); | 74 DISALLOW_COPY_AND_ASSIGN(OfflinePageTestArchiver); |
67 }; | 75 }; |
68 | 76 |
69 } // namespace offline_pages | 77 } // namespace offline_pages |
70 | 78 |
71 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_TEST_ARCHIVER_H_ | 79 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_TEST_ARCHIVER_H_ |
OLD | NEW |