| 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 <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 // that the entry is not in the LRU. | 53 // that the entry is not in the LRU. |
| 54 int sequence_number; | 54 int sequence_number; |
| 55 }; | 55 }; |
| 56 | 56 |
| 57 // Tracks the files that apps have retained access to both while running and | 57 // Tracks the files that apps have retained access to both while running and |
| 58 // when suspended. | 58 // when suspended. |
| 59 class SavedFilesService : public KeyedService, | 59 class SavedFilesService : public KeyedService, |
| 60 public content::NotificationObserver { | 60 public content::NotificationObserver { |
| 61 public: | 61 public: |
| 62 explicit SavedFilesService(Profile* profile); | 62 explicit SavedFilesService(Profile* profile); |
| 63 virtual ~SavedFilesService(); | 63 ~SavedFilesService() override; |
| 64 | 64 |
| 65 static SavedFilesService* Get(Profile* profile); | 65 static SavedFilesService* Get(Profile* profile); |
| 66 | 66 |
| 67 // Registers a file entry with the saved files service, making it eligible to | 67 // 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 | 68 // be put into the queue. File entries that are in the retained files queue at |
| 69 // object construction are automatically registered. | 69 // object construction are automatically registered. |
| 70 void RegisterFileEntry(const std::string& extension_id, | 70 void RegisterFileEntry(const std::string& extension_id, |
| 71 const std::string& id, | 71 const std::string& id, |
| 72 const base::FilePath& file_path, | 72 const base::FilePath& file_path, |
| 73 bool is_directory); | 73 bool is_directory); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 102 FRIEND_TEST_ALL_PREFIXES(::SavedFilesServiceUnitTest, RetainTwoFilesTest); | 102 FRIEND_TEST_ALL_PREFIXES(::SavedFilesServiceUnitTest, RetainTwoFilesTest); |
| 103 FRIEND_TEST_ALL_PREFIXES(::SavedFilesServiceUnitTest, EvictionTest); | 103 FRIEND_TEST_ALL_PREFIXES(::SavedFilesServiceUnitTest, EvictionTest); |
| 104 FRIEND_TEST_ALL_PREFIXES(::SavedFilesServiceUnitTest, | 104 FRIEND_TEST_ALL_PREFIXES(::SavedFilesServiceUnitTest, |
| 105 SequenceNumberCompactionTest); | 105 SequenceNumberCompactionTest); |
| 106 friend class ::SavedFilesServiceUnitTest; | 106 friend class ::SavedFilesServiceUnitTest; |
| 107 | 107 |
| 108 // A container for the registered files for an app. | 108 // A container for the registered files for an app. |
| 109 class SavedFiles; | 109 class SavedFiles; |
| 110 | 110 |
| 111 // content::NotificationObserver. | 111 // content::NotificationObserver. |
| 112 virtual void Observe(int type, | 112 void Observe(int type, |
| 113 const content::NotificationSource& source, | 113 const content::NotificationSource& source, |
| 114 const content::NotificationDetails& details) override; | 114 const content::NotificationDetails& details) override; |
| 115 | 115 |
| 116 // Returns the SavedFiles for |extension_id| or NULL if one does not exist. | 116 // Returns the SavedFiles for |extension_id| or NULL if one does not exist. |
| 117 SavedFiles* Get(const std::string& extension_id) const; | 117 SavedFiles* Get(const std::string& extension_id) const; |
| 118 | 118 |
| 119 // Returns the SavedFiles for |extension_id|, creating it if necessary. | 119 // Returns the SavedFiles for |extension_id|, creating it if necessary. |
| 120 SavedFiles* GetOrInsert(const std::string& extension_id); | 120 SavedFiles* GetOrInsert(const std::string& extension_id); |
| 121 | 121 |
| 122 // Clears the SavedFiles for |extension_id|. | 122 // Clears the SavedFiles for |extension_id|. |
| 123 void Clear(const std::string& extension_id); | 123 void Clear(const std::string& extension_id); |
| 124 | 124 |
| 125 static void SetMaxSequenceNumberForTest(int max_value); | 125 static void SetMaxSequenceNumberForTest(int max_value); |
| 126 static void ClearMaxSequenceNumberForTest(); | 126 static void ClearMaxSequenceNumberForTest(); |
| 127 static void SetLruSizeForTest(int size); | 127 static void SetLruSizeForTest(int size); |
| 128 static void ClearLruSizeForTest(); | 128 static void ClearLruSizeForTest(); |
| 129 | 129 |
| 130 std::map<std::string, SavedFiles*> extension_id_to_saved_files_; | 130 std::map<std::string, SavedFiles*> extension_id_to_saved_files_; |
| 131 STLValueDeleter<std::map<std::string, SavedFiles*> > | 131 STLValueDeleter<std::map<std::string, SavedFiles*> > |
| 132 extension_id_to_saved_files_deleter_; | 132 extension_id_to_saved_files_deleter_; |
| 133 content::NotificationRegistrar registrar_; | 133 content::NotificationRegistrar registrar_; |
| 134 Profile* profile_; | 134 Profile* profile_; |
| 135 | 135 |
| 136 DISALLOW_COPY_AND_ASSIGN(SavedFilesService); | 136 DISALLOW_COPY_AND_ASSIGN(SavedFilesService); |
| 137 }; | 137 }; |
| 138 | 138 |
| 139 } // namespace apps | 139 } // namespace apps |
| 140 | 140 |
| 141 #endif // APPS_SAVED_FILES_SERVICE_H_ | 141 #endif // APPS_SAVED_FILES_SERVICE_H_ |
| OLD | NEW |