| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/speech/speech_recognition_request.h" | 5 #include "chrome/browser/speech/speech_recognition_request.h" |
| 6 | 6 |
| 7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 DCHECK(delegate); | 101 DCHECK(delegate); |
| 102 } | 102 } |
| 103 | 103 |
| 104 bool SpeechRecognitionRequest::Send(const std::string& audio_data) { | 104 bool SpeechRecognitionRequest::Send(const std::string& audio_data) { |
| 105 DCHECK(!url_fetcher_.get()); | 105 DCHECK(!url_fetcher_.get()); |
| 106 | 106 |
| 107 url_fetcher_.reset(URLFetcher::Create( | 107 url_fetcher_.reset(URLFetcher::Create( |
| 108 url_fetcher_id_for_tests, url_, URLFetcher::POST, this)); | 108 url_fetcher_id_for_tests, url_, URLFetcher::POST, this)); |
| 109 url_fetcher_->set_upload_data(kMimeRawAudio, audio_data); | 109 url_fetcher_->set_upload_data(kMimeRawAudio, audio_data); |
| 110 url_fetcher_->set_request_context(url_context_); | 110 url_fetcher_->set_request_context(url_context_); |
| 111 |
| 112 // The speech recognition API does not require user identification as part |
| 113 // of requests, so we don't send cookies or auth data for these requests to |
| 114 // prevent any accidental connection between users who are logged into the |
| 115 // domain for other services (e.g. bookmark sync) with the speech requests. |
| 111 url_fetcher_->set_load_flags( | 116 url_fetcher_->set_load_flags( |
| 112 net::LOAD_BYPASS_CACHE | net::LOAD_DISABLE_CACHE | | |
| 113 net::LOAD_DO_NOT_SAVE_COOKIES | net::LOAD_DO_NOT_SEND_COOKIES | | 117 net::LOAD_DO_NOT_SAVE_COOKIES | net::LOAD_DO_NOT_SEND_COOKIES | |
| 114 net::LOAD_DO_NOT_SEND_AUTH_DATA); | 118 net::LOAD_DO_NOT_SEND_AUTH_DATA); |
| 115 url_fetcher_->Start(); | 119 url_fetcher_->Start(); |
| 116 return true; | 120 return true; |
| 117 } | 121 } |
| 118 | 122 |
| 119 void SpeechRecognitionRequest::OnURLFetchComplete( | 123 void SpeechRecognitionRequest::OnURLFetchComplete( |
| 120 const URLFetcher* source, | 124 const URLFetcher* source, |
| 121 const GURL& url, | 125 const GURL& url, |
| 122 const URLRequestStatus& status, | 126 const URLRequestStatus& status, |
| 123 int response_code, | 127 int response_code, |
| 124 const ResponseCookies& cookies, | 128 const ResponseCookies& cookies, |
| 125 const std::string& data) { | 129 const std::string& data) { |
| 126 DCHECK_EQ(url_fetcher_.get(), source); | 130 DCHECK_EQ(url_fetcher_.get(), source); |
| 127 DCHECK(url_.possibly_invalid_spec() == url.possibly_invalid_spec()); | 131 DCHECK(url_.possibly_invalid_spec() == url.possibly_invalid_spec()); |
| 128 | 132 |
| 129 bool error = !status.is_success() || response_code != 200; | 133 bool error = !status.is_success() || response_code != 200; |
| 130 string16 value; | 134 string16 value; |
| 131 if (!error) | 135 if (!error) |
| 132 error = !ParseServerResponse(data, &value); | 136 error = !ParseServerResponse(data, &value); |
| 133 url_fetcher_.reset(); | 137 url_fetcher_.reset(); |
| 134 | 138 |
| 135 DLOG(INFO) << "SpeechRecognitionRequest: Invoking delegate with result."; | 139 DLOG(INFO) << "SpeechRecognitionRequest: Invoking delegate with result."; |
| 136 delegate_->SetRecognitionResult(error, value); | 140 delegate_->SetRecognitionResult(error, value); |
| 137 } | 141 } |
| 138 | 142 |
| 139 } // namespace speech_input | 143 } // namespace speech_input |
| OLD | NEW |