OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 APPS_SAVED_FILES_SERVICE_H_ | 5 #ifndef APPS_SAVED_FILES_SERVICE_H_ |
6 #define APPS_SAVED_FILES_SERVICE_H_ | 6 #define APPS_SAVED_FILES_SERVICE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <memory> | 9 #include <memory> |
10 #include <set> | 10 #include <set> |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
15 #include "base/gtest_prod_util.h" | 15 #include "base/gtest_prod_util.h" |
16 #include "components/keyed_service/core/keyed_service.h" | 16 #include "components/keyed_service/core/keyed_service.h" |
17 #include "content/public/browser/notification_observer.h" | 17 #include "content/public/browser/notification_observer.h" |
18 #include "content/public/browser/notification_registrar.h" | 18 #include "content/public/browser/notification_registrar.h" |
19 | 19 |
20 class Profile; | 20 namespace content { |
| 21 class BrowserContext; |
| 22 } |
| 23 |
21 class SavedFilesServiceUnitTest; | 24 class SavedFilesServiceUnitTest; |
22 FORWARD_DECLARE_TEST(SavedFilesServiceUnitTest, RetainTwoFilesTest); | 25 FORWARD_DECLARE_TEST(SavedFilesServiceUnitTest, RetainTwoFilesTest); |
23 FORWARD_DECLARE_TEST(SavedFilesServiceUnitTest, EvictionTest); | 26 FORWARD_DECLARE_TEST(SavedFilesServiceUnitTest, EvictionTest); |
24 FORWARD_DECLARE_TEST(SavedFilesServiceUnitTest, SequenceNumberCompactionTest); | 27 FORWARD_DECLARE_TEST(SavedFilesServiceUnitTest, SequenceNumberCompactionTest); |
25 | 28 |
26 namespace extensions { | 29 namespace extensions { |
27 class Extension; | 30 class Extension; |
28 } | 31 } |
29 | 32 |
30 namespace apps { | 33 namespace apps { |
(...skipping 21 matching lines...) Expand all Loading... |
52 // The sequence number in the LRU of the file entry. The value 0 indicates | 55 // The sequence number in the LRU of the file entry. The value 0 indicates |
53 // that the entry is not in the LRU. | 56 // that the entry is not in the LRU. |
54 int sequence_number; | 57 int sequence_number; |
55 }; | 58 }; |
56 | 59 |
57 // Tracks the files that apps have retained access to both while running and | 60 // Tracks the files that apps have retained access to both while running and |
58 // when suspended. | 61 // when suspended. |
59 class SavedFilesService : public KeyedService, | 62 class SavedFilesService : public KeyedService, |
60 public content::NotificationObserver { | 63 public content::NotificationObserver { |
61 public: | 64 public: |
62 explicit SavedFilesService(Profile* profile); | 65 explicit SavedFilesService(content::BrowserContext* context); |
63 ~SavedFilesService() override; | 66 ~SavedFilesService() override; |
64 | 67 |
65 static SavedFilesService* Get(Profile* profile); | 68 static SavedFilesService* Get(content::BrowserContext* context); |
66 | 69 |
67 // Registers a file entry with the saved files service, making it eligible to | 70 // Registers a file entry with the saved files service, making it eligible to |
68 // be put into the queue. File entries that are in the retained files queue at | 71 // be put into the queue. File entries that are in the retained files queue at |
69 // object construction are automatically registered. | 72 // object construction are automatically registered. |
70 void RegisterFileEntry(const std::string& extension_id, | 73 void RegisterFileEntry(const std::string& extension_id, |
71 const std::string& id, | 74 const std::string& id, |
72 const base::FilePath& file_path, | 75 const base::FilePath& file_path, |
73 bool is_directory); | 76 bool is_directory); |
74 | 77 |
75 // If the file with |id| is not in the queue of files to be retained | 78 // If the file with |id| is not in the queue of files to be retained |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 void Clear(const std::string& extension_id); | 126 void Clear(const std::string& extension_id); |
124 | 127 |
125 static void SetMaxSequenceNumberForTest(int max_value); | 128 static void SetMaxSequenceNumberForTest(int max_value); |
126 static void ClearMaxSequenceNumberForTest(); | 129 static void ClearMaxSequenceNumberForTest(); |
127 static void SetLruSizeForTest(int size); | 130 static void SetLruSizeForTest(int size); |
128 static void ClearLruSizeForTest(); | 131 static void ClearLruSizeForTest(); |
129 | 132 |
130 std::map<std::string, std::unique_ptr<SavedFiles>> | 133 std::map<std::string, std::unique_ptr<SavedFiles>> |
131 extension_id_to_saved_files_; | 134 extension_id_to_saved_files_; |
132 content::NotificationRegistrar registrar_; | 135 content::NotificationRegistrar registrar_; |
133 Profile* profile_; | 136 content::BrowserContext* context_; |
134 | 137 |
135 DISALLOW_COPY_AND_ASSIGN(SavedFilesService); | 138 DISALLOW_COPY_AND_ASSIGN(SavedFilesService); |
136 }; | 139 }; |
137 | 140 |
138 } // namespace apps | 141 } // namespace apps |
139 | 142 |
140 #endif // APPS_SAVED_FILES_SERVICE_H_ | 143 #endif // APPS_SAVED_FILES_SERVICE_H_ |
OLD | NEW |