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 25 matching lines...) Expand all Loading... | |
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& app_id, |
47 const std::string& api_key); | |
48 void set_auth_token(const std::string& app_id, | |
49 const std::string& token); | |
47 | 50 |
48 // Manager override for testing. | 51 // Manager override for testing. |
49 void set_manager_for_testing( | 52 void set_manager_for_testing( |
50 scoped_ptr<copresence::CopresenceManager> manager); | 53 scoped_ptr<copresence::CopresenceManager> manager); |
51 | 54 |
52 // BrowserContextKeyedAPI implementation. | 55 // BrowserContextKeyedAPI implementation. |
53 static BrowserContextKeyedAPIFactory<CopresenceService>* GetFactoryInstance(); | 56 static BrowserContextKeyedAPIFactory<CopresenceService>* GetFactoryInstance(); |
54 | 57 |
55 private: | 58 private: |
56 friend class BrowserContextKeyedAPIFactory<CopresenceService>; | 59 friend class BrowserContextKeyedAPIFactory<CopresenceService>; |
57 | 60 |
58 // CopresenceDelegate implementation | 61 // CopresenceDelegate implementation |
59 virtual void HandleMessages( | 62 virtual void HandleMessages( |
60 const std::string& app_id, | 63 const std::string& app_id, |
61 const std::string& subscription_id, | 64 const std::string& subscription_id, |
62 const std::vector<copresence::Message>& message) override; | 65 const std::vector<copresence::Message>& message) override; |
63 virtual net::URLRequestContextGetter* GetRequestContext() const override; | 66 virtual net::URLRequestContextGetter* GetRequestContext() const override; |
64 virtual const std::string GetPlatformVersionString() const override; | 67 virtual const std::string GetPlatformVersionString() const override; |
65 virtual const std::string GetAPIKey() const override; | 68 virtual const std::string GetAPIKey(const std::string& app_id) const override; |
69 virtual const std::string GetAuthToken(const std::string& app_id) const | |
70 override; | |
66 virtual copresence::WhispernetClient* GetWhispernetClient() override; | 71 virtual copresence::WhispernetClient* GetWhispernetClient() override; |
67 | 72 |
68 // BrowserContextKeyedAPI implementation. | 73 // BrowserContextKeyedAPI implementation. |
69 static const char* service_name() { return "CopresenceService"; } | 74 static const char* service_name() { return "CopresenceService"; } |
70 | 75 |
71 bool is_shutting_down_; | 76 bool is_shutting_down_; |
72 std::map<std::string, std::string> apps_by_subscription_id_; | 77 std::map<std::string, std::string> apps_by_subscription_id_; |
73 | 78 |
74 content::BrowserContext* const browser_context_; | 79 content::BrowserContext* const browser_context_; |
75 std::string api_key_; | 80 std::map<std::string, std::string> api_keys_by_app_; |
rkc
2014/10/21 22:48:38
Instead of three different maps, all indexing by a
Charlie
2014/10/21 23:19:44
Putting the subscriptions IDs in doesn't actually
| |
81 std::map<std::string, std::string> auth_tokens_by_app_; | |
76 | 82 |
77 scoped_ptr<copresence::CopresenceManager> manager_; | 83 scoped_ptr<copresence::CopresenceManager> manager_; |
78 scoped_ptr<copresence::WhispernetClient> whispernet_client_; | 84 scoped_ptr<copresence::WhispernetClient> whispernet_client_; |
79 | 85 |
80 DISALLOW_COPY_AND_ASSIGN(CopresenceService); | 86 DISALLOW_COPY_AND_ASSIGN(CopresenceService); |
81 }; | 87 }; |
82 | 88 |
83 template <> | 89 template <> |
84 void BrowserContextKeyedAPIFactory< | 90 void BrowserContextKeyedAPIFactory< |
85 CopresenceService>::DeclareFactoryDependencies(); | 91 CopresenceService>::DeclareFactoryDependencies(); |
(...skipping 12 matching lines...) Expand all Loading... | |
98 | 104 |
99 class CopresenceSetApiKeyFunction : public ChromeUIThreadExtensionFunction { | 105 class CopresenceSetApiKeyFunction : public ChromeUIThreadExtensionFunction { |
100 public: | 106 public: |
101 DECLARE_EXTENSION_FUNCTION("copresence.setApiKey", COPRESENCE_SETAPIKEY); | 107 DECLARE_EXTENSION_FUNCTION("copresence.setApiKey", COPRESENCE_SETAPIKEY); |
102 | 108 |
103 protected: | 109 protected: |
104 virtual ~CopresenceSetApiKeyFunction() {} | 110 virtual ~CopresenceSetApiKeyFunction() {} |
105 virtual ExtensionFunction::ResponseAction Run() override; | 111 virtual ExtensionFunction::ResponseAction Run() override; |
106 }; | 112 }; |
107 | 113 |
114 class CopresenceSetAuthTokenFunction : public ChromeUIThreadExtensionFunction { | |
115 public: | |
116 DECLARE_EXTENSION_FUNCTION("copresence.setAuthToken", | |
117 COPRESENCE_SETAUTHTOKEN); | |
118 | |
119 protected: | |
120 virtual ~CopresenceSetAuthTokenFunction() {} | |
121 virtual ExtensionFunction::ResponseAction Run() override; | |
122 }; | |
123 | |
108 } // namespace extensions | 124 } // namespace extensions |
109 | 125 |
110 #endif // CHROME_BROWSER_EXTENSIONS_API_COPRESENCE_COPRESENCE_API_H_ | 126 #endif // CHROME_BROWSER_EXTENSIONS_API_COPRESENCE_COPRESENCE_API_H_ |
OLD | NEW |