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

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

Issue 2357053002: Always use arc::InstanceHolder<T>::GetInstanceForMethod (Closed)
Patch Set: review Created 4 years, 3 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/common/tts.mojom.h" 8 #include "components/arc/common/tts.mojom.h"
9 #include "content/public/browser/browser_thread.h" 9 #include "content/public/browser/browser_thread.h"
10 10
11 namespace { 11 namespace {
12 12
13 // For Speak and Stop.
14 constexpr uint32_t kDefaultMinVersion = 0;
15
13 // Helper returning an ARC tts instance. 16 // Helper returning an ARC tts instance.
14 arc::mojom::TtsInstance* GetArcTts() { 17 arc::mojom::TtsInstance* GetArcTts(const std::string& method_name_for_logging,
18 uint32_t min_version) {
15 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 19 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
16 return arc::ArcBridgeService::Get() 20 return arc::ArcBridgeService::Get()
17 ? arc::ArcBridgeService::Get()->tts()->instance() 21 ? arc::ArcBridgeService::Get()->tts()->GetInstanceForMethod(
22 method_name_for_logging, min_version)
18 : nullptr; 23 : nullptr;
19 } 24 }
20 25
21 } // namespace 26 } // namespace
22 27
23 // This class includes extension-based tts through LoadBuiltInTtsExtension and 28 // This class includes extension-based tts through LoadBuiltInTtsExtension and
24 // native tts through ARC. 29 // native tts through ARC.
25 class TtsPlatformImplChromeOs : public TtsPlatformImpl { 30 class TtsPlatformImplChromeOs : public TtsPlatformImpl {
26 public: 31 public:
27 // TtsPlatformImpl overrides: 32 // TtsPlatformImpl overrides:
28 bool PlatformImplAvailable() override { return GetArcTts() != nullptr; } 33 bool PlatformImplAvailable() override {
34 return arc::ArcBridgeService::Get() &&
35 arc::ArcBridgeService::Get()->tts()->HasInstance();
36 }
29 37
30 bool LoadBuiltInTtsExtension( 38 bool LoadBuiltInTtsExtension(
31 content::BrowserContext* browser_context) override { 39 content::BrowserContext* browser_context) override {
32 TtsEngineDelegate* tts_engine_delegate = 40 TtsEngineDelegate* tts_engine_delegate =
33 TtsController::GetInstance()->GetTtsEngineDelegate(); 41 TtsController::GetInstance()->GetTtsEngineDelegate();
34 if (tts_engine_delegate) 42 if (tts_engine_delegate)
35 return tts_engine_delegate->LoadBuiltInTtsExtension(browser_context); 43 return tts_engine_delegate->LoadBuiltInTtsExtension(browser_context);
36 return false; 44 return false;
37 } 45 }
38 46
39 bool Speak(int utterance_id, 47 bool Speak(int utterance_id,
40 const std::string& utterance, 48 const std::string& utterance,
41 const std::string& lang, 49 const std::string& lang,
42 const VoiceData& voice, 50 const VoiceData& voice,
43 const UtteranceContinuousParameters& params) override { 51 const UtteranceContinuousParameters& params) override {
44 arc::mojom::TtsInstance* tts = GetArcTts(); 52 arc::mojom::TtsInstance* tts = GetArcTts("Speak", kDefaultMinVersion);
45 if (!tts) 53 if (!tts)
46 return false; 54 return false;
47 55
48 arc::mojom::TtsUtterancePtr arc_utterance = arc::mojom::TtsUtterance::New(); 56 arc::mojom::TtsUtterancePtr arc_utterance = arc::mojom::TtsUtterance::New();
49 arc_utterance->utteranceId = utterance_id; 57 arc_utterance->utteranceId = utterance_id;
50 arc_utterance->text = utterance; 58 arc_utterance->text = utterance;
51 arc_utterance->rate = params.rate; 59 arc_utterance->rate = params.rate;
52 arc_utterance->pitch = params.pitch; 60 arc_utterance->pitch = params.pitch;
53 tts->Speak(std::move(arc_utterance)); 61 tts->Speak(std::move(arc_utterance));
54 return true; 62 return true;
55 } 63 }
56 64
57 bool StopSpeaking() override { 65 bool StopSpeaking() override {
58 arc::mojom::TtsInstance* tts = GetArcTts(); 66 arc::mojom::TtsInstance* tts = GetArcTts("Stop", kDefaultMinVersion);
59 if (!tts) 67 if (!tts)
60 return false; 68 return false;
61 69
62 tts->Stop(); 70 tts->Stop();
63 return true; 71 return true;
64 } 72 }
65 73
66 void GetVoices(std::vector<VoiceData>* out_voices) override { 74 void GetVoices(std::vector<VoiceData>* out_voices) override {
67 out_voices->push_back(VoiceData()); 75 out_voices->push_back(VoiceData());
68 VoiceData& voice = out_voices->back(); 76 VoiceData& voice = out_voices->back();
(...skipping 23 matching lines...) Expand all
92 // static 100 // static
93 TtsPlatformImpl* TtsPlatformImpl::GetInstance() { 101 TtsPlatformImpl* TtsPlatformImpl::GetInstance() {
94 return TtsPlatformImplChromeOs::GetInstance(); 102 return TtsPlatformImplChromeOs::GetInstance();
95 } 103 }
96 104
97 // static 105 // static
98 TtsPlatformImplChromeOs* 106 TtsPlatformImplChromeOs*
99 TtsPlatformImplChromeOs::GetInstance() { 107 TtsPlatformImplChromeOs::GetInstance() {
100 return base::Singleton<TtsPlatformImplChromeOs>::get(); 108 return base::Singleton<TtsPlatformImplChromeOs>::get();
101 } 109 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698