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

Side by Side Diff: chrome/browser/chromeos/dbus/speech_synthesizer_client.cc

Issue 9838085: Move files inside chrome/browser/chromeos/dbus to chromeos/dbus (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: _ Created 8 years, 9 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/chromeos/dbus/speech_synthesizer_client.h"
6
7 #include "base/bind.h"
8 #include "base/chromeos/chromeos_version.h"
9 #include "base/compiler_specific.h"
10 #include "dbus/bus.h"
11 #include "dbus/message.h"
12 #include "dbus/object_path.h"
13 #include "dbus/object_proxy.h"
14 #include "third_party/cros_system_api/dbus/service_constants.h"
15
16 namespace chromeos {
17
18 // TODO(chaitanyag): rename to "locale" after making equivalent change in
19 // Chrome OS code.
20 const char SpeechSynthesizerClient::kSpeechPropertyLocale[] = "name";
21
22 const char SpeechSynthesizerClient::kSpeechPropertyGender[] = "gender";
23 const char SpeechSynthesizerClient::kSpeechPropertyRate[] = "rate";
24 const char SpeechSynthesizerClient::kSpeechPropertyPitch[] = "pitch";
25 const char SpeechSynthesizerClient::kSpeechPropertyVolume[] = "volume";
26 const char SpeechSynthesizerClient::kSpeechPropertyEquals[] = "=";
27 const char SpeechSynthesizerClient::kSpeechPropertyDelimiter[] = ";";
28
29 class SpeechSynthesizerClientImpl : public SpeechSynthesizerClient {
30 public:
31 explicit SpeechSynthesizerClientImpl(dbus::Bus* bus)
32 : proxy_(NULL),
33 weak_ptr_factory_(this) {
34 proxy_ = bus->GetObjectProxy(
35 speech_synthesis::kSpeechSynthesizerServiceName,
36 dbus::ObjectPath(speech_synthesis::kSpeechSynthesizerServicePath));
37 }
38 virtual ~SpeechSynthesizerClientImpl() {}
39
40 virtual void Speak(const std::string& text,
41 const std::string& properties) OVERRIDE {
42 dbus::MethodCall method_call(speech_synthesis::kSpeechSynthesizerInterface,
43 speech_synthesis::kSpeak);
44 dbus::MessageWriter writer(&method_call);
45 writer.AppendString(text);
46 writer.AppendString(properties);
47 proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
48 base::Bind(&SpeechSynthesizerClientImpl::OnSpeak,
49 weak_ptr_factory_.GetWeakPtr()));
50 }
51
52 virtual void StopSpeaking() OVERRIDE {
53 dbus::MethodCall method_call(speech_synthesis::kSpeechSynthesizerInterface,
54 speech_synthesis::kStop);
55 proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
56 base::Bind(&SpeechSynthesizerClientImpl::OnStopSpeaking,
57 weak_ptr_factory_.GetWeakPtr()));
58 }
59
60 virtual void IsSpeaking(IsSpeakingCallback callback) OVERRIDE {
61 dbus::MethodCall method_call(speech_synthesis::kSpeechSynthesizerInterface,
62 speech_synthesis::kIsSpeaking);
63 proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
64 base::Bind(&SpeechSynthesizerClientImpl::OnIsSpeaking,
65 weak_ptr_factory_.GetWeakPtr(),
66 callback));
67 }
68
69 private:
70 // Called when a response for Speak() is received
71 void OnSpeak(dbus::Response* response) {
72 if (!response) {
73 LOG(ERROR) << "Failed to speak.";
74 return;
75 }
76 VLOG(1) << "Spoke: " << response->ToString();
77 }
78
79 // Called when a response for StopSpeaking() is received
80 void OnStopSpeaking(dbus::Response* response) {
81 if (!response) {
82 LOG(ERROR) << "Failed to stop speaking.";
83 return;
84 }
85 VLOG(1) << "Stopped speaking: " << response->ToString();
86 }
87
88 // Called when a response for IsSpeaking() is received
89 void OnIsSpeaking(IsSpeakingCallback callback, dbus::Response* response) {
90 bool value = false;
91 if (response) {
92 dbus::MessageReader reader(response);
93 reader.PopBool(&value);
94 } else {
95 LOG(ERROR) << "Failed to ask if it is speaking";
96 }
97 callback.Run(value);
98 }
99
100 dbus::ObjectProxy* proxy_;
101 base::WeakPtrFactory<SpeechSynthesizerClientImpl> weak_ptr_factory_;
102
103 DISALLOW_COPY_AND_ASSIGN(SpeechSynthesizerClientImpl);
104 };
105
106 class SpeechSynthesizerClientStubImpl : public SpeechSynthesizerClient {
107 public:
108 SpeechSynthesizerClientStubImpl() {}
109 virtual ~SpeechSynthesizerClientStubImpl() {}
110 virtual void Speak(const std::string& text,
111 const std::string& properties) OVERRIDE {}
112 virtual void StopSpeaking() OVERRIDE {}
113 virtual void IsSpeaking(IsSpeakingCallback callback) OVERRIDE {
114 callback.Run(false);
115 }
116
117 private:
118 DISALLOW_COPY_AND_ASSIGN(SpeechSynthesizerClientStubImpl);
119 };
120
121 SpeechSynthesizerClient::SpeechSynthesizerClient() {
122 }
123
124 SpeechSynthesizerClient::~SpeechSynthesizerClient() {
125 }
126
127 // static
128 SpeechSynthesizerClient* SpeechSynthesizerClient::Create(dbus::Bus* bus) {
129 if (base::chromeos::IsRunningOnChromeOS()) {
130 return new SpeechSynthesizerClientImpl(bus);
131 } else {
132 return new SpeechSynthesizerClientStubImpl();
133 }
134 }
135
136 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698