Chromium Code Reviews| Index: apps/saved_files_service.h |
| diff --git a/apps/saved_files_service.h b/apps/saved_files_service.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..be3941b52d4bbaa71d1063e3f083063d789c9b14 |
| --- /dev/null |
| +++ b/apps/saved_files_service.h |
| @@ -0,0 +1,102 @@ |
| +// Copyright 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef APPS_SAVED_FILES_SERVICE_H_ |
| +#define APPS_SAVED_FILES_SERVICE_H_ |
| + |
| +#include <map> |
| +#include <set> |
| +#include <string> |
| +#include <vector> |
| + |
| +#include "base/files/file_path.h" |
| +#include "base/stl_util.h" |
| +#include "chrome/browser/profiles/profile_keyed_service.h" |
| +#include "content/public/browser/notification_observer.h" |
| +#include "content/public/browser/notification_registrar.h" |
| + |
| +class Profile; |
| + |
| +namespace apps { |
| + |
| +// Represents a file entry that a user has given an extension permission to |
|
Matt Giuca
2013/05/17 08:28:45
s/extension/app
Sam McNally
2013/05/20 01:17:13
Done.
|
| +// access. Intended to be persisted to disk (in the Preferences file), so should |
| +// remain serializable. |
| +struct SavedFileEntry { |
|
Matt Giuca
2013/05/17 08:28:45
If it's serializable, how do you serialize it? Sho
Sam McNally
2013/05/20 01:17:13
See AddSavedFileEntry and friends in saved_files_s
|
| + SavedFileEntry() |
| + : writable(false), |
| + sequence_number(0) {} |
| + |
| + SavedFileEntry(const std::string& id, |
| + const base::FilePath& path, |
| + bool writable, |
| + int sequence_number) |
| + : id(id), |
| + path(path), |
| + writable(writable), |
| + sequence_number(sequence_number) {} |
| + |
| + std::string id; |
|
Matt Giuca
2013/05/17 08:28:45
Document (briefly) each of these fields.
Sam McNally
2013/05/20 01:17:13
Done.
|
| + base::FilePath path; |
| + bool writable; |
| + int sequence_number; |
| +}; |
| + |
| +class SavedFilesService : public ProfileKeyedService, |
| + public content::NotificationObserver { |
| + public: |
| + explicit SavedFilesService(Profile* profile); |
| + virtual ~SavedFilesService(); |
| + |
| + static SavedFilesService* Get(Profile* profile); |
| + |
| + void RetainFileEntry(const std::string& extension_id, |
|
Matt Giuca
2013/05/17 08:28:45
Document.
Sam McNally
2013/05/20 01:17:13
Done.
|
| + const std::string& id, |
| + const base::FilePath& file_path, |
| + bool writable); |
| + |
| + void MoveEntryToFrontOfQueue(const std::string& extension_id, |
|
Matt Giuca
2013/05/17 08:28:45
Document.
Sam McNally
2013/05/20 01:17:13
Done.
|
| + const std::string& id); |
| + |
| + bool IsRetained(const std::string& extension_id, const std::string& id); |
|
Matt Giuca
2013/05/17 08:28:45
Document.
Sam McNally
2013/05/20 01:17:13
Done.
|
| + |
| + bool GetFileEntry(const std::string& extension_id, |
|
Matt Giuca
2013/05/17 08:28:45
Document.
Sam McNally
2013/05/20 01:17:13
Done.
|
| + const std::string& id, |
| + SavedFileEntry* out); |
| + |
| + std::vector<SavedFileEntry> GetAllFileEntries( |
|
Matt Giuca
2013/05/17 08:28:45
Document.
Sam McNally
2013/05/20 01:17:13
Done.
|
| + const std::string& extension_id); |
| + |
| + void ClearExtensionForTest(const std::string& extension_id); |
|
Matt Giuca
2013/05/17 08:28:45
Document.
Sam McNally
2013/05/20 01:17:13
Done.
|
| + |
| + static void SetMaxSequenceNumberForTest(int max_value); |
|
Matt Giuca
2013/05/17 08:28:45
Document these four, and explain (in a paragraph a
Sam McNally
2013/05/20 01:17:13
Done.
|
| + static void ClearMaxSequenceNumberForTest(); |
| + static void SetLruSizeForTest(int size); |
| + static void ClearLruSizeForTest(); |
| + |
| + private: |
| + class SavedFiles; |
| + |
| + // content::NotificationObserver. |
| + virtual void Observe(int type, |
| + const content::NotificationSource& source, |
| + const content::NotificationDetails& details) OVERRIDE; |
| + |
| + SavedFiles* GetOrInsert(const std::string& extension_id); |
| + |
| + void ClearExtension(const std::string& extension_id); |
| + |
| + std::map<std::string, SavedFiles*> extension_id_to_saved_files_; |
| + STLValueDeleter<std::map<std::string, SavedFiles*> > |
| + extension_id_to_saved_files_deleter_; |
| + std::set<std::string> extensions_to_clear_; |
| + content::NotificationRegistrar registrar_; |
| + Profile* profile_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(SavedFilesService); |
| +}; |
| + |
| +} // namespace apps |
| + |
| +#endif // APPS_SAVED_FILES_SERVICE_H_ |