| 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 <set> |
| 9 #include <string> | 10 #include <string> |
| 10 #include <vector> | 11 #include <vector> |
| 11 | 12 |
| 12 #include "base/macros.h" | 13 #include "base/macros.h" |
| 13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 14 #include "chrome/browser/extensions/api/copresence/copresence_translations.h" | 15 #include "chrome/browser/extensions/api/copresence/copresence_translations.h" |
| 15 #include "chrome/browser/extensions/chrome_extension_function.h" | 16 #include "chrome/browser/extensions/chrome_extension_function.h" |
| 16 #include "chrome/common/extensions/api/copresence.h" | 17 #include "chrome/common/extensions/api/copresence.h" |
| 17 #include "components/copresence/public/copresence_delegate.h" | 18 #include "components/copresence/public/copresence_delegate.h" |
| 18 #include "extensions/browser/browser_context_keyed_api_factory.h" | 19 #include "extensions/browser/browser_context_keyed_api_factory.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 38 // These accessors will always return an object (except during shutdown). | 39 // These accessors will always return an object (except during shutdown). |
| 39 // If the object doesn't exist, they will create one first. | 40 // If the object doesn't exist, they will create one first. |
| 40 copresence::CopresenceManager* manager(); | 41 copresence::CopresenceManager* manager(); |
| 41 copresence::WhispernetClient* whispernet_client(); | 42 copresence::WhispernetClient* whispernet_client(); |
| 42 | 43 |
| 43 // A registry containing the app id's associated with every subscription. | 44 // A registry containing the app id's associated with every subscription. |
| 44 SubscriptionToAppMap& apps_by_subscription_id() { | 45 SubscriptionToAppMap& apps_by_subscription_id() { |
| 45 return apps_by_subscription_id_; | 46 return apps_by_subscription_id_; |
| 46 } | 47 } |
| 47 | 48 |
| 49 std::set<std::string>& copresence_apps() { return copresence_apps_; } |
| 50 |
| 48 void set_api_key(const std::string& app_id, | 51 void set_api_key(const std::string& app_id, |
| 49 const std::string& api_key); | 52 const std::string& api_key); |
| 50 void set_auth_token(const std::string& token); | 53 void set_auth_token(const std::string& token); |
| 51 | 54 |
| 52 // Manager override for testing. | 55 // Manager override for testing. |
| 53 void set_manager_for_testing( | 56 void set_manager_for_testing( |
| 54 scoped_ptr<copresence::CopresenceManager> manager); | 57 scoped_ptr<copresence::CopresenceManager> manager); |
| 55 | 58 |
| 56 // BrowserContextKeyedAPI implementation. | 59 // BrowserContextKeyedAPI implementation. |
| 57 static BrowserContextKeyedAPIFactory<CopresenceService>* GetFactoryInstance(); | 60 static BrowserContextKeyedAPIFactory<CopresenceService>* GetFactoryInstance(); |
| 58 | 61 |
| 59 private: | 62 private: |
| 60 friend class BrowserContextKeyedAPIFactory<CopresenceService>; | 63 friend class BrowserContextKeyedAPIFactory<CopresenceService>; |
| 61 | 64 |
| 62 // CopresenceDelegate implementation | 65 // CopresenceDelegate implementation |
| 63 void HandleMessages(const std::string& app_id, | 66 void HandleMessages(const std::string& app_id, |
| 64 const std::string& subscription_id, | 67 const std::string& subscription_id, |
| 65 const std::vector<copresence::Message>& message) override; | 68 const std::vector<copresence::Message>& message) override; |
| 69 void HandleStatusUpdate(copresence::CopresenceStatus status) override; |
| 66 net::URLRequestContextGetter* GetRequestContext() const override; | 70 net::URLRequestContextGetter* GetRequestContext() const override; |
| 67 const std::string GetPlatformVersionString() const override; | 71 const std::string GetPlatformVersionString() const override; |
| 68 const std::string GetAPIKey(const std::string& app_id) const override; | 72 const std::string GetAPIKey(const std::string& app_id) const override; |
| 69 const std::string GetAuthToken() const override; | 73 const std::string GetAuthToken() const override; |
| 70 copresence::WhispernetClient* GetWhispernetClient() override; | 74 copresence::WhispernetClient* GetWhispernetClient() override; |
| 71 | 75 |
| 72 // BrowserContextKeyedAPI implementation. | 76 // BrowserContextKeyedAPI implementation. |
| 73 static const char* service_name() { return "CopresenceService"; } | 77 static const char* service_name() { return "CopresenceService"; } |
| 74 | 78 |
| 75 bool is_shutting_down_; | 79 bool is_shutting_down_; |
| 76 std::map<std::string, std::string> apps_by_subscription_id_; | 80 std::map<std::string, std::string> apps_by_subscription_id_; |
| 81 std::set<std::string> copresence_apps_; |
| 77 | 82 |
| 78 content::BrowserContext* const browser_context_; | 83 content::BrowserContext* const browser_context_; |
| 79 std::map<std::string, std::string> api_keys_by_app_; | 84 std::map<std::string, std::string> api_keys_by_app_; |
| 80 | 85 |
| 81 // TODO(ckehoe): This is a temporary hack. | 86 // TODO(ckehoe): This is a temporary hack. |
| 82 // Auth tokens from different apps needs to be separated properly. | 87 // Auth tokens from different apps needs to be separated properly. |
| 83 std::string auth_token_; | 88 std::string auth_token_; |
| 84 | 89 |
| 85 scoped_ptr<copresence::CopresenceManager> manager_; | 90 scoped_ptr<copresence::CopresenceManager> manager_; |
| 86 scoped_ptr<ChromeWhispernetClient> whispernet_client_; | 91 scoped_ptr<ChromeWhispernetClient> whispernet_client_; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 COPRESENCE_SETAUTHTOKEN); | 124 COPRESENCE_SETAUTHTOKEN); |
| 120 | 125 |
| 121 protected: | 126 protected: |
| 122 virtual ~CopresenceSetAuthTokenFunction() {} | 127 virtual ~CopresenceSetAuthTokenFunction() {} |
| 123 virtual ExtensionFunction::ResponseAction Run() override; | 128 virtual ExtensionFunction::ResponseAction Run() override; |
| 124 }; | 129 }; |
| 125 | 130 |
| 126 } // namespace extensions | 131 } // namespace extensions |
| 127 | 132 |
| 128 #endif // CHROME_BROWSER_EXTENSIONS_API_COPRESENCE_COPRESENCE_API_H_ | 133 #endif // CHROME_BROWSER_EXTENSIONS_API_COPRESENCE_COPRESENCE_API_H_ |
| OLD | NEW |