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> |
| 8 |
7 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
8 #include "base/memory/linked_ptr.h" | 10 #include "base/memory/linked_ptr.h" |
9 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
10 #include "chrome/browser/copresence/chrome_whispernet_client.h" | 12 #include "chrome/browser/copresence/chrome_whispernet_client.h" |
11 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" | 14 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" |
13 #include "chrome/common/channel_info.h" | 15 #include "chrome/common/channel_info.h" |
14 #include "chrome/common/extensions/api/copresence.h" | 16 #include "chrome/common/extensions/api/copresence.h" |
15 #include "chrome/common/extensions/manifest_handlers/copresence_manifest.h" | 17 #include "chrome/common/extensions/manifest_handlers/copresence_manifest.h" |
16 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 } | 87 } |
86 | 88 |
87 void CopresenceService::set_auth_token(const std::string& app_id, | 89 void CopresenceService::set_auth_token(const std::string& app_id, |
88 const std::string& token) { | 90 const std::string& token) { |
89 DCHECK(!app_id.empty()); | 91 DCHECK(!app_id.empty()); |
90 auth_tokens_by_app_[app_id] = token; | 92 auth_tokens_by_app_[app_id] = token; |
91 } | 93 } |
92 | 94 |
93 void CopresenceService::set_manager_for_testing( | 95 void CopresenceService::set_manager_for_testing( |
94 scoped_ptr<copresence::CopresenceManager> manager) { | 96 scoped_ptr<copresence::CopresenceManager> manager) { |
95 manager_ = manager.Pass(); | 97 manager_ = std::move(manager); |
96 } | 98 } |
97 | 99 |
98 void CopresenceService::ResetState() { | 100 void CopresenceService::ResetState() { |
99 DVLOG(2) << "Deleting copresence state"; | 101 DVLOG(2) << "Deleting copresence state"; |
100 GetPrefService()->ClearPref(prefs::kCopresenceAuthenticatedDeviceId); | 102 GetPrefService()->ClearPref(prefs::kCopresenceAuthenticatedDeviceId); |
101 GetPrefService()->ClearPref(prefs::kCopresenceAnonymousDeviceId); | 103 GetPrefService()->ClearPref(prefs::kCopresenceAnonymousDeviceId); |
102 manager_ = nullptr; | 104 manager_ = nullptr; |
103 } | 105 } |
104 | 106 |
105 // static | 107 // static |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 DVLOG(2) << "Dispatching message of type " << api_messages[m]->type << ":\n" | 147 DVLOG(2) << "Dispatching message of type " << api_messages[m]->type << ":\n" |
146 << messages[m].payload(); | 148 << messages[m].payload(); |
147 } | 149 } |
148 | 150 |
149 // Send the messages to the client app. | 151 // Send the messages to the client app. |
150 scoped_ptr<Event> event(new Event( | 152 scoped_ptr<Event> event(new Event( |
151 events::COPRESENCE_ON_MESSAGES_RECEIVED, OnMessagesReceived::kEventName, | 153 events::COPRESENCE_ON_MESSAGES_RECEIVED, OnMessagesReceived::kEventName, |
152 OnMessagesReceived::Create(subscription_id, api_messages), | 154 OnMessagesReceived::Create(subscription_id, api_messages), |
153 browser_context_)); | 155 browser_context_)); |
154 EventRouter::Get(browser_context_) | 156 EventRouter::Get(browser_context_) |
155 ->DispatchEventToExtension(app_id, event.Pass()); | 157 ->DispatchEventToExtension(app_id, std::move(event)); |
156 DVLOG(2) << "Passed " << api_messages.size() << " messages to app \"" | 158 DVLOG(2) << "Passed " << api_messages.size() << " messages to app \"" |
157 << app_id << "\" for subscription \"" << subscription_id << "\""; | 159 << app_id << "\" for subscription \"" << subscription_id << "\""; |
158 } | 160 } |
159 | 161 |
160 void CopresenceService::HandleStatusUpdate( | 162 void CopresenceService::HandleStatusUpdate( |
161 copresence::CopresenceStatus status) { | 163 copresence::CopresenceStatus status) { |
162 DCHECK_EQ(copresence::AUDIO_FAIL, status); | 164 DCHECK_EQ(copresence::AUDIO_FAIL, status); |
163 scoped_ptr<Event> event(new Event( | 165 scoped_ptr<Event> event(new Event( |
164 events::COPRESENCE_ON_STATUS_UPDATED, OnStatusUpdated::kEventName, | 166 events::COPRESENCE_ON_STATUS_UPDATED, OnStatusUpdated::kEventName, |
165 OnStatusUpdated::Create(api::copresence::STATUS_AUDIOFAILED), | 167 OnStatusUpdated::Create(api::copresence::STATUS_AUDIOFAILED), |
166 browser_context_)); | 168 browser_context_)); |
167 EventRouter::Get(browser_context_)->BroadcastEvent(event.Pass()); | 169 EventRouter::Get(browser_context_)->BroadcastEvent(std::move(event)); |
168 DVLOG(2) << "Sent Audio Failed status update."; | 170 DVLOG(2) << "Sent Audio Failed status update."; |
169 } | 171 } |
170 | 172 |
171 net::URLRequestContextGetter* CopresenceService::GetRequestContext() const { | 173 net::URLRequestContextGetter* CopresenceService::GetRequestContext() const { |
172 return browser_context_->GetRequestContext(); | 174 return browser_context_->GetRequestContext(); |
173 } | 175 } |
174 | 176 |
175 std::string CopresenceService::GetPlatformVersionString() const { | 177 std::string CopresenceService::GetPlatformVersionString() const { |
176 return chrome::GetVersionString(); | 178 return chrome::GetVersionString(); |
177 } | 179 } |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 scoped_ptr<SetAuthToken::Params> params(SetAuthToken::Params::Create(*args_)); | 296 scoped_ptr<SetAuthToken::Params> params(SetAuthToken::Params::Create(*args_)); |
295 EXTENSION_FUNCTION_VALIDATE(params.get()); | 297 EXTENSION_FUNCTION_VALIDATE(params.get()); |
296 | 298 |
297 // The token may be set to empty, to clear it. | 299 // The token may be set to empty, to clear it. |
298 CopresenceService::GetFactoryInstance()->Get(browser_context()) | 300 CopresenceService::GetFactoryInstance()->Get(browser_context()) |
299 ->set_auth_token(extension_id(), params->token); | 301 ->set_auth_token(extension_id(), params->token); |
300 return RespondNow(NoArguments()); | 302 return RespondNow(NoArguments()); |
301 } | 303 } |
302 | 304 |
303 } // namespace extensions | 305 } // namespace extensions |
OLD | NEW |