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

Side by Side Diff: chrome/browser/speech/tts_chromeos.cc

Issue 2599673005: arc: Use GET_INTERFACE_FOR_METHOD macro (Closed)
Patch Set: Addressed feedback Created 3 years, 11 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/macros.h" 5 #include "base/macros.h"
6 #include "chrome/browser/speech/tts_platform.h" 6 #include "chrome/browser/speech/tts_platform.h"
7 #include "components/arc/arc_bridge_service.h" 7 #include "components/arc/arc_bridge_service.h"
8 #include "components/arc/arc_service_manager.h" 8 #include "components/arc/arc_service_manager.h"
9 #include "components/arc/common/tts.mojom.h" 9 #include "components/arc/common/tts.mojom.h"
10 #include "content/public/browser/browser_thread.h" 10 #include "content/public/browser/browser_thread.h"
11 11
12 namespace {
13
14 // For Speak and Stop.
15 constexpr uint32_t kDefaultMinVersion = 0;
16
17 // Helper returning an ARC tts instance.
18 arc::mojom::TtsInstance* GetArcTts(const std::string& method_name_for_logging,
19 uint32_t min_version) {
20 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
21 auto* const arc_service_manager = arc::ArcServiceManager::Get();
22 if (!arc_service_manager)
23 return nullptr;
24
25 return arc_service_manager->arc_bridge_service()->tts()->GetInstanceForMethod(
26 method_name_for_logging, min_version);
27 }
28
29 } // namespace
30
31 // This class includes extension-based tts through LoadBuiltInTtsExtension and 12 // This class includes extension-based tts through LoadBuiltInTtsExtension and
32 // native tts through ARC. 13 // native tts through ARC.
33 class TtsPlatformImplChromeOs : public TtsPlatformImpl { 14 class TtsPlatformImplChromeOs : public TtsPlatformImpl {
34 public: 15 public:
35 // TtsPlatformImpl overrides: 16 // TtsPlatformImpl overrides:
36 bool PlatformImplAvailable() override { 17 bool PlatformImplAvailable() override {
37 return arc::ArcServiceManager::Get() && 18 return arc::ArcServiceManager::Get() &&
38 arc::ArcServiceManager::Get() 19 arc::ArcServiceManager::Get()
39 ->arc_bridge_service() 20 ->arc_bridge_service()
40 ->tts() 21 ->tts()
41 ->has_instance(); 22 ->has_instance();
42 } 23 }
43 24
44 bool LoadBuiltInTtsExtension( 25 bool LoadBuiltInTtsExtension(
45 content::BrowserContext* browser_context) override { 26 content::BrowserContext* browser_context) override {
46 TtsEngineDelegate* tts_engine_delegate = 27 TtsEngineDelegate* tts_engine_delegate =
47 TtsController::GetInstance()->GetTtsEngineDelegate(); 28 TtsController::GetInstance()->GetTtsEngineDelegate();
48 if (tts_engine_delegate) 29 if (tts_engine_delegate)
49 return tts_engine_delegate->LoadBuiltInTtsExtension(browser_context); 30 return tts_engine_delegate->LoadBuiltInTtsExtension(browser_context);
50 return false; 31 return false;
51 } 32 }
52 33
53 bool Speak(int utterance_id, 34 bool Speak(int utterance_id,
54 const std::string& utterance, 35 const std::string& utterance,
55 const std::string& lang, 36 const std::string& lang,
56 const VoiceData& voice, 37 const VoiceData& voice,
57 const UtteranceContinuousParameters& params) override { 38 const UtteranceContinuousParameters& params) override {
58 arc::mojom::TtsInstance* tts = GetArcTts("Speak", kDefaultMinVersion); 39 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
40 auto* const arc_service_manager = arc::ArcServiceManager::Get();
41 if (!arc_service_manager)
42 return false;
43 arc::mojom::TtsInstance* tts = ARC_GET_INSTANCE_FOR_METHOD(
44 arc_service_manager->arc_bridge_service()->tts(), Speak);
59 if (!tts) 45 if (!tts)
60 return false; 46 return false;
61 47
62 arc::mojom::TtsUtterancePtr arc_utterance = arc::mojom::TtsUtterance::New(); 48 arc::mojom::TtsUtterancePtr arc_utterance = arc::mojom::TtsUtterance::New();
63 arc_utterance->utteranceId = utterance_id; 49 arc_utterance->utteranceId = utterance_id;
64 arc_utterance->text = utterance; 50 arc_utterance->text = utterance;
65 arc_utterance->rate = params.rate; 51 arc_utterance->rate = params.rate;
66 arc_utterance->pitch = params.pitch; 52 arc_utterance->pitch = params.pitch;
67 tts->Speak(std::move(arc_utterance)); 53 tts->Speak(std::move(arc_utterance));
68 return true; 54 return true;
69 } 55 }
70 56
71 bool StopSpeaking() override { 57 bool StopSpeaking() override {
72 arc::mojom::TtsInstance* tts = GetArcTts("Stop", kDefaultMinVersion); 58 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
59 auto* const arc_service_manager = arc::ArcServiceManager::Get();
60 if (!arc_service_manager)
61 return false;
62 arc::mojom::TtsInstance* tts = ARC_GET_INSTANCE_FOR_METHOD(
63 arc_service_manager->arc_bridge_service()->tts(), Stop);
73 if (!tts) 64 if (!tts)
74 return false; 65 return false;
75 66
76 tts->Stop(); 67 tts->Stop();
77 return true; 68 return true;
78 } 69 }
79 70
80 void GetVoices(std::vector<VoiceData>* out_voices) override { 71 void GetVoices(std::vector<VoiceData>* out_voices) override {
81 out_voices->push_back(VoiceData()); 72 out_voices->push_back(VoiceData());
82 VoiceData& voice = out_voices->back(); 73 VoiceData& voice = out_voices->back();
(...skipping 23 matching lines...) Expand all
106 // static 97 // static
107 TtsPlatformImpl* TtsPlatformImpl::GetInstance() { 98 TtsPlatformImpl* TtsPlatformImpl::GetInstance() {
108 return TtsPlatformImplChromeOs::GetInstance(); 99 return TtsPlatformImplChromeOs::GetInstance();
109 } 100 }
110 101
111 // static 102 // static
112 TtsPlatformImplChromeOs* 103 TtsPlatformImplChromeOs*
113 TtsPlatformImplChromeOs::GetInstance() { 104 TtsPlatformImplChromeOs::GetInstance() {
114 return base::Singleton<TtsPlatformImplChromeOs>::get(); 105 return base::Singleton<TtsPlatformImplChromeOs>::get();
115 } 106 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698