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

Side by Side Diff: components/offline_pages/offline_page_test_archiver.cc

Issue 2489443002: Move all components/offline_pages/ files into component/offline_pages/core (Closed)
Patch Set: rebase Created 4 years 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 #include "components/offline_pages/offline_page_test_archiver.h"
6
7 #include "base/bind.h"
8 #include "base/files/file_util.h"
9 #include "base/location.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "url/gurl.h"
12
13 namespace offline_pages {
14
15 OfflinePageTestArchiver::OfflinePageTestArchiver(
16 Observer* observer,
17 const GURL& url,
18 ArchiverResult result,
19 const base::string16& result_title,
20 int64_t size_to_report,
21 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner)
22 : observer_(observer),
23 url_(url),
24 result_(result),
25 size_to_report_(size_to_report),
26 create_archive_called_(false),
27 delayed_(false),
28 result_title_(result_title),
29 task_runner_(task_runner) {}
30
31 OfflinePageTestArchiver::~OfflinePageTestArchiver() {
32 EXPECT_TRUE(create_archive_called_);
33 }
34
35 void OfflinePageTestArchiver::CreateArchive(
36 const base::FilePath& archives_dir,
37 int64_t archive_id,
38 const CreateArchiveCallback& callback) {
39 create_archive_called_ = true;
40 callback_ = callback;
41 archives_dir_ = archives_dir;
42 if (!delayed_)
43 CompleteCreateArchive();
44 }
45
46 void OfflinePageTestArchiver::CompleteCreateArchive() {
47 DCHECK(!callback_.is_null());
48 base::FilePath archive_path;
49 if (filename_.empty()) {
50 ASSERT_TRUE(base::CreateTemporaryFileInDir(archives_dir_, &archive_path));
51 } else {
52 archive_path = archives_dir_.Append(filename_);
53 // This step ensures the file is created and closed immediately.
54 base::File file(archive_path, base::File::FLAG_OPEN_ALWAYS);
55 }
56 observer_->SetLastPathCreatedByArchiver(archive_path);
57 task_runner_->PostTask(
58 FROM_HERE, base::Bind(callback_, this, result_, url_, archive_path,
59 result_title_, size_to_report_));
60 }
61
62 } // namespace offline_pages
OLDNEW
« no previous file with comments | « components/offline_pages/offline_page_test_archiver.h ('k') | components/offline_pages/offline_page_test_store.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698