| 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 "chrome/browser/copresence/chrome_whispernet_client.h" | 9 #include "chrome/browser/copresence/chrome_whispernet_client.h" |
| 10 #include "chrome/common/chrome_version_info.h" | 10 #include "chrome/common/chrome_version_info.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 | 26 |
| 27 const char kInvalidOperationsMessage[] = | 27 const char kInvalidOperationsMessage[] = |
| 28 "Invalid operation in operations array."; | 28 "Invalid operation in operations array."; |
| 29 const char kShuttingDownMessage[] = "Shutting down."; | 29 const char kShuttingDownMessage[] = "Shutting down."; |
| 30 | 30 |
| 31 } // namespace | 31 } // namespace |
| 32 | 32 |
| 33 // CopresenceService implementation: | 33 // CopresenceService implementation: |
| 34 | 34 |
| 35 CopresenceService::CopresenceService(content::BrowserContext* context) | 35 CopresenceService::CopresenceService(content::BrowserContext* context) |
| 36 : is_shutting_down_(false), browser_context_(context) { | 36 : is_shutting_down_(false), browser_context_(context) {} |
| 37 } | |
| 38 | 37 |
| 39 CopresenceService::~CopresenceService() { | 38 CopresenceService::~CopresenceService() {} |
| 40 } | |
| 41 | 39 |
| 42 copresence::CopresenceClient* CopresenceService::client() { | 40 copresence::CopresenceClient* CopresenceService::client() { |
| 43 if (!client_ && !is_shutting_down_) | 41 if (!client_ && !is_shutting_down_) |
| 44 client_.reset(new copresence::CopresenceClient(this)); | 42 client_.reset(new copresence::CopresenceClient(this)); |
| 45 return client_.get(); | 43 return client_.get(); |
| 46 } | 44 } |
| 47 | 45 |
| 48 copresence::WhispernetClient* CopresenceService::whispernet_client() { | 46 copresence::WhispernetClient* CopresenceService::whispernet_client() { |
| 49 if (!whispernet_client_ && !is_shutting_down_) | 47 if (!whispernet_client_ && !is_shutting_down_) |
| 50 whispernet_client_.reset(new ChromeWhispernetClient(browser_context_)); | 48 whispernet_client_.reset(new ChromeWhispernetClient(browser_context_)); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 } | 100 } |
| 103 | 101 |
| 104 net::URLRequestContextGetter* CopresenceService::GetRequestContext() const { | 102 net::URLRequestContextGetter* CopresenceService::GetRequestContext() const { |
| 105 return browser_context_->GetRequestContext(); | 103 return browser_context_->GetRequestContext(); |
| 106 } | 104 } |
| 107 | 105 |
| 108 const std::string CopresenceService::GetPlatformVersionString() const { | 106 const std::string CopresenceService::GetPlatformVersionString() const { |
| 109 return chrome::VersionInfo().CreateVersionString(); | 107 return chrome::VersionInfo().CreateVersionString(); |
| 110 } | 108 } |
| 111 | 109 |
| 110 const std::string CopresenceService::GetAPIKey() const { |
| 111 return api_key_; |
| 112 } |
| 113 |
| 112 copresence::WhispernetClient* CopresenceService::GetWhispernetClient() { | 114 copresence::WhispernetClient* CopresenceService::GetWhispernetClient() { |
| 113 return whispernet_client(); | 115 return whispernet_client(); |
| 114 } | 116 } |
| 115 | 117 |
| 116 template <> | 118 template <> |
| 117 void | 119 void |
| 118 BrowserContextKeyedAPIFactory<CopresenceService>::DeclareFactoryDependencies() { | 120 BrowserContextKeyedAPIFactory<CopresenceService>::DeclareFactoryDependencies() { |
| 119 DependsOn(ExtensionsBrowserClient::Get()->GetExtensionSystemFactory()); | 121 DependsOn(ExtensionsBrowserClient::Get()->GetExtensionSystemFactory()); |
| 120 } | 122 } |
| 121 | 123 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 : api::copresence::EXECUTE_STATUS_FAILED; | 158 : api::copresence::EXECUTE_STATUS_FAILED; |
| 157 Respond(ArgumentList(api::copresence::Execute::Results::Create(api_status))); | 159 Respond(ArgumentList(api::copresence::Execute::Results::Create(api_status))); |
| 158 } | 160 } |
| 159 | 161 |
| 160 // CopresenceSetApiKeyFunction implementation: | 162 // CopresenceSetApiKeyFunction implementation: |
| 161 ExtensionFunction::ResponseAction CopresenceSetApiKeyFunction::Run() { | 163 ExtensionFunction::ResponseAction CopresenceSetApiKeyFunction::Run() { |
| 162 scoped_ptr<api::copresence::SetApiKey::Params> params( | 164 scoped_ptr<api::copresence::SetApiKey::Params> params( |
| 163 api::copresence::SetApiKey::Params::Create(*args_)); | 165 api::copresence::SetApiKey::Params::Create(*args_)); |
| 164 EXTENSION_FUNCTION_VALIDATE(params.get()); | 166 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 165 | 167 |
| 166 // TODO(rkc): Use the API key set by this function for this app. | 168 // The api key may be set to empty, to clear it. |
| 167 // http://crbug.com/400617. | 169 CopresenceService::GetFactoryInstance()->Get(browser_context()) |
| 170 ->set_api_key(params->api_key); |
| 168 return RespondNow(NoArguments()); | 171 return RespondNow(NoArguments()); |
| 169 } | 172 } |
| 170 | 173 |
| 171 } // namespace extensions | 174 } // namespace extensions |
| OLD | NEW |