| 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 audio_modem::WhispernetClient* CopresenceService::whispernet_client() { | |
| 75 if (!whispernet_client_ && !is_shutting_down_) | |
| 76 whispernet_client_.reset(new ChromeWhispernetClient(browser_context_)); | |
| 77 return whispernet_client_.get(); | |
| 78 } | |
| 79 | |
| 80 const std::string CopresenceService::auth_token(const std::string& app_id) | 74 const std::string CopresenceService::auth_token(const std::string& app_id) |
| 81 const { | 75 const { |
| 82 // This won't be const if we use map[] | 76 // This won't be const if we use map[] |
| 83 const auto& key = auth_tokens_by_app_.find(app_id); | 77 const auto& key = auth_tokens_by_app_.find(app_id); |
| 84 return key == auth_tokens_by_app_.end() ? std::string() : key->second; | 78 return key == auth_tokens_by_app_.end() ? std::string() : key->second; |
| 85 } | 79 } |
| 86 | 80 |
| 87 void CopresenceService::set_api_key(const std::string& app_id, | 81 void CopresenceService::set_api_key(const std::string& app_id, |
| 88 const std::string& api_key) { | 82 const std::string& api_key) { |
| 89 DCHECK(!app_id.empty()); | 83 DCHECK(!app_id.empty()); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 static_cast<CopresenceManifestData*>( | 192 static_cast<CopresenceManifestData*>( |
| 199 extension->GetManifestData(manifest_keys::kCopresence)); | 193 extension->GetManifestData(manifest_keys::kCopresence)); |
| 200 if (manifest_data) | 194 if (manifest_data) |
| 201 return manifest_data->api_key; | 195 return manifest_data->api_key; |
| 202 } | 196 } |
| 203 | 197 |
| 204 return std::string(); | 198 return std::string(); |
| 205 } | 199 } |
| 206 | 200 |
| 207 audio_modem::WhispernetClient* CopresenceService::GetWhispernetClient() { | 201 audio_modem::WhispernetClient* CopresenceService::GetWhispernetClient() { |
| 208 return whispernet_client(); | 202 if (!whispernet_client_ && !is_shutting_down_) |
| 203 whispernet_client_.reset(new ChromeWhispernetClient(browser_context_)); |
| 204 return whispernet_client_.get(); |
| 209 } | 205 } |
| 210 | 206 |
| 211 gcm::GCMDriver* CopresenceService::GetGCMDriver() { | 207 gcm::GCMDriver* CopresenceService::GetGCMDriver() { |
| 212 gcm::GCMProfileService* gcm_service = | 208 gcm::GCMProfileService* gcm_service = |
| 213 gcm::GCMProfileServiceFactory::GetForProfile(browser_context_); | 209 gcm::GCMProfileServiceFactory::GetForProfile(browser_context_); |
| 214 return gcm_service ? gcm_service->driver() : nullptr; | 210 return gcm_service ? gcm_service->driver() : nullptr; |
| 215 } | 211 } |
| 216 | 212 |
| 217 const std::string CopresenceService::GetDeviceId(bool authenticated) { | 213 const std::string CopresenceService::GetDeviceId(bool authenticated) { |
| 218 std::string id = GetPrefService()->GetString(GetPrefName(authenticated)); | 214 std::string id = GetPrefService()->GetString(GetPrefName(authenticated)); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 scoped_ptr<SetAuthToken::Params> params(SetAuthToken::Params::Create(*args_)); | 294 scoped_ptr<SetAuthToken::Params> params(SetAuthToken::Params::Create(*args_)); |
| 299 EXTENSION_FUNCTION_VALIDATE(params.get()); | 295 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 300 | 296 |
| 301 // The token may be set to empty, to clear it. | 297 // The token may be set to empty, to clear it. |
| 302 CopresenceService::GetFactoryInstance()->Get(browser_context()) | 298 CopresenceService::GetFactoryInstance()->Get(browser_context()) |
| 303 ->set_auth_token(extension_id(), params->token); | 299 ->set_auth_token(extension_id(), params->token); |
| 304 return RespondNow(NoArguments()); | 300 return RespondNow(NoArguments()); |
| 305 } | 301 } |
| 306 | 302 |
| 307 } // namespace extensions | 303 } // namespace extensions |
| OLD | NEW |