| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_COPRESENCE_COPRESENCE_API_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_COPRESENCE_COPRESENCE_API_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_COPRESENCE_COPRESENCE_API_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_COPRESENCE_COPRESENCE_API_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "chrome/browser/extensions/api/copresence/copresence_translations.h" | 14 #include "chrome/browser/extensions/api/copresence/copresence_translations.h" |
| 15 #include "chrome/browser/extensions/chrome_extension_function.h" | 15 #include "chrome/browser/extensions/chrome_extension_function.h" |
| 16 #include "chrome/common/extensions/api/copresence.h" | 16 #include "chrome/common/extensions/api/copresence.h" |
| 17 #include "components/copresence/public/copresence_delegate.h" | 17 #include "components/copresence/public/copresence_delegate.h" |
| 18 #include "extensions/browser/browser_context_keyed_api_factory.h" | 18 #include "extensions/browser/browser_context_keyed_api_factory.h" |
| 19 | 19 |
| 20 class ChromeWhispernetClient; | 20 class ChromeWhispernetClient; |
| 21 | 21 |
| 22 namespace copresence { | 22 namespace audio_modem { |
| 23 class CopresenceManager; | |
| 24 class WhispernetClient; | 23 class WhispernetClient; |
| 25 } | 24 } |
| 26 | 25 |
| 26 namespace copresence { |
| 27 class CopresenceManager; |
| 28 } |
| 29 |
| 27 namespace gcm { | 30 namespace gcm { |
| 28 class GCMDriver; | 31 class GCMDriver; |
| 29 } | 32 } |
| 30 | 33 |
| 31 namespace user_prefs { | 34 namespace user_prefs { |
| 32 class PrefRegistrySyncable; | 35 class PrefRegistrySyncable; |
| 33 } | 36 } |
| 34 | 37 |
| 35 namespace extensions { | 38 namespace extensions { |
| 36 | 39 |
| 37 class CopresenceService final : public BrowserContextKeyedAPI, | 40 class CopresenceService final : public BrowserContextKeyedAPI, |
| 38 public copresence::CopresenceDelegate { | 41 public copresence::CopresenceDelegate { |
| 39 public: | 42 public: |
| 40 explicit CopresenceService(content::BrowserContext* context); | 43 explicit CopresenceService(content::BrowserContext* context); |
| 41 ~CopresenceService() override; | 44 ~CopresenceService() override; |
| 42 | 45 |
| 43 // BrowserContextKeyedAPI implementation. | 46 // BrowserContextKeyedAPI implementation. |
| 44 static const bool kServiceHasOwnInstanceInIncognito = true; | 47 static const bool kServiceHasOwnInstanceInIncognito = true; |
| 45 void Shutdown() override; | 48 void Shutdown() override; |
| 46 | 49 |
| 47 // These accessors will always return an object (except during shutdown). | 50 // These accessors will always return an object (except during shutdown). |
| 48 // If the object doesn't exist, they will create one first. | 51 // If the object doesn't exist, they will create one first. |
| 49 copresence::CopresenceManager* manager(); | 52 copresence::CopresenceManager* manager(); |
| 50 copresence::WhispernetClient* whispernet_client(); | 53 // TODO(ckehoe): Merge this with GetWhispernetClient() below. |
| 54 audio_modem::WhispernetClient* whispernet_client(); |
| 51 | 55 |
| 52 // A registry containing the app id's associated with every subscription. | 56 // A registry containing the app id's associated with every subscription. |
| 53 SubscriptionToAppMap& apps_by_subscription_id() { | 57 SubscriptionToAppMap& apps_by_subscription_id() { |
| 54 return apps_by_subscription_id_; | 58 return apps_by_subscription_id_; |
| 55 } | 59 } |
| 56 | 60 |
| 57 const std::string auth_token(const std::string& app_id) const; | 61 const std::string auth_token(const std::string& app_id) const; |
| 58 | 62 |
| 59 void set_api_key(const std::string& app_id, | 63 void set_api_key(const std::string& app_id, |
| 60 const std::string& api_key); | 64 const std::string& api_key); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 80 | 84 |
| 81 // CopresenceDelegate implementation | 85 // CopresenceDelegate implementation |
| 82 void HandleMessages(const std::string& app_id, | 86 void HandleMessages(const std::string& app_id, |
| 83 const std::string& subscription_id, | 87 const std::string& subscription_id, |
| 84 const std::vector<copresence::Message>& message) override; | 88 const std::vector<copresence::Message>& message) override; |
| 85 void HandleStatusUpdate(copresence::CopresenceStatus status) override; | 89 void HandleStatusUpdate(copresence::CopresenceStatus status) override; |
| 86 net::URLRequestContextGetter* GetRequestContext() const override; | 90 net::URLRequestContextGetter* GetRequestContext() const override; |
| 87 const std::string GetPlatformVersionString() const override; | 91 const std::string GetPlatformVersionString() const override; |
| 88 const std::string GetAPIKey(const std::string& app_id) const override; | 92 const std::string GetAPIKey(const std::string& app_id) const override; |
| 89 const std::string GetProjectId(const std::string& app_id) const override; | 93 const std::string GetProjectId(const std::string& app_id) const override; |
| 90 copresence::WhispernetClient* GetWhispernetClient() override; | 94 audio_modem::WhispernetClient* GetWhispernetClient() override; |
| 91 gcm::GCMDriver* GetGCMDriver() override; | 95 gcm::GCMDriver* GetGCMDriver() override; |
| 92 const std::string GetDeviceId(bool authenticated) override; | 96 const std::string GetDeviceId(bool authenticated) override; |
| 93 void SaveDeviceId(bool authenticated, const std::string& device_id) override; | 97 void SaveDeviceId(bool authenticated, const std::string& device_id) override; |
| 94 | 98 |
| 95 // BrowserContextKeyedAPI implementation. | 99 // BrowserContextKeyedAPI implementation. |
| 96 static const char* service_name() { return "CopresenceService"; } | 100 static const char* service_name() { return "CopresenceService"; } |
| 97 | 101 |
| 98 PrefService* GetPrefService(); | 102 PrefService* GetPrefService(); |
| 99 | 103 |
| 100 bool is_shutting_down_; | 104 bool is_shutting_down_; |
| 101 content::BrowserContext* const browser_context_; | 105 content::BrowserContext* const browser_context_; |
| 102 | 106 |
| 103 std::map<std::string, std::string> apps_by_subscription_id_; | 107 std::map<std::string, std::string> apps_by_subscription_id_; |
| 104 | 108 |
| 105 std::map<std::string, std::string> api_keys_by_app_; | 109 std::map<std::string, std::string> api_keys_by_app_; |
| 106 std::map<std::string, std::string> auth_tokens_by_app_; | 110 std::map<std::string, std::string> auth_tokens_by_app_; |
| 107 | 111 |
| 108 scoped_ptr<copresence::CopresenceManager> manager_; | 112 scoped_ptr<copresence::CopresenceManager> manager_; |
| 109 scoped_ptr<ChromeWhispernetClient> whispernet_client_; | 113 scoped_ptr<audio_modem::WhispernetClient> whispernet_client_; |
| 110 | 114 |
| 111 DISALLOW_COPY_AND_ASSIGN(CopresenceService); | 115 DISALLOW_COPY_AND_ASSIGN(CopresenceService); |
| 112 }; | 116 }; |
| 113 | 117 |
| 114 template <> | 118 template <> |
| 115 void BrowserContextKeyedAPIFactory< | 119 void BrowserContextKeyedAPIFactory< |
| 116 CopresenceService>::DeclareFactoryDependencies(); | 120 CopresenceService>::DeclareFactoryDependencies(); |
| 117 | 121 |
| 118 class CopresenceExecuteFunction : public ChromeUIThreadExtensionFunction { | 122 class CopresenceExecuteFunction : public ChromeUIThreadExtensionFunction { |
| 119 public: | 123 public: |
| (...skipping 22 matching lines...) Expand all Loading... |
| 142 COPRESENCE_SETAUTHTOKEN); | 146 COPRESENCE_SETAUTHTOKEN); |
| 143 | 147 |
| 144 protected: | 148 protected: |
| 145 ~CopresenceSetAuthTokenFunction() override {} | 149 ~CopresenceSetAuthTokenFunction() override {} |
| 146 ExtensionFunction::ResponseAction Run() override; | 150 ExtensionFunction::ResponseAction Run() override; |
| 147 }; | 151 }; |
| 148 | 152 |
| 149 } // namespace extensions | 153 } // namespace extensions |
| 150 | 154 |
| 151 #endif // CHROME_BROWSER_EXTENSIONS_API_COPRESENCE_COPRESENCE_API_H_ | 155 #endif // CHROME_BROWSER_EXTENSIONS_API_COPRESENCE_COPRESENCE_API_H_ |
| OLD | NEW |