| 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 "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "base/memory/linked_ptr.h" | 8 #include "base/memory/linked_ptr.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "chrome/browser/copresence/chrome_whispernet_client.h" | 10 #include "chrome/browser/copresence/chrome_whispernet_client.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 manager_.reset(); | 64 manager_.reset(); |
| 65 whispernet_client_.reset(); | 65 whispernet_client_.reset(); |
| 66 } | 66 } |
| 67 | 67 |
| 68 copresence::CopresenceManager* CopresenceService::manager() { | 68 copresence::CopresenceManager* CopresenceService::manager() { |
| 69 if (!manager_ && !is_shutting_down_) | 69 if (!manager_ && !is_shutting_down_) |
| 70 manager_.reset(new copresence::CopresenceManagerImpl(this)); | 70 manager_.reset(new copresence::CopresenceManagerImpl(this)); |
| 71 return manager_.get(); | 71 return manager_.get(); |
| 72 } | 72 } |
| 73 | 73 |
| 74 const std::string CopresenceService::auth_token(const std::string& app_id) | 74 std::string CopresenceService::auth_token(const std::string& app_id) |
| 75 const { | 75 const { |
| 76 // This won't be const if we use map[] | 76 // This won't be const if we use map[] |
| 77 const auto& key = auth_tokens_by_app_.find(app_id); | 77 const auto& key = auth_tokens_by_app_.find(app_id); |
| 78 return key == auth_tokens_by_app_.end() ? std::string() : key->second; | 78 return key == auth_tokens_by_app_.end() ? std::string() : key->second; |
| 79 } | 79 } |
| 80 | 80 |
| 81 void CopresenceService::set_api_key(const std::string& app_id, | 81 void CopresenceService::set_api_key(const std::string& app_id, |
| 82 const std::string& api_key) { | 82 const std::string& api_key) { |
| 83 DCHECK(!app_id.empty()); | 83 DCHECK(!app_id.empty()); |
| 84 api_keys_by_app_[app_id] = api_key; | 84 api_keys_by_app_[app_id] = api_key; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 OnStatusUpdated::Create(api::copresence::STATUS_AUDIOFAILED), | 165 OnStatusUpdated::Create(api::copresence::STATUS_AUDIOFAILED), |
| 166 browser_context_)); | 166 browser_context_)); |
| 167 EventRouter::Get(browser_context_)->BroadcastEvent(event.Pass()); | 167 EventRouter::Get(browser_context_)->BroadcastEvent(event.Pass()); |
| 168 DVLOG(2) << "Sent Audio Failed status update."; | 168 DVLOG(2) << "Sent Audio Failed status update."; |
| 169 } | 169 } |
| 170 | 170 |
| 171 net::URLRequestContextGetter* CopresenceService::GetRequestContext() const { | 171 net::URLRequestContextGetter* CopresenceService::GetRequestContext() const { |
| 172 return browser_context_->GetRequestContext(); | 172 return browser_context_->GetRequestContext(); |
| 173 } | 173 } |
| 174 | 174 |
| 175 const std::string CopresenceService::GetPlatformVersionString() const { | 175 std::string CopresenceService::GetPlatformVersionString() const { |
| 176 return chrome::GetVersionString(); | 176 return chrome::GetVersionString(); |
| 177 } | 177 } |
| 178 | 178 |
| 179 const std::string | 179 std::string |
| 180 CopresenceService::GetAPIKey(const std::string& app_id) const { | 180 CopresenceService::GetAPIKey(const std::string& app_id) const { |
| 181 // Check first if the app has set its key via the API. | 181 // Check first if the app has set its key via the API. |
| 182 const auto& key = api_keys_by_app_.find(app_id); | 182 const auto& key = api_keys_by_app_.find(app_id); |
| 183 if (key != api_keys_by_app_.end()) | 183 if (key != api_keys_by_app_.end()) |
| 184 return key->second; | 184 return key->second; |
| 185 | 185 |
| 186 // If no key was found, look in the manifest. | 186 // If no key was found, look in the manifest. |
| 187 if (!app_id.empty()) { | 187 if (!app_id.empty()) { |
| 188 const Extension* extension = ExtensionRegistry::Get(browser_context_) | 188 const Extension* extension = ExtensionRegistry::Get(browser_context_) |
| 189 ->GetExtensionById(app_id, ExtensionRegistry::ENABLED); | 189 ->GetExtensionById(app_id, ExtensionRegistry::ENABLED); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 203 whispernet_client_.reset(new ChromeWhispernetClient(browser_context_)); | 203 whispernet_client_.reset(new ChromeWhispernetClient(browser_context_)); |
| 204 return whispernet_client_.get(); | 204 return whispernet_client_.get(); |
| 205 } | 205 } |
| 206 | 206 |
| 207 gcm::GCMDriver* CopresenceService::GetGCMDriver() { | 207 gcm::GCMDriver* CopresenceService::GetGCMDriver() { |
| 208 gcm::GCMProfileService* gcm_service = | 208 gcm::GCMProfileService* gcm_service = |
| 209 gcm::GCMProfileServiceFactory::GetForProfile(browser_context_); | 209 gcm::GCMProfileServiceFactory::GetForProfile(browser_context_); |
| 210 return gcm_service ? gcm_service->driver() : nullptr; | 210 return gcm_service ? gcm_service->driver() : nullptr; |
| 211 } | 211 } |
| 212 | 212 |
| 213 const std::string CopresenceService::GetDeviceId(bool authenticated) { | 213 std::string CopresenceService::GetDeviceId(bool authenticated) { |
| 214 std::string id = GetPrefService()->GetString(GetPrefName(authenticated)); | 214 std::string id = GetPrefService()->GetString(GetPrefName(authenticated)); |
| 215 DVLOG(3) << "Retrieved device ID \"" << id << "\", " | 215 DVLOG(3) << "Retrieved device ID \"" << id << "\", " |
| 216 << "authenticated = " << authenticated; | 216 << "authenticated = " << authenticated; |
| 217 return id; | 217 return id; |
| 218 } | 218 } |
| 219 | 219 |
| 220 void CopresenceService::SaveDeviceId(bool authenticated, | 220 void CopresenceService::SaveDeviceId(bool authenticated, |
| 221 const std::string& device_id) { | 221 const std::string& device_id) { |
| 222 DVLOG(3) << "Storing device ID \"" << device_id << "\", " | 222 DVLOG(3) << "Storing device ID \"" << device_id << "\", " |
| 223 << "authenticated = " << authenticated; | 223 << "authenticated = " << authenticated; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 scoped_ptr<SetAuthToken::Params> params(SetAuthToken::Params::Create(*args_)); | 294 scoped_ptr<SetAuthToken::Params> params(SetAuthToken::Params::Create(*args_)); |
| 295 EXTENSION_FUNCTION_VALIDATE(params.get()); | 295 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 296 | 296 |
| 297 // The token may be set to empty, to clear it. | 297 // The token may be set to empty, to clear it. |
| 298 CopresenceService::GetFactoryInstance()->Get(browser_context()) | 298 CopresenceService::GetFactoryInstance()->Get(browser_context()) |
| 299 ->set_auth_token(extension_id(), params->token); | 299 ->set_auth_token(extension_id(), params->token); |
| 300 return RespondNow(NoArguments()); | 300 return RespondNow(NoArguments()); |
| 301 } | 301 } |
| 302 | 302 |
| 303 } // namespace extensions | 303 } // namespace extensions |
| OLD | NEW |