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 18 matching lines...) Expand all Loading... |
79 friend class BrowserContextKeyedAPIFactory<CopresenceService>; | 83 friend class BrowserContextKeyedAPIFactory<CopresenceService>; |
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 copresence::WhispernetClient* GetWhispernetClient() override; | 93 audio_modem::WhispernetClient* GetWhispernetClient() override; |
90 gcm::GCMDriver* GetGCMDriver() override; | 94 gcm::GCMDriver* GetGCMDriver() override; |
91 const std::string GetDeviceId(bool authenticated) override; | 95 const std::string GetDeviceId(bool authenticated) override; |
92 void SaveDeviceId(bool authenticated, const std::string& device_id) override; | 96 void SaveDeviceId(bool authenticated, const std::string& device_id) override; |
93 | 97 |
94 // BrowserContextKeyedAPI implementation. | 98 // BrowserContextKeyedAPI implementation. |
95 static const char* service_name() { return "CopresenceService"; } | 99 static const char* service_name() { return "CopresenceService"; } |
96 | 100 |
97 PrefService* GetPrefService(); | 101 PrefService* GetPrefService(); |
98 | 102 |
99 bool is_shutting_down_; | 103 bool is_shutting_down_; |
100 content::BrowserContext* const browser_context_; | 104 content::BrowserContext* const browser_context_; |
101 | 105 |
102 std::map<std::string, std::string> apps_by_subscription_id_; | 106 std::map<std::string, std::string> apps_by_subscription_id_; |
103 | 107 |
104 std::map<std::string, std::string> api_keys_by_app_; | 108 std::map<std::string, std::string> api_keys_by_app_; |
105 std::map<std::string, std::string> auth_tokens_by_app_; | 109 std::map<std::string, std::string> auth_tokens_by_app_; |
106 | 110 |
107 scoped_ptr<ChromeWhispernetClient> whispernet_client_; | 111 scoped_ptr<audio_modem::WhispernetClient> whispernet_client_; |
108 scoped_ptr<copresence::CopresenceManager> manager_; | 112 scoped_ptr<copresence::CopresenceManager> manager_; |
109 | 113 |
110 DISALLOW_COPY_AND_ASSIGN(CopresenceService); | 114 DISALLOW_COPY_AND_ASSIGN(CopresenceService); |
111 }; | 115 }; |
112 | 116 |
113 template <> | 117 template <> |
114 void BrowserContextKeyedAPIFactory< | 118 void BrowserContextKeyedAPIFactory< |
115 CopresenceService>::DeclareFactoryDependencies(); | 119 CopresenceService>::DeclareFactoryDependencies(); |
116 | 120 |
117 class CopresenceExecuteFunction : public ChromeUIThreadExtensionFunction { | 121 class CopresenceExecuteFunction : public ChromeUIThreadExtensionFunction { |
(...skipping 24 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 |