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: components/offline_pages/archive_manager.cc

Issue 1977853004: [Offline pages] Adding ArchiveManager to abstract offline archives management (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 2016 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 "base/bind.h"
6 #include "base/callback.h"
7 #include "base/files/file_util.h"
8 #include "base/location.h"
9 #include "components/offline_pages/archive_manager.h"
10
11 namespace offline_pages {
jianli 2016/05/13 23:50:48 nit: add empty line
fgorski 2016/05/16 17:46:51 Done.
12 namespace {
jianli 2016/05/13 23:50:48 nit: add empty line
fgorski 2016/05/16 17:46:51 Done.
13 void EnsureArchivesDirCreatedImpl(const base::FilePath& archives_dir) {
14 CHECK(base::CreateDirectory(archives_dir));
15 }
16
17 void ArchiveExistsImpl(const base::FilePath& file_path, bool* exists) {
18 DCHECK(exists);
jianli 2016/05/13 23:50:48 Please include logging.h
fgorski 2016/05/16 17:46:51 Done.
19 *exists = base::PathExists(file_path);
20 }
21
22 void DeleteArchivesImpl(const std::vector<base::FilePath>& file_paths,
23 bool* result) {
24 DCHECK(result);
25 for (const auto& file_path : file_paths) {
26 // Make sure delete happens on the left of || so that it is always executed.
27 *result = base::DeleteFile(file_path, false) || *result;
28 }
29 }
30
31 void CompleteBooleanCallback(const base::Callback<void(bool)>& callback,
32 bool* exists) {
33 callback.Run(*exists);
34 }
35 } // namespace
36
37 ArchiveManager::ArchiveManager(
38 const base::FilePath& archives_dir,
39 const scoped_refptr<base::SequencedTaskRunner>& task_runner)
40 : archives_dir_(archives_dir), task_runner_(task_runner) {}
41
42 ArchiveManager::~ArchiveManager() {}
43
44 void ArchiveManager::EnsureArchivesDirCreated(const base::Closure& callback) {
45 task_runner_->PostTaskAndReply(
46 FROM_HERE, base::Bind(EnsureArchivesDirCreatedImpl, archives_dir_),
47 callback);
48 }
49
50 void ArchiveManager::ArchiveExists(const base::FilePath& archive_path,
51 const base::Callback<void(bool)>& callback) {
52 bool* result = new bool(false);
53 task_runner_->PostTaskAndReply(
54 FROM_HERE, base::Bind(ArchiveExistsImpl, archive_path, result),
55 base::Bind(CompleteBooleanCallback, callback, base::Owned(result)));
56 }
57
58 void ArchiveManager::DeleteArchive(const base::FilePath& archive_path,
59 const base::Callback<void(bool)>& callback) {
60 std::vector<base::FilePath> archive_paths = {archive_path};
61 DeleteArchives(archive_paths, callback);
62 }
63
64 void ArchiveManager::DeleteArchives(
65 const std::vector<base::FilePath>& archive_paths,
66 const base::Callback<void(bool)>& callback) {
67 bool* result = new bool(false);
68 task_runner_->PostTaskAndReply(
69 FROM_HERE, base::Bind(DeleteArchivesImpl, archive_paths, result),
70 base::Bind(CompleteBooleanCallback, callback, base::Owned(result)));
71 }
72
73 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698