Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6335)

Unified Diff: chrome/browser/extensions/api/dial/dial_api.h

Issue 11444020: DIAL extension API skeleton. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: abc.... Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/extensions/api/dial/dial_api.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/api/dial/dial_api.h
diff --git a/chrome/browser/extensions/api/dial/dial_api.h b/chrome/browser/extensions/api/dial/dial_api.h
new file mode 100644
index 0000000000000000000000000000000000000000..ee3ba7f861ad25909e253d9594992be7060dc591
--- /dev/null
+++ b/chrome/browser/extensions/api/dial/dial_api.h
@@ -0,0 +1,98 @@
+// 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_API_DIAL_DIAL_API_H_
+#define CHROME_BROWSER_EXTENSIONS_API_DIAL_DIAL_API_H_
+
+#include "base/memory/scoped_ptr.h"
+#include "chrome/browser/extensions/api/api_function.h"
+#include "chrome/browser/extensions/api/dial/dial_device_data.h"
+#include "chrome/browser/extensions/api/dial/dial_registry.h"
+#include "chrome/browser/extensions/event_router.h"
+#include "chrome/browser/profiles/refcounted_profile_keyed_service.h"
+
+namespace extensions {
+
+class DialRegistry;
+
+// Dial API which is a ref-counted ProfileKeyedService that manages the DIAL
+// registry. It takes care of creating the registry on the IO thread and
+// is an observer of the registry. It makes sure devices events are sent out
+// to extension listeners on the right thread.
+class DialAPI : public RefcountedProfileKeyedService,
+ public EventRouter::Observer,
+ public DialRegistry::Observer {
+ public:
+ explicit DialAPI(Profile* profile);
+
+ // The DialRegistry for the API. This must always be used only from the IO
+ // thread.
+ DialRegistry* dial_registry();
+
+ // Called by the DialRegistry on the IO thread so that the DialAPI dispatches
+ // the event to listeners on the UI thread.
+ void SendEventOnUIThread(const DialRegistry::DeviceList& devices);
+
+ private:
+ virtual ~DialAPI();
+
+ // RefcountedProfileKeyedService:
+ virtual void ShutdownOnUIThread() OVERRIDE;
+
+ // EventRouter::Observer:
+ virtual void OnListenerAdded(const EventListenerInfo& details) OVERRIDE;
+ virtual void OnListenerRemoved(const EventListenerInfo& details) OVERRIDE;
+
+ // DialRegistry::Observer:
+ virtual void OnDialDeviceEvent(
+ const DialRegistry::DeviceList& devices) OVERRIDE;
+
+ // Methods to notify the DialRegistry on the correct thread of new/removed
+ // listeners.
+ void NotifyListenerAddedOnIOThread();
+ void NotifyListenerRemovedOnIOThread();
+
+ Profile* profile_;
+
+ // Created lazily on first access on the IO thread.
+ scoped_ptr<DialRegistry> dial_registry_;
+
+ DISALLOW_COPY_AND_ASSIGN(DialAPI);
+};
+
+namespace api {
+
+// DiscoverNow function. This function needs a round-trip from the IO thread
+// because it needs to grab a pointer to the DIAL API in order to get a
+// reference to the DialRegistry while on the IO thread. Then, the result
+// must be returned on the UI thread.
+class DialDiscoverNowFunction : public AsyncApiFunction {
+ public:
+ DialDiscoverNowFunction();
+
+ protected:
+ virtual ~DialDiscoverNowFunction() {}
+
+ // AsyncApiFunction:
+ virtual bool Prepare() OVERRIDE;
+ virtual void Work() OVERRIDE;
+ virtual bool Respond() OVERRIDE;
+
+ private:
+ DECLARE_EXTENSION_FUNCTION_NAME("dial.discoverNow")
+
+ // Pointer to the DIAL API for this profile. We get this on the UI thread.
+ DialAPI* dial_;
+
+ // Result of the discoverNow call to the DIAL registry. This result is
+ // retrieved on the IO thread but the function result is returned on the UI
+ // thread.
+ bool result_;
+};
+
+} // namespace api
+
+} // namespace extensions
+
+#endif // CHROME_BROWSER_EXTENSIONS_API_DIAL_DIAL_API_H_
« no previous file with comments | « no previous file | chrome/browser/extensions/api/dial/dial_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698