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 16 matching lines...) Expand all Loading... |
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 device_fingerprint_.set_platform_version( |
| 38 chrome::VersionInfo().CreateVersionString()); |
37 } | 39 } |
38 | 40 |
39 CopresenceService::~CopresenceService() { | 41 CopresenceService::~CopresenceService() { |
40 } | 42 } |
41 | 43 |
42 copresence::CopresenceClient* CopresenceService::client() { | 44 copresence::CopresenceClient* CopresenceService::client() { |
43 if (!client_ && !is_shutting_down_) | 45 if (!client_ && !is_shutting_down_) |
44 client_.reset(new copresence::CopresenceClient(this)); | 46 client_.reset(new copresence::CopresenceClient(this)); |
45 return client_.get(); | 47 return client_.get(); |
46 } | 48 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 EventRouter::Get(browser_context_) | 100 EventRouter::Get(browser_context_) |
99 ->DispatchEventToExtension(app_id, event.Pass()); | 101 ->DispatchEventToExtension(app_id, event.Pass()); |
100 DVLOG(2) << "Passed " << api_messages.size() << " messages to app \"" | 102 DVLOG(2) << "Passed " << api_messages.size() << " messages to app \"" |
101 << app_id << "\" for subscription \"" << subscription_id << "\""; | 103 << app_id << "\" for subscription \"" << subscription_id << "\""; |
102 } | 104 } |
103 | 105 |
104 net::URLRequestContextGetter* CopresenceService::GetRequestContext() const { | 106 net::URLRequestContextGetter* CopresenceService::GetRequestContext() const { |
105 return browser_context_->GetRequestContext(); | 107 return browser_context_->GetRequestContext(); |
106 } | 108 } |
107 | 109 |
108 const std::string CopresenceService::GetPlatformVersionString() const { | 110 const copresence::DeviceFingerprint& |
109 return chrome::VersionInfo().CreateVersionString(); | 111 CopresenceService::GetDeviceFingerprint() const { |
| 112 return device_fingerprint_; |
| 113 } |
| 114 |
| 115 const std::string& GetAPIKey() const { |
| 116 return api_key_; |
110 } | 117 } |
111 | 118 |
112 copresence::WhispernetClient* CopresenceService::GetWhispernetClient() { | 119 copresence::WhispernetClient* CopresenceService::GetWhispernetClient() { |
113 return whispernet_client(); | 120 return whispernet_client(); |
114 } | 121 } |
115 | 122 |
116 template <> | 123 template <> |
117 void | 124 void |
118 BrowserContextKeyedAPIFactory<CopresenceService>::DeclareFactoryDependencies() { | 125 BrowserContextKeyedAPIFactory<CopresenceService>::DeclareFactoryDependencies() { |
119 DependsOn(ExtensionsBrowserClient::Get()->GetExtensionSystemFactory()); | 126 DependsOn(ExtensionsBrowserClient::Get()->GetExtensionSystemFactory()); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 : api::copresence::EXECUTE_STATUS_FAILED; | 163 : api::copresence::EXECUTE_STATUS_FAILED; |
157 Respond(ArgumentList(api::copresence::Execute::Results::Create(api_status))); | 164 Respond(ArgumentList(api::copresence::Execute::Results::Create(api_status))); |
158 } | 165 } |
159 | 166 |
160 // CopresenceSetApiKeyFunction implementation: | 167 // CopresenceSetApiKeyFunction implementation: |
161 ExtensionFunction::ResponseAction CopresenceSetApiKeyFunction::Run() { | 168 ExtensionFunction::ResponseAction CopresenceSetApiKeyFunction::Run() { |
162 scoped_ptr<api::copresence::SetApiKey::Params> params( | 169 scoped_ptr<api::copresence::SetApiKey::Params> params( |
163 api::copresence::SetApiKey::Params::Create(*args_)); | 170 api::copresence::SetApiKey::Params::Create(*args_)); |
164 EXTENSION_FUNCTION_VALIDATE(params.get()); | 171 EXTENSION_FUNCTION_VALIDATE(params.get()); |
165 | 172 |
166 // TODO(rkc): Use the API key set by this function for this app. | 173 // The api key may be set to empty, to clear it. |
167 // http://crbug.com/400617. | 174 api_key_ = params->apiKey; |
168 return RespondNow(NoArguments()); | 175 return RespondNow(NoArguments()); |
169 } | 176 } |
170 | 177 |
171 } // namespace extensions | 178 } // namespace extensions |
OLD | NEW |