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 #include "chrome/browser/extensions/api/copresence/copresence_api.h" | 5 #include "chrome/browser/extensions/api/copresence/copresence_api.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "chrome/browser/copresence/chrome_whispernet_client.h" | 10 #include "chrome/browser/copresence/chrome_whispernet_client.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 api_keys_by_app_[app_id] = api_key; | 85 api_keys_by_app_[app_id] = api_key; |
86 } | 86 } |
87 | 87 |
88 void CopresenceService::set_auth_token(const std::string& app_id, | 88 void CopresenceService::set_auth_token(const std::string& app_id, |
89 const std::string& token) { | 89 const std::string& token) { |
90 DCHECK(!app_id.empty()); | 90 DCHECK(!app_id.empty()); |
91 auth_tokens_by_app_[app_id] = token; | 91 auth_tokens_by_app_[app_id] = token; |
92 } | 92 } |
93 | 93 |
94 void CopresenceService::set_manager_for_testing( | 94 void CopresenceService::set_manager_for_testing( |
95 scoped_ptr<copresence::CopresenceManager> manager) { | 95 std::unique_ptr<copresence::CopresenceManager> manager) { |
96 manager_ = std::move(manager); | 96 manager_ = std::move(manager); |
97 } | 97 } |
98 | 98 |
99 void CopresenceService::ResetState() { | 99 void CopresenceService::ResetState() { |
100 DVLOG(2) << "Deleting copresence state"; | 100 DVLOG(2) << "Deleting copresence state"; |
101 GetPrefService()->ClearPref(prefs::kCopresenceAuthenticatedDeviceId); | 101 GetPrefService()->ClearPref(prefs::kCopresenceAuthenticatedDeviceId); |
102 GetPrefService()->ClearPref(prefs::kCopresenceAnonymousDeviceId); | 102 GetPrefService()->ClearPref(prefs::kCopresenceAnonymousDeviceId); |
103 manager_ = nullptr; | 103 manager_ = nullptr; |
104 } | 104 } |
105 | 105 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 api::copresence::Message api_message; | 141 api::copresence::Message api_message; |
142 api_message.type = message.type().type(); | 142 api_message.type = message.type().type(); |
143 api_message.payload.assign(message.payload().begin(), | 143 api_message.payload.assign(message.payload().begin(), |
144 message.payload().end()); | 144 message.payload().end()); |
145 api_messages.push_back(std::move(api_message)); | 145 api_messages.push_back(std::move(api_message)); |
146 DVLOG(2) << "Dispatching message of type " << api_message.type << ":\n" | 146 DVLOG(2) << "Dispatching message of type " << api_message.type << ":\n" |
147 << message.payload(); | 147 << message.payload(); |
148 } | 148 } |
149 | 149 |
150 // Send the messages to the client app. | 150 // Send the messages to the client app. |
151 scoped_ptr<Event> event(new Event( | 151 std::unique_ptr<Event> event(new Event( |
152 events::COPRESENCE_ON_MESSAGES_RECEIVED, OnMessagesReceived::kEventName, | 152 events::COPRESENCE_ON_MESSAGES_RECEIVED, OnMessagesReceived::kEventName, |
153 OnMessagesReceived::Create(subscription_id, api_messages), | 153 OnMessagesReceived::Create(subscription_id, api_messages), |
154 browser_context_)); | 154 browser_context_)); |
155 EventRouter::Get(browser_context_) | 155 EventRouter::Get(browser_context_) |
156 ->DispatchEventToExtension(app_id, std::move(event)); | 156 ->DispatchEventToExtension(app_id, std::move(event)); |
157 DVLOG(2) << "Passed " << api_messages.size() << " messages to app \"" | 157 DVLOG(2) << "Passed " << api_messages.size() << " messages to app \"" |
158 << app_id << "\" for subscription \"" << subscription_id << "\""; | 158 << app_id << "\" for subscription \"" << subscription_id << "\""; |
159 } | 159 } |
160 | 160 |
161 void CopresenceService::HandleStatusUpdate( | 161 void CopresenceService::HandleStatusUpdate( |
162 copresence::CopresenceStatus status) { | 162 copresence::CopresenceStatus status) { |
163 DCHECK_EQ(copresence::AUDIO_FAIL, status); | 163 DCHECK_EQ(copresence::AUDIO_FAIL, status); |
164 scoped_ptr<Event> event(new Event( | 164 std::unique_ptr<Event> event(new Event( |
165 events::COPRESENCE_ON_STATUS_UPDATED, OnStatusUpdated::kEventName, | 165 events::COPRESENCE_ON_STATUS_UPDATED, OnStatusUpdated::kEventName, |
166 OnStatusUpdated::Create(api::copresence::STATUS_AUDIOFAILED), | 166 OnStatusUpdated::Create(api::copresence::STATUS_AUDIOFAILED), |
167 browser_context_)); | 167 browser_context_)); |
168 EventRouter::Get(browser_context_)->BroadcastEvent(std::move(event)); | 168 EventRouter::Get(browser_context_)->BroadcastEvent(std::move(event)); |
169 DVLOG(2) << "Sent Audio Failed status update."; | 169 DVLOG(2) << "Sent Audio Failed status update."; |
170 } | 170 } |
171 | 171 |
172 net::URLRequestContextGetter* CopresenceService::GetRequestContext() const { | 172 net::URLRequestContextGetter* CopresenceService::GetRequestContext() const { |
173 return browser_context_->GetRequestContext(); | 173 return browser_context_->GetRequestContext(); |
174 } | 174 } |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 } | 233 } |
234 | 234 |
235 template <> | 235 template <> |
236 void | 236 void |
237 BrowserContextKeyedAPIFactory<CopresenceService>::DeclareFactoryDependencies() { | 237 BrowserContextKeyedAPIFactory<CopresenceService>::DeclareFactoryDependencies() { |
238 DependsOn(ExtensionsBrowserClient::Get()->GetExtensionSystemFactory()); | 238 DependsOn(ExtensionsBrowserClient::Get()->GetExtensionSystemFactory()); |
239 } | 239 } |
240 | 240 |
241 // CopresenceExecuteFunction implementation. | 241 // CopresenceExecuteFunction implementation. |
242 ExtensionFunction::ResponseAction CopresenceExecuteFunction::Run() { | 242 ExtensionFunction::ResponseAction CopresenceExecuteFunction::Run() { |
243 scoped_ptr<Execute::Params> params(Execute::Params::Create(*args_)); | 243 std::unique_ptr<Execute::Params> params(Execute::Params::Create(*args_)); |
244 EXTENSION_FUNCTION_VALIDATE(params.get()); | 244 EXTENSION_FUNCTION_VALIDATE(params.get()); |
245 | 245 |
246 CopresenceService* service = | 246 CopresenceService* service = |
247 CopresenceService::GetFactoryInstance()->Get(browser_context()); | 247 CopresenceService::GetFactoryInstance()->Get(browser_context()); |
248 | 248 |
249 // This can only happen if we're shutting down. In all other cases, if we | 249 // This can only happen if we're shutting down. In all other cases, if we |
250 // don't have a manager, we'll create one. | 250 // don't have a manager, we'll create one. |
251 if (!service->manager()) | 251 if (!service->manager()) |
252 return RespondNow(Error(kShuttingDownMessage)); | 252 return RespondNow(Error(kShuttingDownMessage)); |
253 | 253 |
(...skipping 17 matching lines...) Expand all Loading... |
271 void CopresenceExecuteFunction::SendResult( | 271 void CopresenceExecuteFunction::SendResult( |
272 copresence::CopresenceStatus status) { | 272 copresence::CopresenceStatus status) { |
273 api::copresence::ExecuteStatus api_status = | 273 api::copresence::ExecuteStatus api_status = |
274 (status == copresence::SUCCESS) ? api::copresence::EXECUTE_STATUS_SUCCESS | 274 (status == copresence::SUCCESS) ? api::copresence::EXECUTE_STATUS_SUCCESS |
275 : api::copresence::EXECUTE_STATUS_FAILED; | 275 : api::copresence::EXECUTE_STATUS_FAILED; |
276 Respond(ArgumentList(Execute::Results::Create(api_status))); | 276 Respond(ArgumentList(Execute::Results::Create(api_status))); |
277 } | 277 } |
278 | 278 |
279 // CopresenceSetApiKeyFunction implementation. | 279 // CopresenceSetApiKeyFunction implementation. |
280 ExtensionFunction::ResponseAction CopresenceSetApiKeyFunction::Run() { | 280 ExtensionFunction::ResponseAction CopresenceSetApiKeyFunction::Run() { |
281 scoped_ptr<SetApiKey::Params> params(SetApiKey::Params::Create(*args_)); | 281 std::unique_ptr<SetApiKey::Params> params(SetApiKey::Params::Create(*args_)); |
282 EXTENSION_FUNCTION_VALIDATE(params.get()); | 282 EXTENSION_FUNCTION_VALIDATE(params.get()); |
283 | 283 |
284 LOG(WARNING) << "copresence.setApiKey() is deprecated. " | 284 LOG(WARNING) << "copresence.setApiKey() is deprecated. " |
285 << "Put the key in the manifest at copresence.api_key instead."; | 285 << "Put the key in the manifest at copresence.api_key instead."; |
286 | 286 |
287 // The api key may be set to empty, to clear it. | 287 // The api key may be set to empty, to clear it. |
288 CopresenceService::GetFactoryInstance()->Get(browser_context()) | 288 CopresenceService::GetFactoryInstance()->Get(browser_context()) |
289 ->set_api_key(extension_id(), params->api_key); | 289 ->set_api_key(extension_id(), params->api_key); |
290 return RespondNow(NoArguments()); | 290 return RespondNow(NoArguments()); |
291 } | 291 } |
292 | 292 |
293 // CopresenceSetAuthTokenFunction implementation | 293 // CopresenceSetAuthTokenFunction implementation |
294 ExtensionFunction::ResponseAction CopresenceSetAuthTokenFunction::Run() { | 294 ExtensionFunction::ResponseAction CopresenceSetAuthTokenFunction::Run() { |
295 scoped_ptr<SetAuthToken::Params> params(SetAuthToken::Params::Create(*args_)); | 295 std::unique_ptr<SetAuthToken::Params> params( |
| 296 SetAuthToken::Params::Create(*args_)); |
296 EXTENSION_FUNCTION_VALIDATE(params.get()); | 297 EXTENSION_FUNCTION_VALIDATE(params.get()); |
297 | 298 |
298 // The token may be set to empty, to clear it. | 299 // The token may be set to empty, to clear it. |
299 CopresenceService::GetFactoryInstance()->Get(browser_context()) | 300 CopresenceService::GetFactoryInstance()->Get(browser_context()) |
300 ->set_auth_token(extension_id(), params->token); | 301 ->set_auth_token(extension_id(), params->token); |
301 return RespondNow(NoArguments()); | 302 return RespondNow(NoArguments()); |
302 } | 303 } |
303 | 304 |
304 } // namespace extensions | 305 } // namespace extensions |
OLD | NEW |