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 #include "components/offline_pages/offline_page_test_archiver.h" | 5 #include "components/offline_pages/offline_page_test_archiver.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 create_archive_called_ = true; | 36 create_archive_called_ = true; |
37 callback_ = callback; | 37 callback_ = callback; |
38 archives_dir_ = archives_dir; | 38 archives_dir_ = archives_dir; |
39 if (!delayed_) | 39 if (!delayed_) |
40 CompleteCreateArchive(); | 40 CompleteCreateArchive(); |
41 } | 41 } |
42 | 42 |
43 void OfflinePageTestArchiver::CompleteCreateArchive() { | 43 void OfflinePageTestArchiver::CompleteCreateArchive() { |
44 DCHECK(!callback_.is_null()); | 44 DCHECK(!callback_.is_null()); |
45 base::FilePath archive_path; | 45 base::FilePath archive_path; |
46 ASSERT_TRUE(base::CreateTemporaryFileInDir(archives_dir_, &archive_path)); | 46 if (filename_.empty()) { |
| 47 ASSERT_TRUE(base::CreateTemporaryFileInDir(archives_dir_, &archive_path)); |
| 48 } else { |
| 49 archive_path = archives_dir_.Append(filename_); |
| 50 // This step ensures the file is created and closed immediately. |
| 51 base::File file(archive_path, base::File::FLAG_OPEN_ALWAYS); |
| 52 } |
47 observer_->SetLastPathCreatedByArchiver(archive_path); | 53 observer_->SetLastPathCreatedByArchiver(archive_path); |
48 task_runner_->PostTask(FROM_HERE, base::Bind(callback_, this, result_, url_, | 54 task_runner_->PostTask(FROM_HERE, base::Bind(callback_, this, result_, url_, |
49 archive_path, size_to_report_)); | 55 archive_path, size_to_report_)); |
50 } | 56 } |
51 | 57 |
52 } // namespace offline_pages | 58 } // namespace offline_pages |
OLD | NEW |