Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(110)

Side by Side Diff: chrome/browser/extensions/api/copresence/copresence_api.cc

Issue 441103002: Tests for the Copresence API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@api
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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_ = copresence::CopresenceClient::Create(this);
46 }
46 return client_.get(); 47 return client_.get();
47 } 48 }
48 49
49 copresence::WhispernetClient* CopresenceService::whispernet_client() { 50 copresence::WhispernetClient* CopresenceService::whispernet_client() {
50 if (!whispernet_client_) 51 if (!whispernet_client_)
51 whispernet_client_.reset(new ChromeWhispernetClient(browser_context_)); 52 whispernet_client_.reset(new ChromeWhispernetClient(browser_context_));
52 return whispernet_client_.get(); 53 return whispernet_client_.get();
53 } 54 }
54 55
55 void CopresenceService::Shutdown() { 56 void CopresenceService::Shutdown() {
56 if (client_.get()) 57 if (client_.get())
57 client_->Shutdown(); 58 client_->Shutdown();
58 } 59 }
59 60
61 void CopresenceService::set_client_for_testing(
62 scoped_ptr<copresence::CopresenceClient> client) {
63 client_ = client.Pass();
64 }
65
60 // static 66 // static
61 BrowserContextKeyedAPIFactory<CopresenceService>* 67 BrowserContextKeyedAPIFactory<CopresenceService>*
62 CopresenceService::GetFactoryInstance() { 68 CopresenceService::GetFactoryInstance() {
63 return g_factory.Pointer(); 69 return g_factory.Pointer();
64 } 70 }
65 71
66 void CopresenceService::HandleMessages( 72 void CopresenceService::HandleMessages(
67 const std::string& /* app_id */, 73 const std::string& /* app_id */,
68 const std::string& subscription_id, 74 const std::string& subscription_id,
69 const std::vector<copresence::Message>& messages) { 75 const std::vector<copresence::Message>& messages) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 110
105 net::URLRequestContextGetter* CopresenceService::GetRequestContext() const { 111 net::URLRequestContextGetter* CopresenceService::GetRequestContext() const {
106 return browser_context_->GetRequestContext(); 112 return browser_context_->GetRequestContext();
107 } 113 }
108 114
109 const std::string CopresenceService::GetPlatformVersionString() const { 115 const std::string CopresenceService::GetPlatformVersionString() const {
110 return chrome::VersionInfo().CreateVersionString(); 116 return chrome::VersionInfo().CreateVersionString();
111 } 117 }
112 118
113 copresence::WhispernetClient* CopresenceService::GetWhispernetClient() { 119 copresence::WhispernetClient* CopresenceService::GetWhispernetClient() {
114 return whispernet_client_.get(); 120 return whispernet_client();
115 } 121 }
116 122
117 template <> 123 template <>
118 void 124 void
119 BrowserContextKeyedAPIFactory<CopresenceService>::DeclareFactoryDependencies() { 125 BrowserContextKeyedAPIFactory<CopresenceService>::DeclareFactoryDependencies() {
120 DependsOn(ExtensionsBrowserClient::Get()->GetExtensionSystemFactory()); 126 DependsOn(ExtensionsBrowserClient::Get()->GetExtensionSystemFactory());
121 } 127 }
122 128
123 // CopresenceExecuteFunction implementation: 129 // CopresenceExecuteFunction implementation:
124 ExtensionFunction::ResponseAction CopresenceExecuteFunction::Run() { 130 ExtensionFunction::ResponseAction CopresenceExecuteFunction::Run() {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 scoped_ptr<api::copresence::SetApiKey::Params> params( 164 scoped_ptr<api::copresence::SetApiKey::Params> params(
159 api::copresence::SetApiKey::Params::Create(*args_)); 165 api::copresence::SetApiKey::Params::Create(*args_));
160 EXTENSION_FUNCTION_VALIDATE(params.get()); 166 EXTENSION_FUNCTION_VALIDATE(params.get());
161 167
162 // TODO(rkc): Use the API key set by this function for this app. 168 // TODO(rkc): Use the API key set by this function for this app.
163 // http://crbug.com/400617. 169 // http://crbug.com/400617.
164 return RespondNow(NoArguments()); 170 return RespondNow(NoArguments());
165 } 171 }
166 172
167 } // namespace extensions 173 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698