| 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 22 matching lines...) Expand all Loading... |
| 33 namespace { | 33 namespace { |
| 34 | 34 |
| 35 base::LazyInstance<BrowserContextKeyedAPIFactory<CopresenceService>> | 35 base::LazyInstance<BrowserContextKeyedAPIFactory<CopresenceService>> |
| 36 g_factory = LAZY_INSTANCE_INITIALIZER; | 36 g_factory = LAZY_INSTANCE_INITIALIZER; |
| 37 | 37 |
| 38 const char kInvalidOperationsMessage[] = | 38 const char kInvalidOperationsMessage[] = |
| 39 "Invalid operation in operations array."; | 39 "Invalid operation in operations array."; |
| 40 const char kShuttingDownMessage[] = "Shutting down."; | 40 const char kShuttingDownMessage[] = "Shutting down."; |
| 41 | 41 |
| 42 const std::string GetPrefName(bool authenticated) { | 42 const std::string GetPrefName(bool authenticated) { |
| 43 #if defined(ENABLE_EXTENSIONS) && !defined(OS_ANDROID) && !defined(OS_IOS) |
| 43 return authenticated ? prefs::kCopresenceAuthenticatedDeviceId | 44 return authenticated ? prefs::kCopresenceAuthenticatedDeviceId |
| 44 : prefs::kCopresenceAnonymousDeviceId; | 45 : prefs::kCopresenceAnonymousDeviceId; |
| 46 #else |
| 47 return "dummy"; |
| 48 #endif |
| 45 } | 49 } |
| 46 | 50 |
| 47 } // namespace | 51 } // namespace |
| 48 | 52 |
| 49 namespace Execute = api::copresence::Execute; | 53 namespace Execute = api::copresence::Execute; |
| 50 namespace OnMessagesReceived = api::copresence::OnMessagesReceived; | 54 namespace OnMessagesReceived = api::copresence::OnMessagesReceived; |
| 51 namespace OnStatusUpdated = api::copresence::OnStatusUpdated; | 55 namespace OnStatusUpdated = api::copresence::OnStatusUpdated; |
| 52 namespace SetApiKey = api::copresence::SetApiKey; | 56 namespace SetApiKey = api::copresence::SetApiKey; |
| 53 namespace SetAuthToken = api::copresence::SetAuthToken; | 57 namespace SetAuthToken = api::copresence::SetAuthToken; |
| 54 | 58 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 DCHECK(!app_id.empty()); | 93 DCHECK(!app_id.empty()); |
| 90 auth_tokens_by_app_[app_id] = token; | 94 auth_tokens_by_app_[app_id] = token; |
| 91 } | 95 } |
| 92 | 96 |
| 93 void CopresenceService::set_manager_for_testing( | 97 void CopresenceService::set_manager_for_testing( |
| 94 scoped_ptr<copresence::CopresenceManager> manager) { | 98 scoped_ptr<copresence::CopresenceManager> manager) { |
| 95 manager_ = manager.Pass(); | 99 manager_ = manager.Pass(); |
| 96 } | 100 } |
| 97 | 101 |
| 98 void CopresenceService::ResetState() { | 102 void CopresenceService::ResetState() { |
| 103 #if !defined(OS_ANDROID) |
| 99 DVLOG(2) << "Deleting copresence state"; | 104 DVLOG(2) << "Deleting copresence state"; |
| 100 GetPrefService()->ClearPref(prefs::kCopresenceAuthenticatedDeviceId); | 105 GetPrefService()->ClearPref(prefs::kCopresenceAuthenticatedDeviceId); |
| 101 GetPrefService()->ClearPref(prefs::kCopresenceAnonymousDeviceId); | 106 GetPrefService()->ClearPref(prefs::kCopresenceAnonymousDeviceId); |
| 102 manager_ = nullptr; | 107 manager_ = nullptr; |
| 108 #endif |
| 103 } | 109 } |
| 104 | 110 |
| 105 // static | 111 // static |
| 106 void CopresenceService::RegisterProfilePrefs(PrefRegistrySyncable* registry) { | 112 void CopresenceService::RegisterProfilePrefs(PrefRegistrySyncable* registry) { |
| 113 #if !defined(OS_ANDROID) |
| 107 registry->RegisterStringPref(prefs::kCopresenceAuthenticatedDeviceId, | 114 registry->RegisterStringPref(prefs::kCopresenceAuthenticatedDeviceId, |
| 108 std::string()); | 115 std::string()); |
| 109 registry->RegisterStringPref(prefs::kCopresenceAnonymousDeviceId, | 116 registry->RegisterStringPref(prefs::kCopresenceAnonymousDeviceId, |
| 110 std::string()); | 117 std::string()); |
| 118 #endif |
| 111 } | 119 } |
| 112 | 120 |
| 113 // static | 121 // static |
| 114 BrowserContextKeyedAPIFactory<CopresenceService>* | 122 BrowserContextKeyedAPIFactory<CopresenceService>* |
| 115 CopresenceService::GetFactoryInstance() { | 123 CopresenceService::GetFactoryInstance() { |
| 116 return g_factory.Pointer(); | 124 return g_factory.Pointer(); |
| 117 } | 125 } |
| 118 | 126 |
| 119 | 127 |
| 120 // Private functions. | 128 // Private functions. |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 scoped_ptr<SetAuthToken::Params> params(SetAuthToken::Params::Create(*args_)); | 302 scoped_ptr<SetAuthToken::Params> params(SetAuthToken::Params::Create(*args_)); |
| 295 EXTENSION_FUNCTION_VALIDATE(params.get()); | 303 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 296 | 304 |
| 297 // The token may be set to empty, to clear it. | 305 // The token may be set to empty, to clear it. |
| 298 CopresenceService::GetFactoryInstance()->Get(browser_context()) | 306 CopresenceService::GetFactoryInstance()->Get(browser_context()) |
| 299 ->set_auth_token(extension_id(), params->token); | 307 ->set_auth_token(extension_id(), params->token); |
| 300 return RespondNow(NoArguments()); | 308 return RespondNow(NoArguments()); |
| 301 } | 309 } |
| 302 | 310 |
| 303 } // namespace extensions | 311 } // namespace extensions |
| OLD | NEW |