| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_PROVIDED_FILE_SYSTEM_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_PROVIDED_FILE_SYSTEM_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_PROVIDED_FILE_SYSTEM_H_ | 6 #define CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_PROVIDED_FILE_SYSTEM_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 } // namespace extensions | 33 } // namespace extensions |
| 34 | 34 |
| 35 namespace chromeos { | 35 namespace chromeos { |
| 36 namespace file_system_provider { | 36 namespace file_system_provider { |
| 37 | 37 |
| 38 class NotificationManagerInterface; | 38 class NotificationManagerInterface; |
| 39 | 39 |
| 40 // Automatically calls the |update_callback| after all of the callbacks created | 40 // Automatically calls the |update_callback| after all of the callbacks created |
| 41 // with |CreateCallback| are called. | 41 // with |CreateCallback| are called. |
| 42 // | 42 // |
| 43 // It's used to update tags of observed entries once a notification about a | 43 // It's used to update tags of watchers once a notification about a change is |
| 44 // change are fully handles. It is to make sure that the change notification is | 44 // handled. It is to make sure that the change notification is fully handled |
| 45 // fully handled before remembering the new tag. | 45 // before remembering the new tag. |
| 46 // | 46 // |
| 47 // It is necessary to update the tag after all observers handle it fully, so | 47 // It is necessary to update the tag after all observers handle it fully, so |
| 48 // in case of shutdown or a crash we get the notifications again. | 48 // in case of shutdown or a crash we get the notifications again. |
| 49 class AutoUpdater : public base::RefCounted<AutoUpdater> { | 49 class AutoUpdater : public base::RefCounted<AutoUpdater> { |
| 50 public: | 50 public: |
| 51 explicit AutoUpdater(const base::Closure& update_callback); | 51 explicit AutoUpdater(const base::Closure& update_callback); |
| 52 | 52 |
| 53 // Creates a new callback which needs to be called before the update callback | 53 // Creates a new callback which needs to be called before the update callback |
| 54 // is called. | 54 // is called. |
| 55 base::Closure CreateCallback(); | 55 base::Closure CreateCallback(); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 virtual AbortCallback Truncate( | 130 virtual AbortCallback Truncate( |
| 131 const base::FilePath& file_path, | 131 const base::FilePath& file_path, |
| 132 int64 length, | 132 int64 length, |
| 133 const storage::AsyncFileUtil::StatusCallback& callback) override; | 133 const storage::AsyncFileUtil::StatusCallback& callback) override; |
| 134 virtual AbortCallback WriteFile( | 134 virtual AbortCallback WriteFile( |
| 135 int file_handle, | 135 int file_handle, |
| 136 net::IOBuffer* buffer, | 136 net::IOBuffer* buffer, |
| 137 int64 offset, | 137 int64 offset, |
| 138 int length, | 138 int length, |
| 139 const storage::AsyncFileUtil::StatusCallback& callback) override; | 139 const storage::AsyncFileUtil::StatusCallback& callback) override; |
| 140 virtual AbortCallback ObserveDirectory( | 140 virtual AbortCallback AddWatcher( |
| 141 const GURL& origin, | 141 const GURL& origin, |
| 142 const base::FilePath& directory_path, | 142 const base::FilePath& entry_path, |
| 143 bool recursive, | 143 bool recursive, |
| 144 bool persistent, | 144 bool persistent, |
| 145 const storage::AsyncFileUtil::StatusCallback& callback) override; | 145 const storage::AsyncFileUtil::StatusCallback& callback) override; |
| 146 virtual void UnobserveEntry( | 146 virtual void RemoveWatcher( |
| 147 const GURL& origin, | 147 const GURL& origin, |
| 148 const base::FilePath& entry_path, | 148 const base::FilePath& entry_path, |
| 149 bool recursive, | 149 bool recursive, |
| 150 const storage::AsyncFileUtil::StatusCallback& callback) override; | 150 const storage::AsyncFileUtil::StatusCallback& callback) override; |
| 151 virtual const ProvidedFileSystemInfo& GetFileSystemInfo() const override; | 151 virtual const ProvidedFileSystemInfo& GetFileSystemInfo() const override; |
| 152 virtual RequestManager* GetRequestManager() override; | 152 virtual RequestManager* GetRequestManager() override; |
| 153 virtual ObservedEntries* GetObservedEntries() override; | 153 virtual Watchers* GetWatchers() override; |
| 154 virtual void AddObserver(ProvidedFileSystemObserver* observer) override; | 154 virtual void AddObserver(ProvidedFileSystemObserver* observer) override; |
| 155 virtual void RemoveObserver(ProvidedFileSystemObserver* observer) override; | 155 virtual void RemoveObserver(ProvidedFileSystemObserver* observer) override; |
| 156 virtual bool Notify(const base::FilePath& observed_path, | 156 virtual bool Notify(const base::FilePath& entry_path, |
| 157 bool recursive, | 157 bool recursive, |
| 158 ProvidedFileSystemObserver::ChangeType change_type, | 158 ProvidedFileSystemObserver::ChangeType change_type, |
| 159 scoped_ptr<ProvidedFileSystemObserver::Changes> changes, | 159 scoped_ptr<ProvidedFileSystemObserver::Changes> changes, |
| 160 const std::string& tag) override; | 160 const std::string& tag) override; |
| 161 virtual base::WeakPtr<ProvidedFileSystemInterface> GetWeakPtr() override; | 161 virtual base::WeakPtr<ProvidedFileSystemInterface> GetWeakPtr() override; |
| 162 | 162 |
| 163 private: | 163 private: |
| 164 // Aborts an operation executed with a request id equal to | 164 // Aborts an operation executed with a request id equal to |
| 165 // |operation_request_id|. The request is removed immediately on the C++ side | 165 // |operation_request_id|. The request is removed immediately on the C++ side |
| 166 // despite being handled by the providing extension or not. | 166 // despite being handled by the providing extension or not. |
| 167 void Abort(int operation_request_id, | 167 void Abort(int operation_request_id, |
| 168 const storage::AsyncFileUtil::StatusCallback& callback); | 168 const storage::AsyncFileUtil::StatusCallback& callback); |
| 169 | 169 |
| 170 // Called when observing a directory process is completed with either success | 170 // Called when adding a watcher is completed with either success or en error. |
| 171 // or en error. | 171 void OnAddWatcherCompleted( |
| 172 void OnObserveDirectoryCompleted( | |
| 173 const GURL& origin, | 172 const GURL& origin, |
| 174 const base::FilePath& directory_path, | 173 const base::FilePath& entry_path, |
| 175 bool recursive, | 174 bool recursive, |
| 176 bool persistent, | 175 bool persistent, |
| 177 const storage::AsyncFileUtil::StatusCallback& callback, | 176 const storage::AsyncFileUtil::StatusCallback& callback, |
| 178 base::File::Error result); | 177 base::File::Error result); |
| 179 | 178 |
| 180 // Called when all observers finished handling the change notification. It | 179 // Called when all observers finished handling the change notification. It |
| 181 // updates the tag from |last_tag| to |tag| for the entry at |observed_path|. | 180 // updates the tag from |last_tag| to |tag| for the entry at |entry_path|. |
| 182 void OnNotifyCompleted( | 181 void OnNotifyCompleted( |
| 183 const base::FilePath& observed_path, | 182 const base::FilePath& entry_path, |
| 184 bool recursive, | 183 bool recursive, |
| 185 ProvidedFileSystemObserver::ChangeType change_type, | 184 ProvidedFileSystemObserver::ChangeType change_type, |
| 186 scoped_ptr<ProvidedFileSystemObserver::Changes> changes, | 185 scoped_ptr<ProvidedFileSystemObserver::Changes> changes, |
| 187 const std::string& last_tag, | 186 const std::string& last_tag, |
| 188 const std::string& tag); | 187 const std::string& tag); |
| 189 | 188 |
| 190 Profile* profile_; // Not owned. | 189 Profile* profile_; // Not owned. |
| 191 extensions::EventRouter* event_router_; // Not owned. May be NULL. | 190 extensions::EventRouter* event_router_; // Not owned. May be NULL. |
| 192 ProvidedFileSystemInfo file_system_info_; | 191 ProvidedFileSystemInfo file_system_info_; |
| 193 scoped_ptr<NotificationManagerInterface> notification_manager_; | 192 scoped_ptr<NotificationManagerInterface> notification_manager_; |
| 194 scoped_ptr<RequestManager> request_manager_; | 193 scoped_ptr<RequestManager> request_manager_; |
| 195 ObservedEntries observed_entries_; | 194 Watchers watchers_; |
| 196 ObserverList<ProvidedFileSystemObserver> observers_; | 195 ObserverList<ProvidedFileSystemObserver> observers_; |
| 197 | 196 |
| 198 base::WeakPtrFactory<ProvidedFileSystem> weak_ptr_factory_; | 197 base::WeakPtrFactory<ProvidedFileSystem> weak_ptr_factory_; |
| 199 DISALLOW_COPY_AND_ASSIGN(ProvidedFileSystem); | 198 DISALLOW_COPY_AND_ASSIGN(ProvidedFileSystem); |
| 200 }; | 199 }; |
| 201 | 200 |
| 202 } // namespace file_system_provider | 201 } // namespace file_system_provider |
| 203 } // namespace chromeos | 202 } // namespace chromeos |
| 204 | 203 |
| 205 #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_PROVIDED_FILE_SYSTEM_H_ | 204 #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_PROVIDED_FILE_SYSTEM_H_ |
| OLD | NEW |