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.
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_
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"
17 namespace sync_file_system {
18 class SyncFileSystemService;
21 namespace extensions {
23 // Observes changes in SyncFileSystem and relays events to JS Extension API.
24 class ExtensionSyncEventObserver
25 : public sync_file_system::SyncEventObserver,
26 public BrowserContextKeyedService {
28 explicit ExtensionSyncEventObserver(Profile* profile);
29 virtual ~ExtensionSyncEventObserver();
31 void InitializeForService(
32 sync_file_system::SyncFileSystemService* sync_service);
34 // BrowserContextKeyedService override.
35 virtual void Shutdown() OVERRIDE;
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;
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;
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);
56 // Not owned. If not null, then this is registered to SyncFileSystemService.
57 sync_file_system::SyncFileSystemService* sync_service_;
59 void BroadcastOrDispatchEvent(const GURL& app_origin,
60 const std::string& event_name,
61 scoped_ptr<base::ListValue> value);
63 DISALLOW_COPY_AND_ASSIGN(ExtensionSyncEventObserver);
66 } // namespace extensions
68 #endif // CHROME_BROWSER_EXTENSIONS_API_SYNC_FILE_SYSTEM_EXTENSION_SYNC_EVENT_OBSERVER_H_