| 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> |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 | 24 |
| 25 namespace extensions { | 25 namespace extensions { |
| 26 | 26 |
| 27 class CopresenceService : public BrowserContextKeyedAPI, | 27 class CopresenceService : public BrowserContextKeyedAPI, |
| 28 public copresence::CopresenceDelegate { | 28 public copresence::CopresenceDelegate { |
| 29 public: | 29 public: |
| 30 explicit CopresenceService(content::BrowserContext* context); | 30 explicit CopresenceService(content::BrowserContext* context); |
| 31 virtual ~CopresenceService(); | 31 virtual ~CopresenceService(); |
| 32 | 32 |
| 33 // BrowserContextKeyedAPI implementation. | 33 // BrowserContextKeyedAPI implementation. |
| 34 virtual void Shutdown() OVERRIDE; | 34 virtual void Shutdown() override; |
| 35 | 35 |
| 36 // These accessors will always return an object (except during shutdown). | 36 // These accessors will always return an object (except during shutdown). |
| 37 // If the object doesn't exist, they will create one first. | 37 // If the object doesn't exist, they will create one first. |
| 38 copresence::CopresenceManager* manager(); | 38 copresence::CopresenceManager* manager(); |
| 39 copresence::WhispernetClient* whispernet_client(); | 39 copresence::WhispernetClient* whispernet_client(); |
| 40 | 40 |
| 41 // A registry containing the app id's associated with every subscription. | 41 // A registry containing the app id's associated with every subscription. |
| 42 SubscriptionToAppMap& apps_by_subscription_id() { | 42 SubscriptionToAppMap& apps_by_subscription_id() { |
| 43 return apps_by_subscription_id_; | 43 return apps_by_subscription_id_; |
| 44 } | 44 } |
| 45 | 45 |
| 46 void set_api_key(const std::string& api_key) { api_key_ = api_key; } | 46 void set_api_key(const std::string& api_key) { api_key_ = api_key; } |
| 47 | 47 |
| 48 // Manager override for testing. | 48 // Manager override for testing. |
| 49 void set_manager_for_testing( | 49 void set_manager_for_testing( |
| 50 scoped_ptr<copresence::CopresenceManager> manager); | 50 scoped_ptr<copresence::CopresenceManager> manager); |
| 51 | 51 |
| 52 // BrowserContextKeyedAPI implementation. | 52 // BrowserContextKeyedAPI implementation. |
| 53 static BrowserContextKeyedAPIFactory<CopresenceService>* GetFactoryInstance(); | 53 static BrowserContextKeyedAPIFactory<CopresenceService>* GetFactoryInstance(); |
| 54 | 54 |
| 55 private: | 55 private: |
| 56 friend class BrowserContextKeyedAPIFactory<CopresenceService>; | 56 friend class BrowserContextKeyedAPIFactory<CopresenceService>; |
| 57 | 57 |
| 58 // CopresenceDelegate implementation | 58 // CopresenceDelegate implementation |
| 59 virtual void HandleMessages( | 59 virtual void HandleMessages( |
| 60 const std::string& app_id, | 60 const std::string& app_id, |
| 61 const std::string& subscription_id, | 61 const std::string& subscription_id, |
| 62 const std::vector<copresence::Message>& message) OVERRIDE; | 62 const std::vector<copresence::Message>& message) override; |
| 63 virtual net::URLRequestContextGetter* GetRequestContext() const OVERRIDE; | 63 virtual net::URLRequestContextGetter* GetRequestContext() const override; |
| 64 virtual const std::string GetPlatformVersionString() const OVERRIDE; | 64 virtual const std::string GetPlatformVersionString() const override; |
| 65 virtual const std::string GetAPIKey() const OVERRIDE; | 65 virtual const std::string GetAPIKey() const override; |
| 66 virtual copresence::WhispernetClient* GetWhispernetClient() OVERRIDE; | 66 virtual copresence::WhispernetClient* GetWhispernetClient() override; |
| 67 | 67 |
| 68 // BrowserContextKeyedAPI implementation. | 68 // BrowserContextKeyedAPI implementation. |
| 69 static const char* service_name() { return "CopresenceService"; } | 69 static const char* service_name() { return "CopresenceService"; } |
| 70 | 70 |
| 71 bool is_shutting_down_; | 71 bool is_shutting_down_; |
| 72 std::map<std::string, std::string> apps_by_subscription_id_; | 72 std::map<std::string, std::string> apps_by_subscription_id_; |
| 73 | 73 |
| 74 content::BrowserContext* const browser_context_; | 74 content::BrowserContext* const browser_context_; |
| 75 std::string api_key_; | 75 std::string api_key_; |
| 76 | 76 |
| 77 scoped_ptr<copresence::CopresenceManager> manager_; | 77 scoped_ptr<copresence::CopresenceManager> manager_; |
| 78 scoped_ptr<copresence::WhispernetClient> whispernet_client_; | 78 scoped_ptr<copresence::WhispernetClient> whispernet_client_; |
| 79 | 79 |
| 80 DISALLOW_COPY_AND_ASSIGN(CopresenceService); | 80 DISALLOW_COPY_AND_ASSIGN(CopresenceService); |
| 81 }; | 81 }; |
| 82 | 82 |
| 83 template <> | 83 template <> |
| 84 void BrowserContextKeyedAPIFactory< | 84 void BrowserContextKeyedAPIFactory< |
| 85 CopresenceService>::DeclareFactoryDependencies(); | 85 CopresenceService>::DeclareFactoryDependencies(); |
| 86 | 86 |
| 87 class CopresenceExecuteFunction : public ChromeUIThreadExtensionFunction { | 87 class CopresenceExecuteFunction : public ChromeUIThreadExtensionFunction { |
| 88 public: | 88 public: |
| 89 DECLARE_EXTENSION_FUNCTION("copresence.execute", COPRESENCE_EXECUTE); | 89 DECLARE_EXTENSION_FUNCTION("copresence.execute", COPRESENCE_EXECUTE); |
| 90 | 90 |
| 91 protected: | 91 protected: |
| 92 virtual ~CopresenceExecuteFunction() {} | 92 virtual ~CopresenceExecuteFunction() {} |
| 93 virtual ExtensionFunction::ResponseAction Run() OVERRIDE; | 93 virtual ExtensionFunction::ResponseAction Run() override; |
| 94 | 94 |
| 95 private: | 95 private: |
| 96 void SendResult(copresence::CopresenceStatus status); | 96 void SendResult(copresence::CopresenceStatus status); |
| 97 }; | 97 }; |
| 98 | 98 |
| 99 class CopresenceSetApiKeyFunction : public ChromeUIThreadExtensionFunction { | 99 class CopresenceSetApiKeyFunction : public ChromeUIThreadExtensionFunction { |
| 100 public: | 100 public: |
| 101 DECLARE_EXTENSION_FUNCTION("copresence.setApiKey", COPRESENCE_SETAPIKEY); | 101 DECLARE_EXTENSION_FUNCTION("copresence.setApiKey", COPRESENCE_SETAPIKEY); |
| 102 | 102 |
| 103 protected: | 103 protected: |
| 104 virtual ~CopresenceSetApiKeyFunction() {} | 104 virtual ~CopresenceSetApiKeyFunction() {} |
| 105 virtual ExtensionFunction::ResponseAction Run() OVERRIDE; | 105 virtual ExtensionFunction::ResponseAction Run() override; |
| 106 }; | 106 }; |
| 107 | 107 |
| 108 } // namespace extensions | 108 } // namespace extensions |
| 109 | 109 |
| 110 #endif // CHROME_BROWSER_EXTENSIONS_API_COPRESENCE_COPRESENCE_API_H_ | 110 #endif // CHROME_BROWSER_EXTENSIONS_API_COPRESENCE_COPRESENCE_API_H_ |
| OLD | NEW |