Chromium Code Reviews| Index: chrome/browser/chromeos/file_system_provider/provided_file_system.h |
| diff --git a/chrome/browser/chromeos/file_system_provider/provided_file_system.h b/chrome/browser/chromeos/file_system_provider/provided_file_system.h |
| index ce896bd5836dbe723658024e8baf874ec3031b35..cc67d260aa12d3b024ddff06fdededa7993a0131 100644 |
| --- a/chrome/browser/chromeos/file_system_provider/provided_file_system.h |
| +++ b/chrome/browser/chromeos/file_system_provider/provided_file_system.h |
| @@ -5,9 +5,14 @@ |
| #ifndef CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_PROVIDED_FILE_SYSTEM_H_ |
| #define CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_PROVIDED_FILE_SYSTEM_H_ |
| +#include <string> |
| + |
| +#include "base/memory/ref_counted.h" |
| #include "base/memory/weak_ptr.h" |
| +#include "base/observer_list.h" |
| #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info.h" |
| #include "chrome/browser/chromeos/file_system_provider/provided_file_system_interface.h" |
| +#include "chrome/browser/chromeos/file_system_provider/provided_file_system_observer.h" |
| #include "chrome/browser/chromeos/file_system_provider/request_manager.h" |
| #include "storage/browser/fileapi/async_file_util.h" |
| @@ -30,6 +35,37 @@ namespace file_system_provider { |
| class NotificationManagerInterface; |
| +// Automatically calls the |update_callback| after all of the callbacks created |
|
mtomasz
2014/10/03 04:22:48
This class is very important. Basically as in the
|
| +// with |CreateCallback| are called. |
| +// |
| +// It's used to update tags of observed entries once a notification about a |
| +// change are fully handles. It is to make sure that the change notification is |
| +// fully handled before remembering the new tag. |
| +// |
| +// It is necessary to update the tag after all observers handle it fully, so |
| +// in case of shutdown or a crash we get the notifications again. |
| +class AutoUpdater : public base::RefCounted<AutoUpdater> { |
| + public: |
| + explicit AutoUpdater(const base::Closure& update_callback); |
| + |
| + // Creates a new callback which needs to be called before the update callback |
| + // is called. |
| + base::Closure CreateCallback(); |
| + |
| + private: |
| + friend class base::RefCounted<AutoUpdater>; |
| + |
| + // Called once the callback created with |CreateCallback| is executed. Once |
| + // all of such callbacks are called, then the update callback is invoked. |
| + void OnPendingCallback(); |
| + |
| + virtual ~AutoUpdater(); |
| + |
| + base::Closure update_callback_; |
| + int created_callbacks_; |
| + int pending_callbacks_; |
| +}; |
| + |
| // Provided file system implementation. Forwards requests between providers and |
| // clients. |
| class ProvidedFileSystem : public ProvidedFileSystemInterface { |
| @@ -38,6 +74,16 @@ class ProvidedFileSystem : public ProvidedFileSystemInterface { |
| const ProvidedFileSystemInfo& file_system_info); |
| virtual ~ProvidedFileSystem(); |
| + // Sets a custom event router. Used in unit tests to mock out the real |
| + // extension. |
| + void SetEventRouterForTesting(extensions::EventRouter* event_router); |
| + |
| + // Sets a custom notification manager. It will recreate the request manager, |
| + // so is must be called just after creating ProvideFileSystem instance. |
| + // Used by unit tests. |
| + void SetNotificationManagerForTesting( |
| + scoped_ptr<NotificationManagerInterface> notification_manager); |
| + |
| // ProvidedFileSystemInterface overrides. |
| virtual AbortCallback RequestUnmount( |
| const storage::AsyncFileUtil::StatusCallback& callback) OVERRIDE; |
| @@ -89,8 +135,23 @@ class ProvidedFileSystem : public ProvidedFileSystemInterface { |
| int64 offset, |
| int length, |
| const storage::AsyncFileUtil::StatusCallback& callback) OVERRIDE; |
| + virtual AbortCallback ObserveDirectory( |
| + const base::FilePath& directory_path, |
| + bool recursive, |
| + const storage::AsyncFileUtil::StatusCallback& callback) OVERRIDE; |
| + virtual AbortCallback UnobserveEntry( |
| + const base::FilePath& entry_path, |
| + const storage::AsyncFileUtil::StatusCallback& callback) OVERRIDE; |
| virtual const ProvidedFileSystemInfo& GetFileSystemInfo() const OVERRIDE; |
| virtual RequestManager* GetRequestManager() OVERRIDE; |
| + virtual ObservedEntries* GetObservedEntries() OVERRIDE; |
| + virtual void AddObserver(ProvidedFileSystemObserver* observer) OVERRIDE; |
| + virtual void RemoveObserver(ProvidedFileSystemObserver* observer) OVERRIDE; |
| + virtual bool Notify( |
| + const base::FilePath& observed_path, |
| + ProvidedFileSystemObserver::ChangeType change_type, |
| + const ProvidedFileSystemObserver::ChildChanges& child_changes, |
| + const std::string& tag) OVERRIDE; |
| virtual base::WeakPtr<ProvidedFileSystemInterface> GetWeakPtr() OVERRIDE; |
| private: |
| @@ -100,11 +161,27 @@ class ProvidedFileSystem : public ProvidedFileSystemInterface { |
| void Abort(int operation_request_id, |
| const storage::AsyncFileUtil::StatusCallback& callback); |
| + // Called when a directory becomes watched successfully. |
| + void OnObserveDirectoryCompleted( |
| + const base::FilePath& directory_path, |
| + bool recursive, |
| + const storage::AsyncFileUtil::StatusCallback& callback, |
| + base::File::Error result); |
| + |
| + // Called when all observers finished handling the change notification. It |
|
mtomasz
2014/10/03 04:22:47
This is called when all observers in |observers_|
|
| + // updates the tag from |last_tag| to |tag| for the entry at |observed_path|. |
| + void OnNotifyCompleted(const base::FilePath& observed_path, |
| + ProvidedFileSystemObserver::ChangeType change_type, |
| + const std::string& last_tag, |
| + const std::string& tag); |
| + |
| Profile* profile_; // Not owned. |
| extensions::EventRouter* event_router_; // Not owned. May be NULL. |
| ProvidedFileSystemInfo file_system_info_; |
| scoped_ptr<NotificationManagerInterface> notification_manager_; |
| - RequestManager request_manager_; |
| + scoped_ptr<RequestManager> request_manager_; |
| + ObservedEntries observed_entries_; |
| + ObserverList<ProvidedFileSystemObserver> observers_; |
| base::WeakPtrFactory<ProvidedFileSystem> weak_ptr_factory_; |
| DISALLOW_COPY_AND_ASSIGN(ProvidedFileSystem); |