service.h revision effb81e5f8246d0db0270817048dc992db66e9fb
1// Copyright 2014 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#ifndef CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_SERVICE_H_ 6#define CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_SERVICE_H_ 7 8#include <map> 9#include <string> 10#include <vector> 11 12#include "base/observer_list.h" 13#include "chrome/browser/chromeos/file_system_provider/observer.h" 14#include "chrome/browser/profiles/profile.h" 15#include "chrome/common/extensions/api/file_system_provider.h" 16#include "components/keyed_service/core/keyed_service.h" 17#include "content/public/browser/browser_context.h" 18 19namespace chromeos { 20namespace file_system_provider { 21 22class ServiceFactory; 23 24// Manages and registers the fileSystemProvider service. 25class Service : public KeyedService { 26 public: 27 explicit Service(Profile* profile); 28 virtual ~Service(); 29 30 // Registers a file system provided by an extension with the |extension_id|. 31 // For success, it returns a numeric file system id, which is an 32 // auto-incremented non-zero value. For failures, it returns zero. 33 int RegisterFileSystem(const std::string& extension_id, 34 const std::string& file_system_name); 35 36 // Unregisters a file system with the specified |file_system_id| for the 37 // |extension_id|. For success returns true, otherwise false. 38 bool UnregisterFileSystem(const std::string& extension_id, 39 int file_system_id); 40 41 // Returns a list of currently registered file systems. All items are copied. 42 std::vector<ProvidedFileSystem> GetRegisteredFileSystems(); 43 44 // Adds and removes observers. 45 void AddObserver(Observer* observer); 46 void RemoveObserver(Observer* observer); 47 48 // Gets the singleton instance for the |context|. 49 static Service* Get(content::BrowserContext* context); 50 51 private: 52 typedef std::map<int, ProvidedFileSystem> FileSystemMap; 53 54 Profile* profile_; 55 ObserverList<Observer> observers_; 56 FileSystemMap file_systems_; 57 int next_id_; 58 59 DISALLOW_COPY_AND_ASSIGN(Service); 60}; 61 62} // namespace file_system_provider 63} // namespace chromeos 64 65#endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_SERVICE_H_ 66