Commit d28e4bc5 authored by evliu's avatar evliu Committed by Commit Bot

Add incognito support to the speech recognition service factory

This CL adds incognito support to the speech recognition service factory.

Bug: 1093978
Change-Id: I71fbc99fcf3ad01448165a09ddd6b77133995570
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2241944Reviewed-by: default avatarMounir Lamouri <mlamouri@chromium.org>
Commit-Queue: Evan Liu <evliu@google.com>
Cr-Commit-Position: refs/heads/master@{#778023}
parent 3f5b1271
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "chrome/browser/speech/speech_recognition_service_factory.h" #include "chrome/browser/speech/speech_recognition_service_factory.h"
#include "base/no_destructor.h" #include "base/no_destructor.h"
#include "chrome/browser/profiles/incognito_helpers.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/speech/speech_recognition_service.h" #include "chrome/browser/speech/speech_recognition_service.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h" #include "components/keyed_service/content/browser_context_dependency_manager.h"
...@@ -34,3 +35,10 @@ KeyedService* SpeechRecognitionServiceFactory::BuildServiceInstanceFor( ...@@ -34,3 +35,10 @@ KeyedService* SpeechRecognitionServiceFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const { content::BrowserContext* context) const {
return new speech::SpeechRecognitionService(context); return new speech::SpeechRecognitionService(context);
} }
// Incognito profiles should use their own instance of the browser context.
content::BrowserContext*
SpeechRecognitionServiceFactory::GetBrowserContextToUse(
content::BrowserContext* context) const {
return chrome::GetBrowserContextOwnInstanceInIncognito(context);
}
...@@ -35,6 +35,8 @@ class SpeechRecognitionServiceFactory ...@@ -35,6 +35,8 @@ class SpeechRecognitionServiceFactory
// BrowserContextKeyedServiceFactory: // BrowserContextKeyedServiceFactory:
KeyedService* BuildServiceInstanceFor( KeyedService* BuildServiceInstanceFor(
content::BrowserContext* context) const override; content::BrowserContext* context) const override;
content::BrowserContext* GetBrowserContextToUse(
content::BrowserContext* context) const override;
}; };
#endif // CHROME_BROWSER_SPEECH_SPEECH_RECOGNITION_SERVICE_FACTORY_H_ #endif // CHROME_BROWSER_SPEECH_SPEECH_RECOGNITION_SERVICE_FACTORY_H_
// Copyright 2020 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/speech/speech_recognition_service_factory.h"
#include "chrome/test/base/testing_profile.h"
#include "content/public/test/browser_task_environment.h"
#include "testing/gmock/include/gmock/gmock.h"
namespace {
using testing::IsNull;
using testing::Not;
// Verifies that the service factory supports incognito profiles.
TEST(SpeechRecognitionServiceFactoryTest, IncognitoProfile) {
content::BrowserTaskEnvironment task_environment;
TestingProfile profile;
const speech::SpeechRecognitionService* const service =
SpeechRecognitionServiceFactory::GetForProfile(
profile.GetPrimaryOTRProfile());
EXPECT_THAT(service, Not(IsNull()));
}
} // namespace
...@@ -3593,6 +3593,7 @@ test("unit_tests") { ...@@ -3593,6 +3593,7 @@ test("unit_tests") {
"../browser/sharing/webrtc/sharing_service_host_unittest.cc", "../browser/sharing/webrtc/sharing_service_host_unittest.cc",
"../browser/sharing/webrtc/sharing_webrtc_connection_host_unittest.cc", "../browser/sharing/webrtc/sharing_webrtc_connection_host_unittest.cc",
"../browser/sharing/webrtc/webrtc_signalling_host_fcm_unittest.cc", "../browser/sharing/webrtc/webrtc_signalling_host_fcm_unittest.cc",
"../browser/speech/speech_recognition_service_factory_unittest.cc",
"../browser/tab_contents/form_interaction_tab_helper_unittest.cc", "../browser/tab_contents/form_interaction_tab_helper_unittest.cc",
"../browser/ui/autofill/payments/autofill_dialog_models_unittest.cc", "../browser/ui/autofill/payments/autofill_dialog_models_unittest.cc",
"../browser/ui/bookmarks/bookmark_editor_unittest.cc", "../browser/ui/bookmarks/bookmark_editor_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