| Index: chrome/browser/extensions/system_info_event_router.h
|
| diff --git a/chrome/browser/extensions/system_info_event_router.h b/chrome/browser/extensions/system_info_event_router.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..8f3eb816c03daa40c291779addb86b49f59708a4
|
| --- /dev/null
|
| +++ b/chrome/browser/extensions/system_info_event_router.h
|
| @@ -0,0 +1,68 @@
|
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#ifndef CHROME_BROWSER_EXTENSIONS_SYSTEM_INFO_EVENT_ROUTER_H_
|
| +#define CHROME_BROWSER_EXTENSIONS_SYSTEM_INFO_EVENT_ROUTER_H_
|
| +
|
| +#include "base/memory/scoped_ptr.h"
|
| +#include "base/memory/singleton.h"
|
| +#include "base/values.h"
|
| +#include "chrome/browser/profiles/profile.h"
|
| +#include "chrome/browser/extensions/api/system_info_storage/storage_info_provider.h"
|
| +
|
| +namespace extensions {
|
| +
|
| +class SystemInfoWatcher;
|
| +
|
| +// Event router for systemInfo API. It is a singleton instance shared by
|
| +// multiple profiles.
|
| +class SystemInfoEventRouter : public StorageInfoProvider::Delegate {
|
| + public:
|
| + static SystemInfoEventRouter* GetInstance();
|
| +
|
| + // Add/remove event listener for the |event_name| event from |profile|.
|
| + void AddEventListener(Profile* profile, const std::string& event_name);
|
| + void RemoveEventListener(Profile* profile, const std::string& event_name);
|
| +
|
| + // Return true if the |event_name| event is already being listened.
|
| + bool HasEventListener(const std::string& event_name);
|
| +
|
| + // Return true if the |event_name| is an event from systemInfo namespace.
|
| + static bool IsSystemInfoEvent(const std::string& event_name);
|
| +
|
| + private:
|
| + friend struct DefaultSingletonTraits<SystemInfoEventRouter>;
|
| +
|
| + // Map of the profile and its events that are being listened.
|
| + typedef std::map<Profile*, std::set<std::string> > EventListenerMap;
|
| +
|
| + SystemInfoEventRouter();
|
| + virtual ~SystemInfoEventRouter();
|
| +
|
| + // Overriden from StorageInfoProvider::Delegate. These methods can be
|
| + // called from any thread.
|
| + void OnStorageDeviceAvailableCapacityChanged(const std::string& id,
|
| + double available_capacity);
|
| + void OnStorageDeviceAdded(const std::string& id,
|
| + const std::string& type,
|
| + double capacity,
|
| + double available_capacity);
|
| + void OnStorageDeviceRemoved(const std::string& id);
|
| +
|
| +
|
| + // Called on the UI thread to dispatch the systemInfo event to all extension
|
| + // processes cross multiple profiles.
|
| + void DispatchEvent(const std::string& event_name,
|
| + const base::ListValue& args);
|
| + // Called on the UI thread.
|
| + void DispatchAvailableCapacityChangedEvent(const std::string& id,
|
| + double available_capacity);
|
| +
|
| + EventListenerMap event_listener_map_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(SystemInfoEventRouter);
|
| +};
|
| +
|
| +} // namespace extensions
|
| +#endif // CHROME_BROWSER_EXTENSIONS_SYSTEM_INFO_EVENT_ROUTER_H_
|
|
|