| OLD | NEW |
| (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 COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_TEST_ARCHIVER_H_ |
| 6 #define COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_TEST_ARCHIVER_H_ |
| 7 |
| 8 #include "base/macros.h" |
| 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/single_thread_task_runner.h" |
| 11 #include "components/offline_pages/offline_page_archiver.h" |
| 12 |
| 13 class GURL; |
| 14 |
| 15 namespace base { |
| 16 class FilePath; |
| 17 } // namespace |
| 18 |
| 19 namespace offline_pages { |
| 20 |
| 21 // A test archiver class, which allows for testing offline pages without a need |
| 22 // for an actual web contents. |
| 23 class OfflinePageTestArchiver : public OfflinePageArchiver { |
| 24 public: |
| 25 class Observer { |
| 26 public: |
| 27 virtual ~Observer() {} |
| 28 virtual void SetLastPathCreatedByArchiver( |
| 29 const base::FilePath& file_path) = 0; |
| 30 }; |
| 31 |
| 32 OfflinePageTestArchiver( |
| 33 Observer* observer, |
| 34 const GURL& url, |
| 35 ArchiverResult result, |
| 36 int64 size_to_report, |
| 37 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner); |
| 38 ~OfflinePageTestArchiver() override; |
| 39 |
| 40 // OfflinePageArchiver implementation: |
| 41 void CreateArchive(const base::FilePath& archives_dir, |
| 42 const CreateArchiveCallback& callback) override; |
| 43 |
| 44 // Completes the creation of archive. Should be used with |set_delayed| set to |
| 45 // ture. |
| 46 void CompleteCreateArchive(); |
| 47 |
| 48 // When set to true, |CompleteCreateArchive| should be called explicitly for |
| 49 // the process to finish. |
| 50 void set_delayed(bool delayed) { delayed_ = delayed; } |
| 51 |
| 52 bool create_archive_called() const { return create_archive_called_; } |
| 53 |
| 54 private: |
| 55 // Not owned. Outlives OfflinePageTestArchiver. |
| 56 Observer* observer_; |
| 57 GURL url_; |
| 58 base::FilePath archives_dir_; |
| 59 ArchiverResult result_; |
| 60 int64 size_to_report_; |
| 61 bool create_archive_called_; |
| 62 bool delayed_; |
| 63 CreateArchiveCallback callback_; |
| 64 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 65 |
| 66 DISALLOW_COPY_AND_ASSIGN(OfflinePageTestArchiver); |
| 67 }; |
| 68 |
| 69 } // namespace offline_pages |
| 70 |
| 71 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_TEST_ARCHIVER_H_ |
| OLD | NEW |