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

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

Issue 1981093002: [Offline pages] Hooking up Archive Manager to Offline Page Model (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@archive-manager
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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/callback.h" 6 #include "base/callback.h"
7 #include "base/files/file_enumerator.h"
7 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
8 #include "base/location.h" 9 #include "base/location.h"
9 #include "base/logging.h" 10 #include "base/logging.h"
10 #include "components/offline_pages/archive_manager.h" 11 #include "components/offline_pages/archive_manager.h"
11 12
12 namespace offline_pages { 13 namespace offline_pages {
13 14
14 namespace { 15 namespace {
15 16
16 void EnsureArchivesDirCreatedImpl(const base::FilePath& archives_dir) { 17 void EnsureArchivesDirCreatedImpl(const base::FilePath& archives_dir) {
(...skipping 11 matching lines...) Expand all
28 for (const auto& file_path : file_paths) { 29 for (const auto& file_path : file_paths) {
29 // Make sure delete happens on the left of || so that it is always executed. 30 // Make sure delete happens on the left of || so that it is always executed.
30 *result = base::DeleteFile(file_path, false) || *result; 31 *result = base::DeleteFile(file_path, false) || *result;
31 } 32 }
32 } 33 }
33 34
34 void CompleteBooleanCallback(const base::Callback<void(bool)>& callback, 35 void CompleteBooleanCallback(const base::Callback<void(bool)>& callback,
35 bool* exists) { 36 bool* exists) {
36 callback.Run(*exists); 37 callback.Run(*exists);
37 } 38 }
39
40 void GetAllArchivesImpl(const base::FilePath& archive_dir,
41 std::set<base::FilePath>* archive_paths) {
42 DCHECK(archive_paths);
43 archive_paths->clear();
44 base::FileEnumerator file_enumerator(archive_dir, false,
45 base::FileEnumerator::FILES);
46 for (base::FilePath archive_path = file_enumerator.Next();
47 !archive_path.empty();
48 archive_path = file_enumerator.Next()) {
49 archive_paths->insert(archive_path);
50 }
51 }
52
53 void GetAllArchivesImplDone(
54 const base::Callback<void(const std::set<base::FilePath>&)>& callback,
55 std::set<base::FilePath>* archive_paths) {
56 callback.Run(*archive_paths);
57 }
58
38 } // namespace 59 } // namespace
39 60
40 ArchiveManager::ArchiveManager( 61 ArchiveManager::ArchiveManager(
41 const base::FilePath& archives_dir, 62 const base::FilePath& archives_dir,
42 const scoped_refptr<base::SequencedTaskRunner>& task_runner) 63 const scoped_refptr<base::SequencedTaskRunner>& task_runner)
43 : archives_dir_(archives_dir), task_runner_(task_runner) {} 64 : archives_dir_(archives_dir), task_runner_(task_runner) {}
44 65
45 ArchiveManager::~ArchiveManager() {} 66 ArchiveManager::~ArchiveManager() {}
46 67
47 void ArchiveManager::EnsureArchivesDirCreated(const base::Closure& callback) { 68 void ArchiveManager::EnsureArchivesDirCreated(const base::Closure& callback) {
(...skipping 18 matching lines...) Expand all
66 87
67 void ArchiveManager::DeleteMultipleArchives( 88 void ArchiveManager::DeleteMultipleArchives(
68 const std::vector<base::FilePath>& archive_paths, 89 const std::vector<base::FilePath>& archive_paths,
69 const base::Callback<void(bool)>& callback) { 90 const base::Callback<void(bool)>& callback) {
70 bool* result = new bool(false); 91 bool* result = new bool(false);
71 task_runner_->PostTaskAndReply( 92 task_runner_->PostTaskAndReply(
72 FROM_HERE, base::Bind(DeleteArchivesImpl, archive_paths, result), 93 FROM_HERE, base::Bind(DeleteArchivesImpl, archive_paths, result),
73 base::Bind(CompleteBooleanCallback, callback, base::Owned(result))); 94 base::Bind(CompleteBooleanCallback, callback, base::Owned(result)));
74 } 95 }
75 96
97 void ArchiveManager::GetAllArchives(
98 const base::Callback<void(const std::set<base::FilePath>&)>& callback)
99 const {
100 std::set<base::FilePath>* archive_paths = new std::set<base::FilePath>();
101 task_runner_->PostTaskAndReply(
102 FROM_HERE, base::Bind(GetAllArchivesImpl, archives_dir_, archive_paths),
103 base::Bind(GetAllArchivesImplDone, callback, base::Owned(archive_paths)));
jianli 2016/05/17 21:48:13 I think you don't need GetAllArchivesImplDone.
fgorski 2016/05/17 22:50:29 Changed per offline discussion.
104 }
105
76 } // namespace offline_pages 106 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698