1 // Copyright (c) 2012 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_EXTENSIONS_API_SYNC_FILE_SYSTEM_EXTENSION_SYNC_EVENT_OBSERVER_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_SYNC_FILE_SYSTEM_EXTENSION_SYNC_EVENT_OBSERVER_H_ 7 8 #include "base/basictypes.h" 9 #include "base/compiler_specific.h" 10 #include "base/memory/scoped_ptr.h" 11 #include "base/values.h" 12 #include "chrome/browser/sync_file_system/sync_event_observer.h" 13 #include "components/browser_context_keyed_service/browser_context_keyed_service.h" 14 15 class Profile; 16 17 namespace sync_file_system { 18 class SyncFileSystemService; 19 } 20 21 namespace extensions { 22 23 // Observes changes in SyncFileSystem and relays events to JS Extension API. 24 class ExtensionSyncEventObserver 25 : public sync_file_system::SyncEventObserver, 26 public BrowserContextKeyedService { 27 public: 28 explicit ExtensionSyncEventObserver(Profile* profile); 29 virtual ~ExtensionSyncEventObserver(); 30 31 void InitializeForService( 32 sync_file_system::SyncFileSystemService* sync_service); 33 34 // BrowserContextKeyedService override. 35 virtual void Shutdown() OVERRIDE; 36 37 // sync_file_system::SyncEventObserver interface implementation. 38 virtual void OnSyncStateUpdated( 39 const GURL& app_origin, 40 sync_file_system::SyncServiceState state, 41 const std::string& description) OVERRIDE; 42 43 virtual void OnFileSynced( 44 const fileapi::FileSystemURL& url, 45 sync_file_system::SyncFileStatus status, 46 sync_file_system::SyncAction action, 47 sync_file_system::SyncDirection direction) OVERRIDE; 48 49 private: 50 // Returns an empty string if the extension |app_origin| cannot be found 51 // in the installed extension list. 52 std::string GetExtensionId(const GURL& app_origin); 53 54 Profile* profile_; 55 56 // Not owned. If not null, then this is registered to SyncFileSystemService. 57 sync_file_system::SyncFileSystemService* sync_service_; 58 59 void BroadcastOrDispatchEvent(const GURL& app_origin, 60 const std::string& event_name, 61 scoped_ptr<base::ListValue> value); 62 63 DISALLOW_COPY_AND_ASSIGN(ExtensionSyncEventObserver); 64 }; 65 66 } // namespace extensions 67 68 #endif // CHROME_BROWSER_EXTENSIONS_API_SYNC_FILE_SYSTEM_EXTENSION_SYNC_EVENT_OBSERVER_H_ 69