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/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/copresence/chrome_whispernet_client.h" | 10 #include "chrome/browser/copresence/chrome_whispernet_client.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 // CopresenceService implementation: | 34 // CopresenceService implementation: |
35 | 35 |
36 CopresenceService::CopresenceService(content::BrowserContext* context) | 36 CopresenceService::CopresenceService(content::BrowserContext* context) |
37 : browser_context_(context) { | 37 : browser_context_(context) { |
38 } | 38 } |
39 | 39 |
40 CopresenceService::~CopresenceService() { | 40 CopresenceService::~CopresenceService() { |
41 } | 41 } |
42 | 42 |
43 copresence::CopresenceClient* CopresenceService::client() { | 43 copresence::CopresenceClient* CopresenceService::client() { |
44 if (!client_) | 44 if (!client_) { |
45 client_.reset(new copresence::CopresenceClient(this)); | 45 client_.reset(new copresence::CopresenceClient); |
| 46 client_->Initialize(this); |
| 47 } |
46 return client_.get(); | 48 return client_.get(); |
47 } | 49 } |
48 | 50 |
49 copresence::WhispernetClient* CopresenceService::whispernet_client() { | 51 copresence::WhispernetClient* CopresenceService::whispernet_client() { |
50 if (!whispernet_client_) | 52 if (!whispernet_client_) |
51 whispernet_client_.reset(new ChromeWhispernetClient(browser_context_)); | 53 whispernet_client_.reset(new ChromeWhispernetClient(browser_context_)); |
52 return whispernet_client_.get(); | 54 return whispernet_client_.get(); |
53 } | 55 } |
54 | 56 |
55 void CopresenceService::Shutdown() { | 57 void CopresenceService::Shutdown() { |
56 if (client_.get()) | 58 if (client_.get()) |
57 client_->Shutdown(); | 59 client_->Shutdown(); |
58 } | 60 } |
59 | 61 |
| 62 void CopresenceService::set_client_for_testing( |
| 63 scoped_ptr<copresence::CopresenceClient> client) { |
| 64 client_ = client.Pass(); |
| 65 } |
| 66 |
60 // static | 67 // static |
61 BrowserContextKeyedAPIFactory<CopresenceService>* | 68 BrowserContextKeyedAPIFactory<CopresenceService>* |
62 CopresenceService::GetFactoryInstance() { | 69 CopresenceService::GetFactoryInstance() { |
63 return g_factory.Pointer(); | 70 return g_factory.Pointer(); |
64 } | 71 } |
65 | 72 |
66 void CopresenceService::HandleMessages( | 73 void CopresenceService::HandleMessages( |
67 const std::string& /* app_id */, | 74 const std::string& /* app_id */, |
68 const std::string& subscription_id, | 75 const std::string& subscription_id, |
69 const std::vector<copresence::Message>& messages) { | 76 const std::vector<copresence::Message>& messages) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 | 111 |
105 net::URLRequestContextGetter* CopresenceService::GetRequestContext() const { | 112 net::URLRequestContextGetter* CopresenceService::GetRequestContext() const { |
106 return browser_context_->GetRequestContext(); | 113 return browser_context_->GetRequestContext(); |
107 } | 114 } |
108 | 115 |
109 const std::string CopresenceService::GetPlatformVersionString() const { | 116 const std::string CopresenceService::GetPlatformVersionString() const { |
110 return chrome::VersionInfo().CreateVersionString(); | 117 return chrome::VersionInfo().CreateVersionString(); |
111 } | 118 } |
112 | 119 |
113 copresence::WhispernetClient* CopresenceService::GetWhispernetClient() { | 120 copresence::WhispernetClient* CopresenceService::GetWhispernetClient() { |
114 return whispernet_client_.get(); | 121 return whispernet_client(); |
115 } | 122 } |
116 | 123 |
117 template <> | 124 template <> |
118 void | 125 void |
119 BrowserContextKeyedAPIFactory<CopresenceService>::DeclareFactoryDependencies() { | 126 BrowserContextKeyedAPIFactory<CopresenceService>::DeclareFactoryDependencies() { |
120 DependsOn(ExtensionsBrowserClient::Get()->GetExtensionSystemFactory()); | 127 DependsOn(ExtensionsBrowserClient::Get()->GetExtensionSystemFactory()); |
121 } | 128 } |
122 | 129 |
123 // CopresenceExecuteFunction implementation: | 130 // CopresenceExecuteFunction implementation: |
124 ExtensionFunction::ResponseAction CopresenceExecuteFunction::Run() { | 131 ExtensionFunction::ResponseAction CopresenceExecuteFunction::Run() { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 scoped_ptr<api::copresence::SetApiKey::Params> params( | 165 scoped_ptr<api::copresence::SetApiKey::Params> params( |
159 api::copresence::SetApiKey::Params::Create(*args_)); | 166 api::copresence::SetApiKey::Params::Create(*args_)); |
160 EXTENSION_FUNCTION_VALIDATE(params.get()); | 167 EXTENSION_FUNCTION_VALIDATE(params.get()); |
161 | 168 |
162 // TODO(rkc): Use the API key set by this function for this app. | 169 // TODO(rkc): Use the API key set by this function for this app. |
163 // http://crbug.com/400617. | 170 // http://crbug.com/400617. |
164 return RespondNow(NoArguments()); | 171 return RespondNow(NoArguments()); |
165 } | 172 } |
166 | 173 |
167 } // namespace extensions | 174 } // namespace extensions |
OLD | NEW |