 Chromium Code Reviews
 Chromium Code Reviews Issue 625463002:
  [fsp] Add support for observing entries and notifying about changes.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 625463002:
  [fsp] Add support for observing entries and notifying about changes.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| 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> | |
| 9 | |
| 10 #include "base/memory/ref_counted.h" | |
| 8 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" | 
| 12 #include "base/observer_list.h" | |
| 9 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info .h" | 13 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info .h" | 
| 10 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte rface.h" | 14 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte rface.h" | 
| 15 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_obse rver.h" | |
| 11 #include "chrome/browser/chromeos/file_system_provider/request_manager.h" | 16 #include "chrome/browser/chromeos/file_system_provider/request_manager.h" | 
| 12 #include "storage/browser/fileapi/async_file_util.h" | 17 #include "storage/browser/fileapi/async_file_util.h" | 
| 13 | 18 | 
| 14 class Profile; | 19 class Profile; | 
| 15 | 20 | 
| 16 namespace net { | 21 namespace net { | 
| 17 class IOBuffer; | 22 class IOBuffer; | 
| 18 } // namespace net | 23 } // namespace net | 
| 19 | 24 | 
| 20 namespace base { | 25 namespace base { | 
| 21 class FilePath; | 26 class FilePath; | 
| 22 } // namespace base | 27 } // namespace base | 
| 23 | 28 | 
| 24 namespace extensions { | 29 namespace extensions { | 
| 25 class EventRouter; | 30 class EventRouter; | 
| 26 } // namespace extensions | 31 } // namespace extensions | 
| 27 | 32 | 
| 28 namespace chromeos { | 33 namespace chromeos { | 
| 29 namespace file_system_provider { | 34 namespace file_system_provider { | 
| 30 | 35 | 
| 31 class NotificationManagerInterface; | 36 class NotificationManagerInterface; | 
| 32 | 37 | 
| 38 // 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
 | |
| 39 // with |CreateCallback| are called. | |
| 40 // | |
| 41 // It's used to update tags of observed entries once a notification about a | |
| 42 // change are fully handles. It is to make sure that the change notification is | |
| 43 // fully handled before remembering the new tag. | |
| 44 // | |
| 45 // It is necessary to update the tag after all observers handle it fully, so | |
| 46 // in case of shutdown or a crash we get the notifications again. | |
| 47 class AutoUpdater : public base::RefCounted<AutoUpdater> { | |
| 48 public: | |
| 49 explicit AutoUpdater(const base::Closure& update_callback); | |
| 50 | |
| 51 // Creates a new callback which needs to be called before the update callback | |
| 52 // is called. | |
| 53 base::Closure CreateCallback(); | |
| 54 | |
| 55 private: | |
| 56 friend class base::RefCounted<AutoUpdater>; | |
| 57 | |
| 58 // Called once the callback created with |CreateCallback| is executed. Once | |
| 59 // all of such callbacks are called, then the update callback is invoked. | |
| 60 void OnPendingCallback(); | |
| 61 | |
| 62 virtual ~AutoUpdater(); | |
| 63 | |
| 64 base::Closure update_callback_; | |
| 65 int created_callbacks_; | |
| 66 int pending_callbacks_; | |
| 67 }; | |
| 68 | |
| 33 // Provided file system implementation. Forwards requests between providers and | 69 // Provided file system implementation. Forwards requests between providers and | 
| 34 // clients. | 70 // clients. | 
| 35 class ProvidedFileSystem : public ProvidedFileSystemInterface { | 71 class ProvidedFileSystem : public ProvidedFileSystemInterface { | 
| 36 public: | 72 public: | 
| 37 ProvidedFileSystem(Profile* profile, | 73 ProvidedFileSystem(Profile* profile, | 
| 38 const ProvidedFileSystemInfo& file_system_info); | 74 const ProvidedFileSystemInfo& file_system_info); | 
| 39 virtual ~ProvidedFileSystem(); | 75 virtual ~ProvidedFileSystem(); | 
| 40 | 76 | 
| 77 // Sets a custom event router. Used in unit tests to mock out the real | |
| 78 // extension. | |
| 79 void SetEventRouterForTesting(extensions::EventRouter* event_router); | |
| 80 | |
| 81 // Sets a custom notification manager. It will recreate the request manager, | |
| 82 // so is must be called just after creating ProvideFileSystem instance. | |
| 83 // Used by unit tests. | |
| 84 void SetNotificationManagerForTesting( | |
| 85 scoped_ptr<NotificationManagerInterface> notification_manager); | |
| 86 | |
| 41 // ProvidedFileSystemInterface overrides. | 87 // ProvidedFileSystemInterface overrides. | 
| 42 virtual AbortCallback RequestUnmount( | 88 virtual AbortCallback RequestUnmount( | 
| 43 const storage::AsyncFileUtil::StatusCallback& callback) OVERRIDE; | 89 const storage::AsyncFileUtil::StatusCallback& callback) OVERRIDE; | 
| 44 virtual AbortCallback GetMetadata( | 90 virtual AbortCallback GetMetadata( | 
| 45 const base::FilePath& entry_path, | 91 const base::FilePath& entry_path, | 
| 46 MetadataFieldMask fields, | 92 MetadataFieldMask fields, | 
| 47 const GetMetadataCallback& callback) OVERRIDE; | 93 const GetMetadataCallback& callback) OVERRIDE; | 
| 48 virtual AbortCallback ReadDirectory( | 94 virtual AbortCallback ReadDirectory( | 
| 49 const base::FilePath& directory_path, | 95 const base::FilePath& directory_path, | 
| 50 const storage::AsyncFileUtil::ReadDirectoryCallback& callback) OVERRIDE; | 96 const storage::AsyncFileUtil::ReadDirectoryCallback& callback) OVERRIDE; | 
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 82 virtual AbortCallback Truncate( | 128 virtual AbortCallback Truncate( | 
| 83 const base::FilePath& file_path, | 129 const base::FilePath& file_path, | 
| 84 int64 length, | 130 int64 length, | 
| 85 const storage::AsyncFileUtil::StatusCallback& callback) OVERRIDE; | 131 const storage::AsyncFileUtil::StatusCallback& callback) OVERRIDE; | 
| 86 virtual AbortCallback WriteFile( | 132 virtual AbortCallback WriteFile( | 
| 87 int file_handle, | 133 int file_handle, | 
| 88 net::IOBuffer* buffer, | 134 net::IOBuffer* buffer, | 
| 89 int64 offset, | 135 int64 offset, | 
| 90 int length, | 136 int length, | 
| 91 const storage::AsyncFileUtil::StatusCallback& callback) OVERRIDE; | 137 const storage::AsyncFileUtil::StatusCallback& callback) OVERRIDE; | 
| 138 virtual AbortCallback ObserveDirectory( | |
| 139 const base::FilePath& directory_path, | |
| 140 bool recursive, | |
| 141 const storage::AsyncFileUtil::StatusCallback& callback) OVERRIDE; | |
| 142 virtual AbortCallback UnobserveEntry( | |
| 143 const base::FilePath& entry_path, | |
| 144 const storage::AsyncFileUtil::StatusCallback& callback) OVERRIDE; | |
| 92 virtual const ProvidedFileSystemInfo& GetFileSystemInfo() const OVERRIDE; | 145 virtual const ProvidedFileSystemInfo& GetFileSystemInfo() const OVERRIDE; | 
| 93 virtual RequestManager* GetRequestManager() OVERRIDE; | 146 virtual RequestManager* GetRequestManager() OVERRIDE; | 
| 147 virtual ObservedEntries* GetObservedEntries() OVERRIDE; | |
| 148 virtual void AddObserver(ProvidedFileSystemObserver* observer) OVERRIDE; | |
| 149 virtual void RemoveObserver(ProvidedFileSystemObserver* observer) OVERRIDE; | |
| 150 virtual bool Notify( | |
| 151 const base::FilePath& observed_path, | |
| 152 ProvidedFileSystemObserver::ChangeType change_type, | |
| 153 const ProvidedFileSystemObserver::ChildChanges& child_changes, | |
| 154 const std::string& tag) OVERRIDE; | |
| 94 virtual base::WeakPtr<ProvidedFileSystemInterface> GetWeakPtr() OVERRIDE; | 155 virtual base::WeakPtr<ProvidedFileSystemInterface> GetWeakPtr() OVERRIDE; | 
| 95 | 156 | 
| 96 private: | 157 private: | 
| 97 // Aborts an operation executed with a request id equal to | 158 // Aborts an operation executed with a request id equal to | 
| 98 // |operation_request_id|. The request is removed immediately on the C++ side | 159 // |operation_request_id|. The request is removed immediately on the C++ side | 
| 99 // despite being handled by the providing extension or not. | 160 // despite being handled by the providing extension or not. | 
| 100 void Abort(int operation_request_id, | 161 void Abort(int operation_request_id, | 
| 101 const storage::AsyncFileUtil::StatusCallback& callback); | 162 const storage::AsyncFileUtil::StatusCallback& callback); | 
| 102 | 163 | 
| 164 // Called when a directory becomes watched successfully. | |
| 165 void OnObserveDirectoryCompleted( | |
| 166 const base::FilePath& directory_path, | |
| 167 bool recursive, | |
| 168 const storage::AsyncFileUtil::StatusCallback& callback, | |
| 169 base::File::Error result); | |
| 170 | |
| 171 // 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_|
 | |
| 172 // updates the tag from |last_tag| to |tag| for the entry at |observed_path|. | |
| 173 void OnNotifyCompleted(const base::FilePath& observed_path, | |
| 174 ProvidedFileSystemObserver::ChangeType change_type, | |
| 175 const std::string& last_tag, | |
| 176 const std::string& tag); | |
| 177 | |
| 103 Profile* profile_; // Not owned. | 178 Profile* profile_; // Not owned. | 
| 104 extensions::EventRouter* event_router_; // Not owned. May be NULL. | 179 extensions::EventRouter* event_router_; // Not owned. May be NULL. | 
| 105 ProvidedFileSystemInfo file_system_info_; | 180 ProvidedFileSystemInfo file_system_info_; | 
| 106 scoped_ptr<NotificationManagerInterface> notification_manager_; | 181 scoped_ptr<NotificationManagerInterface> notification_manager_; | 
| 107 RequestManager request_manager_; | 182 scoped_ptr<RequestManager> request_manager_; | 
| 183 ObservedEntries observed_entries_; | |
| 184 ObserverList<ProvidedFileSystemObserver> observers_; | |
| 108 | 185 | 
| 109 base::WeakPtrFactory<ProvidedFileSystem> weak_ptr_factory_; | 186 base::WeakPtrFactory<ProvidedFileSystem> weak_ptr_factory_; | 
| 110 DISALLOW_COPY_AND_ASSIGN(ProvidedFileSystem); | 187 DISALLOW_COPY_AND_ASSIGN(ProvidedFileSystem); | 
| 111 }; | 188 }; | 
| 112 | 189 | 
| 113 } // namespace file_system_provider | 190 } // namespace file_system_provider | 
| 114 } // namespace chromeos | 191 } // namespace chromeos | 
| 115 | 192 | 
| 116 #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_PROVIDED_FILE_SYSTEM_H_ | 193 #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_PROVIDED_FILE_SYSTEM_H_ | 
| OLD | NEW |