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

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

Issue 1988973002: [Offline pages] Moving disk size related calls to Archive Manager, reorganizing UMA (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@archive-manager
Patch Set: Adding test, updating ArchiveManager implementation to task runner. 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 #ifndef COMPONENTS_OFFLINE_PAGES_ARCHIVE_MANAGER_H_ 5 #ifndef COMPONENTS_OFFLINE_PAGES_ARCHIVE_MANAGER_H_
6 #define COMPONENTS_OFFLINE_PAGES_ARCHIVE_MANAGER_H_ 6 #define COMPONENTS_OFFLINE_PAGES_ARCHIVE_MANAGER_H_
7 7
8 #include <set> 8 #include <set>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/callback_forward.h" 11 #include "base/callback_forward.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 14
15 namespace base { 15 namespace base {
16 class SequencedTaskRunner; 16 class SequencedTaskRunner;
17 } // namespace base 17 } // namespace base
18 18
19 namespace offline_pages { 19 namespace offline_pages {
20 20
21 // Class that manages all archive files for offline pages. They are all stored 21 // Class that manages all archive files for offline pages. They are all stored
22 // in a specific archive directory. 22 // in a specific archive directory.
23 // All tasks are performed using |task_runner_|. 23 // All tasks are performed using |task_runner_|.
24 class ArchiveManager { 24 class ArchiveManager {
25 public: 25 public:
26 // Structure for passing around information related to disk space consumed by
jianli 2016/05/18 00:06:00 nit: no need to comment since struct name should b
fgorski 2016/05/18 18:14:59 Done.
27 // offline page archives.
28 struct StorageSizes {
jianli 2016/05/18 00:05:59 nit: StorageStats
fgorski 2016/05/18 18:14:59 Done.
29 int64_t free_disk_space;
30 int64_t total_archives_size;
31 };
32
26 ArchiveManager(const base::FilePath& archives_dir, 33 ArchiveManager(const base::FilePath& archives_dir,
27 const scoped_refptr<base::SequencedTaskRunner>& task_runner); 34 const scoped_refptr<base::SequencedTaskRunner>& task_runner);
28 virtual ~ArchiveManager(); 35 virtual ~ArchiveManager();
29 36
30 // Creates archives directory if one does not exist yet; 37 // Creates archives directory if one does not exist yet;
31 virtual void EnsureArchivesDirCreated(const base::Closure& callback); 38 virtual void EnsureArchivesDirCreated(const base::Closure& callback);
32 39
33 // Checks whether an archive with specified |archive_path| exists. 40 // Checks whether an archive with specified |archive_path| exists.
34 virtual void ExistsArchive(const base::FilePath& archive_path, 41 virtual void ExistsArchive(const base::FilePath& archive_path,
35 const base::Callback<void(bool)>& callback); 42 const base::Callback<void(bool)>& callback);
36 43
37 // Deletes an archive with specified |archive_path|. 44 // Deletes an archive with specified |archive_path|.
38 // It is considered successful to attempt to delete a file that does not 45 // It is considered successful to attempt to delete a file that does not
39 // exist. 46 // exist.
40 virtual void DeleteArchive(const base::FilePath& archive_path, 47 virtual void DeleteArchive(const base::FilePath& archive_path,
41 const base::Callback<void(bool)>& callback); 48 const base::Callback<void(bool)>& callback);
42 49
43 // Deletes multiple archives that are specified in |archive_paths|. 50 // Deletes multiple archives that are specified in |archive_paths|.
44 // It is considered successful to attempt to delete a file that does not 51 // It is considered successful to attempt to delete a file that does not
45 // exist. 52 // exist.
46 virtual void DeleteMultipleArchives( 53 virtual void DeleteMultipleArchives(
47 const std::vector<base::FilePath>& archive_paths, 54 const std::vector<base::FilePath>& archive_paths,
48 const base::Callback<void(bool)>& callback); 55 const base::Callback<void(bool)>& callback);
49 56
50 // Lists all archive files in the archive directory. 57 // Lists all archive files in the archive directory.
51 virtual void GetAllArchives( 58 virtual void GetAllArchives(
52 const base::Callback<void(const std::set<base::FilePath>&)>& callback) 59 const base::Callback<void(const std::set<base::FilePath>&)>& callback)
53 const; 60 const;
54 61
62 // Gets information about disk space consumed by offline archives and disk
63 // space available, for UMA reporting.
jianli 2016/05/18 00:06:00 nit: remove UMA reporting in case we might use thi
fgorski 2016/05/18 18:14:59 Done.
64 virtual void GetStorageSizes(
jianli 2016/05/18 00:05:59 nit: GetStorageStats
fgorski 2016/05/18 18:14:59 Done.
65 const base::Callback<void(StorageSizes storage_sizes)>& callback) const;
66
55 private: 67 private:
56 // Path under which all of the managed archives should be stored. 68 // Path under which all of the managed archives should be stored.
57 base::FilePath archives_dir_; 69 base::FilePath archives_dir_;
58 // Task runner for running file operations. 70 // Task runner for running file operations.
59 scoped_refptr<base::SequencedTaskRunner> task_runner_; 71 scoped_refptr<base::SequencedTaskRunner> task_runner_;
60 }; 72 };
61 73
62 } // namespace offline_pages 74 } // namespace offline_pages
63 75
64 #endif // COMPONENTS_OFFLINE_PAGES_ARCHIVE_MANAGER_H_ 76 #endif // COMPONENTS_OFFLINE_PAGES_ARCHIVE_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698