Index: chrome/browser/extensions/api/copresence/copresence_api.h |
diff --git a/chrome/browser/extensions/api/copresence/copresence_api.h b/chrome/browser/extensions/api/copresence/copresence_api.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..0b70e4ae026494d816e3be3d2d99877852ebc4e0 |
--- /dev/null |
+++ b/chrome/browser/extensions/api/copresence/copresence_api.h |
@@ -0,0 +1,108 @@ |
+// Copyright 2014 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_COPRESENCE_COPRESENCE_API_H_ |
+#define CHROME_BROWSER_EXTENSIONS_API_COPRESENCE_COPRESENCE_API_H_ |
+ |
+#include <map> |
+#include <string> |
+#include <vector> |
+ |
+#include "base/macros.h" |
+#include "base/memory/scoped_ptr.h" |
+#include "chrome/browser/extensions/api/copresence/copresence_translations.h" |
+#include "chrome/browser/extensions/chrome_extension_function.h" |
+#include "chrome/common/extensions/api/copresence.h" |
+#include "components/copresence/public/copresence_client_delegate.h" |
+#include "extensions/browser/browser_context_keyed_api_factory.h" |
+ |
+class PrefRegistrySimple; |
+ |
+namespace copresence { |
+class CopresenceClient; |
+class WhispernetClient; |
+} |
+ |
+namespace extensions { |
+ |
+class CopresenceService : public BrowserContextKeyedAPI, |
+ public copresence::CopresenceClientDelegate { |
+ public: |
+ explicit CopresenceService(content::BrowserContext* context); |
+ virtual ~CopresenceService(); |
+ |
+ // These accessors will always return an object. If the object doesn't exist, |
+ // they will create one first. |
+ copresence::CopresenceClient* client(); |
+ copresence::WhispernetClient* whispernet_client(); |
xiyuan
2014/08/05 21:02:35
nit: move accessors to the last.
rkc
2014/08/05 22:25:22
Done.
|
+ |
+ virtual void Shutdown() OVERRIDE; |
xiyuan
2014/08/05 21:02:35
nit: // BrowserContextKeyedAPI implementation.
rkc
2014/08/05 22:25:22
Done.
|
+ |
+ // A registry containing the app id's associated with every subscription. |
+ SubscriptionToAppMap& SubscriptionToAppsRegistry() { |
not at google - send to devlin
2014/08/05 21:05:38
should be subscription_to_apps_registry(), or real
rkc
2014/08/05 22:25:22
Done.
|
+ return apps_by_subscription_id_; |
+ } |
+ |
+ // Registers the preference for saving our device id. |
+ static void RegisterPrefs(PrefRegistrySimple* registry); |
+ |
+ // BrowserContextKeyedAPI implementation. |
+ static BrowserContextKeyedAPIFactory<CopresenceService>* GetFactoryInstance(); |
+ |
+ private: |
+ friend class BrowserContextKeyedAPIFactory<CopresenceService>; |
+ |
+ // CopresenceClientDelegate overrides: |
+ virtual void HandleMessages( |
+ const std::string& app_id, |
+ const std::string& subscription_id, |
+ const std::vector<copresence::Message>& message) OVERRIDE; |
+ virtual net::URLRequestContextGetter* GetRequestContext() const OVERRIDE; |
+ virtual const std::string GetPlatformVersionString() const OVERRIDE; |
+ virtual const std::string GetDeviceId() const OVERRIDE; |
+ virtual void SaveDeviceId(const std::string& device_id) OVERRIDE; |
+ virtual copresence::WhispernetClient* GetWhispernetClient() OVERRIDE; |
+ |
+ // BrowserContextKeyedAPI implementation. |
+ static const char* service_name() { return "CopresenceService"; } |
+ |
+ std::map<std::string, std::string> apps_by_subscription_id_; |
+ |
+ content::BrowserContext* const browser_context_; |
+ scoped_ptr<copresence::CopresenceClient> client_; |
+ scoped_ptr<copresence::WhispernetClient> whispernet_client_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(CopresenceService); |
+}; |
+ |
+template <> |
+void BrowserContextKeyedAPIFactory< |
+ CopresenceService>::DeclareFactoryDependencies(); |
+ |
+class CopresenceBatchExecuteFunction : public ChromeUIThreadExtensionFunction { |
+ public: |
+ DECLARE_EXTENSION_FUNCTION("copresence.batchExecute", |
+ COPRESENCE_BATCHEXECUTE); |
+ |
+ void SendResult(copresence::CopresenceStatus status); |
not at google - send to devlin
2014/08/05 21:05:38
this can be private
rkc
2014/08/05 22:25:22
Done.
|
+ |
+ protected: |
+ virtual ~CopresenceBatchExecuteFunction() {} |
+ virtual ExtensionFunction::ResponseAction Run() OVERRIDE; |
+}; |
+ |
+class CopresenceSetApiKeyFunction : public ChromeUIThreadExtensionFunction { |
+ public: |
+ DECLARE_EXTENSION_FUNCTION("copresence.setApiKey", COPRESENCE_SETAPIKEY); |
+ |
+ void SendResult(copresence::CopresenceStatus status); |
not at google - send to devlin
2014/08/05 21:05:38
this is never implemented
rkc
2014/08/05 22:25:22
Done.
|
+ |
+ protected: |
+ virtual ~CopresenceSetApiKeyFunction() {} |
+ virtual ExtensionFunction::ResponseAction Run() OVERRIDE; |
+}; |
+ |
+} // namespace extensions |
+ |
+#endif // CHROME_BROWSER_EXTENSIONS_API_COPRESENCE_COPRESENCE_API_H_ |