Commit 0230b710 authored by Sam Goto's avatar Sam Goto Committed by Commit Bot

[sms] Create a SmsKeyedService and hang it on Profiles

Explainer:
https://github.com/sso-google/sms-otp-retrieval

Intent to Implement:
https://groups.google.com/a/chromium.org/forum/#!topic/blink-dev/Drmmb_t4eE8

Design Doc:
https://docs.google.com/document/d/1TG7BzAPdt2DWNOmephxNf09kdzDKYq8l6Z126oSif8I/edit

WICG Thread:
https://discourse.wicg.io/t/sms-otp-retrieval/3499

Bug: 670299

Change-Id: I990c32cf248200277e50ffb127d9828a62ef3a22
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1590392Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Commit-Queue: Sam Goto <goto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#659305}
parent eb65ea1f
...@@ -1579,6 +1579,10 @@ jumbo_split_static_library("browser") { ...@@ -1579,6 +1579,10 @@ jumbo_split_static_library("browser") {
"site_isolation/site_details.h", "site_isolation/site_details.h",
"site_isolation/site_isolation_policy.cc", "site_isolation/site_isolation_policy.cc",
"site_isolation/site_isolation_policy.h", "site_isolation/site_isolation_policy.h",
"sms/sms_keyed_service.cc",
"sms/sms_keyed_service.h",
"sms/sms_service_factory.cc",
"sms/sms_service_factory.h",
"speech/chrome_speech_recognition_manager_delegate.cc", "speech/chrome_speech_recognition_manager_delegate.cc",
"speech/chrome_speech_recognition_manager_delegate.h", "speech/chrome_speech_recognition_manager_delegate.h",
"speech/speech_recognizer.cc", "speech/speech_recognizer.cc",
......
...@@ -88,6 +88,8 @@ ...@@ -88,6 +88,8 @@
#include "chrome/browser/signin/identity_manager_factory.h" #include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/signin/signin_ui_util.h" #include "chrome/browser/signin/signin_ui_util.h"
#include "chrome/browser/site_isolation/site_isolation_policy.h" #include "chrome/browser/site_isolation/site_isolation_policy.h"
#include "chrome/browser/sms/sms_keyed_service.h"
#include "chrome/browser/sms/sms_service_factory.h"
#include "chrome/browser/ssl/chrome_ssl_host_state_delegate.h" #include "chrome/browser/ssl/chrome_ssl_host_state_delegate.h"
#include "chrome/browser/ssl/chrome_ssl_host_state_delegate_factory.h" #include "chrome/browser/ssl/chrome_ssl_host_state_delegate_factory.h"
#include "chrome/browser/startup_data.h" #include "chrome/browser/startup_data.h"
...@@ -1380,6 +1382,10 @@ ProfileImpl::RetriveInProgressDownloadManager() { ...@@ -1380,6 +1382,10 @@ ProfileImpl::RetriveInProgressDownloadManager() {
return DownloadManagerUtils::RetrieveInProgressDownloadManager(this); return DownloadManagerUtils::RetrieveInProgressDownloadManager(this);
} }
content::SmsService* ProfileImpl::GetSmsService() {
return SmsServiceFactory::GetForProfile(this)->Get();
}
bool ProfileImpl::IsSameProfile(Profile* profile) { bool ProfileImpl::IsSameProfile(Profile* profile) {
if (profile == static_cast<Profile*>(this)) if (profile == static_cast<Profile*>(this))
return true; return true;
......
...@@ -61,6 +61,10 @@ namespace user_prefs { ...@@ -61,6 +61,10 @@ namespace user_prefs {
class PrefRegistrySyncable; class PrefRegistrySyncable;
} }
namespace content {
class SmsService;
}
// The default profile implementation. // The default profile implementation.
class ProfileImpl : public Profile { class ProfileImpl : public Profile {
public: public:
...@@ -116,6 +120,7 @@ class ProfileImpl : public Profile { ...@@ -116,6 +120,7 @@ class ProfileImpl : public Profile {
std::string GetMediaDeviceIDSalt() override; std::string GetMediaDeviceIDSalt() override;
download::InProgressDownloadManager* RetriveInProgressDownloadManager() download::InProgressDownloadManager* RetriveInProgressDownloadManager()
override; override;
content::SmsService* GetSmsService() override;
// Profile implementation: // Profile implementation:
scoped_refptr<base::SequencedTaskRunner> GetIOTaskRunner() override; scoped_refptr<base::SequencedTaskRunner> GetIOTaskRunner() override;
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/sms/sms_keyed_service.h"
#include "content/public/browser/sms_service.h"
SmsKeyedService::SmsKeyedService()
: KeyedService(), service_(content::SmsService::Create()) {}
SmsKeyedService::~SmsKeyedService() = default;
content::SmsService* SmsKeyedService::Get() {
return service_.get();
}
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_SMS_SMS_KEYED_SERVICE_H_
#define CHROME_BROWSER_SMS_SMS_KEYED_SERVICE_H_
#include <memory>
#include "base/macros.h"
#include "components/keyed_service/core/keyed_service.h"
namespace content {
class SmsService;
}
// A per-profile service that manages per-origin requests and incoming SMS
// messages.
class SmsKeyedService : public KeyedService {
public:
SmsKeyedService();
~SmsKeyedService() override;
content::SmsService* Get();
private:
std::unique_ptr<content::SmsService> service_;
DISALLOW_COPY_AND_ASSIGN(SmsKeyedService);
};
#endif // CHROME_BROWSER_SMS_SMS_KEYED_SERVICE_H_
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/sms/sms_service_factory.h"
#include "base/no_destructor.h"
#include "chrome/browser/profiles/incognito_helpers.h"
#include "chrome/browser/sms/sms_keyed_service.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
// static
SmsKeyedService* SmsServiceFactory::GetForProfile(
content::BrowserContext* profile) {
return static_cast<SmsKeyedService*>(
GetInstance()->GetServiceForBrowserContext(profile, true));
}
// static
SmsServiceFactory* SmsServiceFactory::GetInstance() {
static base::NoDestructor<SmsServiceFactory> instance;
return instance.get();
}
SmsServiceFactory::SmsServiceFactory()
: BrowserContextKeyedServiceFactory(
"SmsService",
BrowserContextDependencyManager::GetInstance()) {}
SmsServiceFactory::~SmsServiceFactory() = default;
content::BrowserContext* SmsServiceFactory::GetBrowserContextToUse(
content::BrowserContext* context) const {
return chrome::GetBrowserContextRedirectedInIncognito(context);
}
KeyedService* SmsServiceFactory::BuildServiceInstanceFor(
content::BrowserContext* profile) const {
return new SmsKeyedService();
}
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_SMS_SMS_SERVICE_FACTORY_H_
#define CHROME_BROWSER_SMS_SMS_SERVICE_FACTORY_H_
#include "base/macros.h"
#include "base/no_destructor.h"
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
class SmsKeyedService;
// Factory to get or create an instance of SmsService from
// a Profile.
class SmsServiceFactory : public BrowserContextKeyedServiceFactory {
public:
static SmsKeyedService* GetForProfile(content::BrowserContext* profile);
static SmsServiceFactory* GetInstance();
private:
friend class base::NoDestructor<SmsServiceFactory>;
SmsServiceFactory();
~SmsServiceFactory() override;
// BrowserContextKeyedServiceFactory:
content::BrowserContext* GetBrowserContextToUse(
content::BrowserContext* context) const override;
KeyedService* BuildServiceInstanceFor(
content::BrowserContext* profile) const override;
DISALLOW_COPY_AND_ASSIGN(SmsServiceFactory);
};
#endif // CHROME_BROWSER_SMS_SMS_SERVICE_FACTORY_H_
...@@ -1785,10 +1785,10 @@ jumbo_source_set("browser") { ...@@ -1785,10 +1785,10 @@ jumbo_source_set("browser") {
"service_worker/service_worker_version.h", "service_worker/service_worker_version.h",
"site_instance_impl.cc", "site_instance_impl.cc",
"site_instance_impl.h", "site_instance_impl.h",
"sms/sms_manager.cc",
"sms/sms_manager.h",
"sms/sms_provider.cc", "sms/sms_provider.cc",
"sms/sms_provider.h", "sms/sms_provider.h",
"sms/sms_service_impl.cc",
"sms/sms_service_impl.h",
"speech/speech_recognition_dispatcher_host.cc", "speech/speech_recognition_dispatcher_host.cc",
"speech/speech_recognition_dispatcher_host.h", "speech/speech_recognition_dispatcher_host.h",
"speech/speech_recognition_manager_impl.cc", "speech/speech_recognition_manager_impl.cc",
......
...@@ -822,4 +822,8 @@ BrowserContext::GetSharedCorsOriginAccessList() const { ...@@ -822,4 +822,8 @@ BrowserContext::GetSharedCorsOriginAccessList() const {
return empty_list->get(); return empty_list->get();
} }
SmsService* BrowserContext::GetSmsService() {
return nullptr;
}
} // namespace content } // namespace content
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "content/public/browser/content_browser_client.h" #include "content/public/browser/content_browser_client.h"
#include "content/public/browser/render_frame_host.h" #include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h" #include "content/public/browser/render_process_host.h"
#include "content/public/browser/sms_service.h"
#include "content/public/common/content_features.h" #include "content/public/common/content_features.h"
#include "content/public/common/content_switches.h" #include "content/public/common/content_switches.h"
#include "media/mojo/interfaces/video_decode_perf_history.mojom.h" #include "media/mojo/interfaces/video_decode_perf_history.mojom.h"
...@@ -44,6 +45,7 @@ ...@@ -44,6 +45,7 @@
#include "third_party/blink/public/mojom/cookie_store/cookie_store.mojom.h" #include "third_party/blink/public/mojom/cookie_store/cookie_store.mojom.h"
#include "third_party/blink/public/mojom/native_file_system/native_file_system_manager.mojom.h" #include "third_party/blink/public/mojom/native_file_system/native_file_system_manager.mojom.h"
#include "third_party/blink/public/mojom/notifications/notification_service.mojom.h" #include "third_party/blink/public/mojom/notifications/notification_service.mojom.h"
#include "third_party/blink/public/mojom/sms/sms_manager.mojom.h"
#include "url/origin.h" #include "url/origin.h"
namespace content { namespace content {
...@@ -214,9 +216,10 @@ void RendererInterfaceBinders::InitializeParameterizedBinderRegistry() { ...@@ -214,9 +216,10 @@ void RendererInterfaceBinders::InitializeParameterizedBinderRegistry() {
parameterized_binder_registry_.AddInterface(base::BindRepeating( parameterized_binder_registry_.AddInterface(base::BindRepeating(
[](blink::mojom::SmsManagerRequest request, RenderProcessHost* host, [](blink::mojom::SmsManagerRequest request, RenderProcessHost* host,
const url::Origin& origin) { const url::Origin& origin) {
static_cast<StoragePartitionImpl*>(host->GetStoragePartition()) SmsService* sms_service = host->GetBrowserContext()->GetSmsService();
->GetSmsManager() if (sms_service) {
->CreateService(std::move(request), origin); sms_service->CreateService(std::move(request), origin);
}
})); }));
} }
parameterized_binder_registry_.AddInterface( parameterized_binder_registry_.AddInterface(
......
jsbell@chromium.org jsbell@chromium.org
reillyg@chromium.org reillyg@chromium.org
# COMPONENT: Blink>SMS # COMPONENT: Blink>SMS
# TEAM: fugu-dev@chromium.org
\ No newline at end of file
...@@ -3,8 +3,9 @@ ...@@ -3,8 +3,9 @@
// found in the LICENSE file. // found in the LICENSE file.
#include "base/time/time.h" #include "base/time/time.h"
#include "content/browser/renderer_host/render_process_host_impl.h" #include "content/browser/sms/sms_provider.h"
#include "content/browser/storage_partition_impl.h" #include "content/browser/sms/sms_service_impl.h"
#include "content/public/browser/browser_context.h"
#include "content/public/common/content_switches.h" #include "content/public/common/content_switches.h"
#include "content/public/test/browser_test_utils.h" #include "content/public/test/browser_test_utils.h"
#include "content/public/test/content_browser_test.h" #include "content/public/test/content_browser_test.h"
...@@ -54,11 +55,8 @@ IN_PROC_BROWSER_TEST_F(SmsTest, Start) { ...@@ -54,11 +55,8 @@ IN_PROC_BROWSER_TEST_F(SmsTest, Start) {
NavigateToURL(shell(), GetTestUrl(nullptr, "simple_page.html")); NavigateToURL(shell(), GetTestUrl(nullptr, "simple_page.html"));
auto mock_sms_provider = std::make_unique<NiceMock<MockSmsProvider>>(); auto mock_sms_provider = std::make_unique<NiceMock<MockSmsProvider>>();
auto* rph = static_cast<RenderProcessHostImpl*>( auto* sms_service = static_cast<SmsServiceImpl*>(
shell()->web_contents()->GetMainFrame()->GetProcess()); shell()->web_contents()->GetBrowserContext()->GetSmsService());
SmsManager* sms_mgr =
static_cast<StoragePartitionImpl*>(rph->GetStoragePartition())
->GetSmsManager();
// Test that SMS content can be retrieved after SmsManager.start(). // Test that SMS content can be retrieved after SmsManager.start().
std::string script = R"( std::string script = R"(
...@@ -80,7 +78,7 @@ IN_PROC_BROWSER_TEST_F(SmsTest, Start) { ...@@ -80,7 +78,7 @@ IN_PROC_BROWSER_TEST_F(SmsTest, Start) {
base::OnceCallback<void(bool, base::Optional<std::string>)>* base::OnceCallback<void(bool, base::Optional<std::string>)>*
callback) { std::move(*callback).Run(true, "hello"); })); callback) { std::move(*callback).Run(true, "hello"); }));
sms_mgr->SetSmsProviderForTest(std::move(mock_sms_provider)); sms_service->SetSmsProviderForTest(std::move(mock_sms_provider));
EXPECT_EQ("hello", EvalJs(shell(), script)); EXPECT_EQ("hello", EvalJs(shell(), script));
} }
......
...@@ -5,12 +5,13 @@ ...@@ -5,12 +5,13 @@
#ifndef CONTENT_BROWSER_SMS_SMS_PROVIDER_ANDROID_H_ #ifndef CONTENT_BROWSER_SMS_SMS_PROVIDER_ANDROID_H_
#define CONTENT_BROWSER_SMS_SMS_PROVIDER_ANDROID_H_ #define CONTENT_BROWSER_SMS_SMS_PROVIDER_ANDROID_H_
#include "sms_provider.h" #include <utility>
#include "base/android/jni_string.h" #include "base/android/jni_string.h"
#include "base/android/scoped_java_ref.h" #include "base/android/scoped_java_ref.h"
#include "base/callback.h" #include "base/callback.h"
#include "base/macros.h" #include "base/macros.h"
#include "content/browser/sms/sms_provider.h"
namespace content { namespace content {
......
...@@ -2,10 +2,9 @@ ...@@ -2,10 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include <utility> #include "content/browser/sms/sms_provider_desktop.h"
#include "base/callback.h" #include "base/callback.h"
#include "content/browser/sms/sms_provider_desktop.h"
namespace content { namespace content {
......
...@@ -4,29 +4,32 @@ ...@@ -4,29 +4,32 @@
#include <utility> #include <utility>
#include "content/browser/sms/sms_manager.h" #include "content/browser/sms/sms_service_impl.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/callback_helpers.h" #include "base/callback_helpers.h"
#include "content/public/browser/permission_controller.h"
#include "content/public/browser/permission_type.h"
namespace content { namespace content {
SmsManager::SmsManager() : sms_provider_(SmsProvider::Create()) {} // static
std::unique_ptr<SmsService> SmsService::Create() {
return std::make_unique<SmsServiceImpl>();
}
SmsServiceImpl::SmsServiceImpl() {}
SmsManager::~SmsManager() { SmsServiceImpl::~SmsServiceImpl() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
} }
void SmsManager::CreateService(blink::mojom::SmsManagerRequest request, void SmsServiceImpl::CreateService(blink::mojom::SmsManagerRequest request,
const url::Origin& origin) { const url::Origin& origin) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
bindings_.AddBinding(this, std::move(request)); bindings_.AddBinding(this, std::move(request));
} }
void SmsManager::GetNextMessage(base::TimeDelta timeout, void SmsServiceImpl::GetNextMessage(base::TimeDelta timeout,
GetNextMessageCallback callback) { GetNextMessageCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (timeout <= base::TimeDelta::FromSeconds(0)) { if (timeout <= base::TimeDelta::FromSeconds(0)) {
...@@ -34,6 +37,9 @@ void SmsManager::GetNextMessage(base::TimeDelta timeout, ...@@ -34,6 +37,9 @@ void SmsManager::GetNextMessage(base::TimeDelta timeout,
return; return;
} }
if (!sms_provider_)
sms_provider_ = SmsProvider::Create();
sms_provider_->Retrieve( sms_provider_->Retrieve(
timeout, base::BindOnce( timeout, base::BindOnce(
[](GetNextMessageCallback callback, bool success, [](GetNextMessageCallback callback, bool success,
...@@ -49,7 +55,7 @@ void SmsManager::GetNextMessage(base::TimeDelta timeout, ...@@ -49,7 +55,7 @@ void SmsManager::GetNextMessage(base::TimeDelta timeout,
std::move(callback))); std::move(callback)));
} }
void SmsManager::SetSmsProviderForTest( void SmsServiceImpl::SetSmsProviderForTest(
std::unique_ptr<SmsProvider> sms_provider) { std::unique_ptr<SmsProvider> sms_provider) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
sms_provider_ = std::move(sms_provider); sms_provider_ = std::move(sms_provider);
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CONTENT_BROWSER_SMS_SMS_MANAGER_H_ #ifndef CONTENT_BROWSER_SMS_SMS_SERVICE_IMPL_H_
#define CONTENT_BROWSER_SMS_SMS_MANAGER_H_ #define CONTENT_BROWSER_SMS_SMS_SERVICE_IMPL_H_
#include <memory> #include <memory>
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "base/time/time.h" #include "base/time/time.h"
#include "content/browser/sms/sms_provider.h" #include "content/browser/sms/sms_provider.h"
#include "content/common/content_export.h" #include "content/common/content_export.h"
#include "content/public/browser/sms_service.h"
#include "mojo/public/cpp/bindings/binding_set.h" #include "mojo/public/cpp/bindings/binding_set.h"
#include "third_party/blink/public/mojom/sms/sms_manager.mojom.h" #include "third_party/blink/public/mojom/sms/sms_manager.mojom.h"
...@@ -23,16 +24,18 @@ class Origin; ...@@ -23,16 +24,18 @@ class Origin;
namespace content { namespace content {
// The SmsManager is responsible for taking the incoming mojo calls from the // The SmsServiceImpl is responsible for taking the incoming mojo calls from the
// renderer process and dispatching them to the SmsProvider platform-specific // renderer process and dispatching them to the SmsProvider platform-specific
// implementation. // implementation.
class CONTENT_EXPORT SmsManager : public blink::mojom::SmsManager { class CONTENT_EXPORT SmsServiceImpl : public blink::mojom::SmsManager,
public content::SmsService {
public: public:
SmsManager(); SmsServiceImpl();
~SmsManager() override; ~SmsServiceImpl() override;
// content::SmsService
void CreateService(blink::mojom::SmsManagerRequest request, void CreateService(blink::mojom::SmsManagerRequest request,
const url::Origin& origin); const url::Origin& origin) override;
// blink.mojom.SmsManager: // blink.mojom.SmsManager:
void GetNextMessage(base::TimeDelta timeout, void GetNextMessage(base::TimeDelta timeout,
...@@ -48,9 +51,9 @@ class CONTENT_EXPORT SmsManager : public blink::mojom::SmsManager { ...@@ -48,9 +51,9 @@ class CONTENT_EXPORT SmsManager : public blink::mojom::SmsManager {
mojo::BindingSet<blink::mojom::SmsManager> bindings_; mojo::BindingSet<blink::mojom::SmsManager> bindings_;
SEQUENCE_CHECKER(sequence_checker_); SEQUENCE_CHECKER(sequence_checker_);
DISALLOW_COPY_AND_ASSIGN(SmsManager); DISALLOW_COPY_AND_ASSIGN(SmsServiceImpl);
}; };
} // namespace content } // namespace content
#endif // CONTENT_BROWSER_SMS_SMS_MANAGER_H_ #endif // CONTENT_BROWSER_SMS_SMS_SERVICE_IMPL_H_
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "content/browser/sms/sms_manager.h" #include "content/browser/sms/sms_service_impl.h"
#include <utility> #include <utility>
...@@ -14,8 +14,8 @@ ...@@ -14,8 +14,8 @@
#include "content/public/common/service_manager_connection.h" #include "content/public/common/service_manager_connection.h"
#include "content/public/test/navigation_simulator.h" #include "content/public/test/navigation_simulator.h"
#include "content/public/test/test_browser_context.h" #include "content/public/test/test_browser_context.h"
#include "content/public/test/test_renderer_host.h"
#include "content/public/test/test_service_manager_context.h" #include "content/public/test/test_service_manager_context.h"
#include "content/test/test_render_frame_host.h"
#include "mojo/public/cpp/bindings/binding_set.h" #include "mojo/public/cpp/bindings/binding_set.h"
#include "mojo/public/cpp/test_support/test_utils.h" #include "mojo/public/cpp/test_support/test_utils.h"
#include "services/service_manager/public/cpp/bind_source_info.h" #include "services/service_manager/public/cpp/bind_source_info.h"
...@@ -49,20 +49,20 @@ class MockSmsProvider : public SmsProvider { ...@@ -49,20 +49,20 @@ class MockSmsProvider : public SmsProvider {
DISALLOW_COPY_AND_ASSIGN(MockSmsProvider); DISALLOW_COPY_AND_ASSIGN(MockSmsProvider);
}; };
class SmsManagerTest : public RenderViewHostImplTestHarness { class SmsServiceImplTest : public RenderViewHostTestHarness {
protected: protected:
SmsManagerTest() {} SmsServiceImplTest() {}
~SmsManagerTest() override {} ~SmsServiceImplTest() override {}
private: private:
DISALLOW_COPY_AND_ASSIGN(SmsManagerTest); DISALLOW_COPY_AND_ASSIGN(SmsServiceImplTest);
}; };
} // namespace } // namespace
TEST_F(SmsManagerTest, AddMonitor) { TEST_F(SmsServiceImplTest, AddMonitor) {
auto impl = std::make_unique<SmsManager>(); auto impl = std::make_unique<SmsServiceImpl>();
auto mock = std::make_unique<NiceMock<MockSmsProvider>>(); auto mock = std::make_unique<NiceMock<MockSmsProvider>>();
blink::mojom::SmsManagerPtr service_ptr; blink::mojom::SmsManagerPtr service_ptr;
GURL url("http://google.com"); GURL url("http://google.com");
...@@ -96,8 +96,8 @@ TEST_F(SmsManagerTest, AddMonitor) { ...@@ -96,8 +96,8 @@ TEST_F(SmsManagerTest, AddMonitor) {
loop.Run(); loop.Run();
} }
TEST_F(SmsManagerTest, InvalidArguments) { TEST_F(SmsServiceImplTest, InvalidArguments) {
auto impl = std::make_unique<SmsManager>(); auto impl = std::make_unique<SmsServiceImpl>();
auto mock = std::make_unique<NiceMock<MockSmsProvider>>(); auto mock = std::make_unique<NiceMock<MockSmsProvider>>();
impl->SetSmsProviderForTest(std::move(mock)); impl->SetSmsProviderForTest(std::move(mock));
blink::mojom::SmsManagerPtr service_ptr; blink::mojom::SmsManagerPtr service_ptr;
......
...@@ -669,8 +669,6 @@ std::unique_ptr<StoragePartitionImpl> StoragePartitionImpl::Create( ...@@ -669,8 +669,6 @@ std::unique_ptr<StoragePartitionImpl> StoragePartitionImpl::Create(
partition->service_worker_context_ = new ServiceWorkerContextWrapper(context); partition->service_worker_context_ = new ServiceWorkerContextWrapper(context);
partition->service_worker_context_->set_storage_partition(partition.get()); partition->service_worker_context_->set_storage_partition(partition.get());
partition->sms_manager_ = std::make_unique<SmsManager>();
partition->appcache_service_ = partition->appcache_service_ =
base::MakeRefCounted<ChromeAppCacheService>(quota_manager_proxy.get()); base::MakeRefCounted<ChromeAppCacheService>(quota_manager_proxy.get());
...@@ -865,10 +863,6 @@ ServiceWorkerContextWrapper* StoragePartitionImpl::GetServiceWorkerContext() { ...@@ -865,10 +863,6 @@ ServiceWorkerContextWrapper* StoragePartitionImpl::GetServiceWorkerContext() {
return service_worker_context_.get(); return service_worker_context_.get();
} }
SmsManager* StoragePartitionImpl::GetSmsManager() {
return sms_manager_.get();
}
SharedWorkerServiceImpl* StoragePartitionImpl::GetSharedWorkerService() { SharedWorkerServiceImpl* StoragePartitionImpl::GetSharedWorkerService() {
return shared_worker_service_.get(); return shared_worker_service_.get();
} }
......
...@@ -30,7 +30,6 @@ ...@@ -30,7 +30,6 @@
#include "content/browser/payments/payment_app_context_impl.h" #include "content/browser/payments/payment_app_context_impl.h"
#include "content/browser/push_messaging/push_messaging_context.h" #include "content/browser/push_messaging/push_messaging_context.h"
#include "content/browser/service_worker/service_worker_context_wrapper.h" #include "content/browser/service_worker/service_worker_context_wrapper.h"
#include "content/browser/sms/sms_manager.h"
#include "content/browser/url_loader_factory_getter.h" #include "content/browser/url_loader_factory_getter.h"
#include "content/browser/worker_host/shared_worker_service_impl.h" #include "content/browser/worker_host/shared_worker_service_impl.h"
#include "content/common/content_export.h" #include "content/common/content_export.h"
...@@ -106,7 +105,6 @@ class CONTENT_EXPORT StoragePartitionImpl ...@@ -106,7 +105,6 @@ class CONTENT_EXPORT StoragePartitionImpl
IndexedDBContextImpl* GetIndexedDBContext() override; IndexedDBContextImpl* GetIndexedDBContext() override;
CacheStorageContextImpl* GetCacheStorageContext() override; CacheStorageContextImpl* GetCacheStorageContext() override;
ServiceWorkerContextWrapper* GetServiceWorkerContext() override; ServiceWorkerContextWrapper* GetServiceWorkerContext() override;
SmsManager* GetSmsManager();
SharedWorkerServiceImpl* GetSharedWorkerService() override; SharedWorkerServiceImpl* GetSharedWorkerService() override;
GeneratedCodeCacheContext* GetGeneratedCodeCacheContext() override; GeneratedCodeCacheContext* GetGeneratedCodeCacheContext() override;
DevToolsBackgroundServicesContextImpl* GetDevToolsBackgroundServicesContext() DevToolsBackgroundServicesContextImpl* GetDevToolsBackgroundServicesContext()
...@@ -328,7 +326,6 @@ class CONTENT_EXPORT StoragePartitionImpl ...@@ -328,7 +326,6 @@ class CONTENT_EXPORT StoragePartitionImpl
scoped_refptr<IndexedDBContextImpl> indexed_db_context_; scoped_refptr<IndexedDBContextImpl> indexed_db_context_;
scoped_refptr<CacheStorageContextImpl> cache_storage_context_; scoped_refptr<CacheStorageContextImpl> cache_storage_context_;
scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_; scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_;
std::unique_ptr<SmsManager> sms_manager_;
std::unique_ptr<SharedWorkerServiceImpl> shared_worker_service_; std::unique_ptr<SharedWorkerServiceImpl> shared_worker_service_;
scoped_refptr<PushMessagingContext> push_messaging_context_; scoped_refptr<PushMessagingContext> push_messaging_context_;
scoped_refptr<storage::SpecialStoragePolicy> special_storage_policy_; scoped_refptr<storage::SpecialStoragePolicy> special_storage_policy_;
......
...@@ -284,6 +284,7 @@ jumbo_source_set("browser_sources") { ...@@ -284,6 +284,7 @@ jumbo_source_set("browser_sources") {
"site_instance.h", "site_instance.h",
"site_isolation_policy.cc", "site_isolation_policy.cc",
"site_isolation_policy.h", "site_isolation_policy.h",
"sms_service.h",
"speech_recognition_event_listener.h", "speech_recognition_event_listener.h",
"speech_recognition_manager.h", "speech_recognition_manager.h",
"speech_recognition_manager_delegate.h", "speech_recognition_manager_delegate.h",
......
...@@ -86,6 +86,7 @@ class PermissionControllerDelegate; ...@@ -86,6 +86,7 @@ class PermissionControllerDelegate;
class PushMessagingService; class PushMessagingService;
class ResourceContext; class ResourceContext;
class ServiceManagerConnection; class ServiceManagerConnection;
class SmsService;
class SharedCorsOriginAccessList; class SharedCorsOriginAccessList;
class SiteInstance; class SiteInstance;
class StoragePartition; class StoragePartition;
...@@ -366,6 +367,10 @@ class CONTENT_EXPORT BrowserContext : public base::SupportsUserData { ...@@ -366,6 +367,10 @@ class CONTENT_EXPORT BrowserContext : public base::SupportsUserData {
virtual download::InProgressDownloadManager* virtual download::InProgressDownloadManager*
RetriveInProgressDownloadManager(); RetriveInProgressDownloadManager();
// Returns the SmsService associated with this context if any,
// nullptr otherwise.
virtual SmsService* GetSmsService();
private: private:
const std::string unique_id_; const std::string unique_id_;
bool was_notify_will_be_destroyed_called_ = false; bool was_notify_will_be_destroyed_called_ = false;
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_PUBLIC_BROWSER_SMS_SERVICE_H_
#define CONTENT_PUBLIC_BROWSER_SMS_SERVICE_H_
#include "content/common/content_export.h"
#include "third_party/blink/public/mojom/sms/sms_manager.mojom.h"
namespace url {
class Origin;
}
namespace content {
// The interface to be implemented by the browser to mediate between SMS
// Receiver calls and the underlying operating system.
// https://github.com/samuelgoto/sms-receiver
class CONTENT_EXPORT SmsService {
public:
virtual ~SmsService() {}
static std::unique_ptr<SmsService> Create();
virtual void CreateService(blink::mojom::SmsManagerRequest request,
const url::Origin& origin) = 0;
};
} // namespace content
#endif // CONTENT_PUBLIC_BROWSER_SMS_SERVICE_H_
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "components/network_session_configurator/common/network_switches.h" #include "components/network_session_configurator/common/network_switches.h"
#include "content/public/browser/browser_task_traits.h" #include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/sms_service.h"
#include "content/public/browser/storage_partition.h" #include "content/public/browser/storage_partition.h"
#include "content/public/common/content_switches.h" #include "content/public/common/content_switches.h"
#include "content/shell/browser/shell_download_manager_delegate.h" #include "content/shell/browser/shell_download_manager_delegate.h"
...@@ -265,4 +266,10 @@ ShellBrowserContext::GetBrowsingDataRemoverDelegate() { ...@@ -265,4 +266,10 @@ ShellBrowserContext::GetBrowsingDataRemoverDelegate() {
return nullptr; return nullptr;
} }
SmsService* ShellBrowserContext::GetSmsService() {
if (!sms_service_)
sms_service_ = content::SmsService::Create();
return sms_service_.get();
}
} // namespace content } // namespace content
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "content/public/browser/browser_context.h" #include "content/public/browser/browser_context.h"
#include "content/public/browser/content_browser_client.h" #include "content/public/browser/content_browser_client.h"
#include "content/public/browser/resource_context.h" #include "content/public/browser/resource_context.h"
#include "content/public/browser/sms_service.h"
#include "content/shell/browser/shell_url_request_context_getter.h" #include "content/shell/browser/shell_url_request_context_getter.h"
#include "net/url_request/url_request_job_factory.h" #include "net/url_request/url_request_job_factory.h"
...@@ -77,6 +78,7 @@ class ShellBrowserContext : public BrowserContext { ...@@ -77,6 +78,7 @@ class ShellBrowserContext : public BrowserContext {
net::URLRequestContextGetter* CreateMediaRequestContextForStoragePartition( net::URLRequestContextGetter* CreateMediaRequestContextForStoragePartition(
const base::FilePath& partition_path, const base::FilePath& partition_path,
bool in_memory) override; bool in_memory) override;
SmsService* GetSmsService() override;
protected: protected:
// Contains URLRequestContextGetter required for resource loading. // Contains URLRequestContextGetter required for resource loading.
...@@ -125,6 +127,7 @@ class ShellBrowserContext : public BrowserContext { ...@@ -125,6 +127,7 @@ class ShellBrowserContext : public BrowserContext {
std::map<base::FilePath, scoped_refptr<ShellURLRequestContextGetter>> std::map<base::FilePath, scoped_refptr<ShellURLRequestContextGetter>>
isolated_url_request_getters_; isolated_url_request_getters_;
std::unique_ptr<SimpleFactoryKey> key_; std::unique_ptr<SimpleFactoryKey> key_;
std::unique_ptr<content::SmsService> sms_service_;
DISALLOW_COPY_AND_ASSIGN(ShellBrowserContext); DISALLOW_COPY_AND_ASSIGN(ShellBrowserContext);
}; };
......
...@@ -1706,7 +1706,7 @@ test("content_unittests") { ...@@ -1706,7 +1706,7 @@ test("content_unittests") {
"../browser/service_worker/service_worker_version_unittest.cc", "../browser/service_worker/service_worker_version_unittest.cc",
"../browser/shareable_file_reference_unittest.cc", "../browser/shareable_file_reference_unittest.cc",
"../browser/site_instance_impl_unittest.cc", "../browser/site_instance_impl_unittest.cc",
"../browser/sms/sms_manager_unittest.cc", "../browser/sms/sms_service_impl_unittest.cc",
"../browser/speech/tts_controller_unittest.cc", "../browser/speech/tts_controller_unittest.cc",
"../browser/startup_task_runner_unittest.cc", "../browser/startup_task_runner_unittest.cc",
"../browser/storage_partition_impl_map_unittest.cc", "../browser/storage_partition_impl_map_unittest.cc",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment