OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/local_discovery/privetv3_session.h" | 5 #include "chrome/browser/local_discovery/privetv3_session.h" |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
| 9 #include "base/location.h" |
9 #include "base/logging.h" | 10 #include "base/logging.h" |
10 #include "base/message_loop/message_loop.h" | 11 #include "base/single_thread_task_runner.h" |
| 12 #include "base/thread_task_runner_handle.h" |
11 #include "chrome/browser/local_discovery/privet_constants.h" | 13 #include "chrome/browser/local_discovery/privet_constants.h" |
12 #include "chrome/browser/local_discovery/privet_http.h" | 14 #include "chrome/browser/local_discovery/privet_http.h" |
13 #include "chrome/browser/local_discovery/privet_url_fetcher.h" | 15 #include "chrome/browser/local_discovery/privet_url_fetcher.h" |
14 #include "chrome/common/cloud_print/cloud_print_constants.h" | 16 #include "chrome/common/cloud_print/cloud_print_constants.h" |
15 #include "crypto/hmac.h" | 17 #include "crypto/hmac.h" |
16 #include "crypto/p224_spake.h" | 18 #include "crypto/p224_spake.h" |
17 #include "url/gurl.h" | 19 #include "url/gurl.h" |
18 | 20 |
19 namespace local_discovery { | 21 namespace local_discovery { |
20 | 22 |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 bool orphaned) { | 170 bool orphaned) { |
169 DCHECK(!url_fetcher_); | 171 DCHECK(!url_fetcher_); |
170 url_fetcher_ = | 172 url_fetcher_ = |
171 session_->client_->CreateURLFetcher(url, request_type, this).Pass(); | 173 session_->client_->CreateURLFetcher(url, request_type, this).Pass(); |
172 url_fetcher_->V3Mode(); | 174 url_fetcher_->V3Mode(); |
173 | 175 |
174 auto timeout_task = | 176 auto timeout_task = |
175 orphaned ? base::Bind(&FetcherDelegate::OnTimeout, base::Owned(this)) | 177 orphaned ? base::Bind(&FetcherDelegate::OnTimeout, base::Owned(this)) |
176 : base::Bind(&FetcherDelegate::OnTimeout, | 178 : base::Bind(&FetcherDelegate::OnTimeout, |
177 weak_ptr_factory_.GetWeakPtr()); | 179 weak_ptr_factory_.GetWeakPtr()); |
178 base::MessageLoop::current()->PostDelayedTask( | 180 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
179 FROM_HERE, timeout_task, | 181 FROM_HERE, timeout_task, |
180 base::TimeDelta::FromSeconds(kUrlFetcherTimeoutSec)); | 182 base::TimeDelta::FromSeconds(kUrlFetcherTimeoutSec)); |
181 return url_fetcher_.get(); | 183 return url_fetcher_.get(); |
182 } | 184 } |
183 | 185 |
184 void PrivetV3Session::FetcherDelegate::ReplyAndDestroyItself( | 186 void PrivetV3Session::FetcherDelegate::ReplyAndDestroyItself( |
185 Result result, | 187 Result result, |
186 const base::DictionaryValue& value) { | 188 const base::DictionaryValue& value) { |
187 if (session_) { | 189 if (session_) { |
188 if (!callback_.is_null()) { | 190 if (!callback_.is_null()) { |
189 callback_.Run(result, value); | 191 callback_.Run(result, value); |
190 callback_.Reset(); | 192 callback_.Reset(); |
191 } | 193 } |
192 base::MessageLoop::current()->PostTask( | 194 base::ThreadTaskRunnerHandle::Get()->PostTask( |
193 FROM_HERE, base::Bind(&PrivetV3Session::DeleteFetcher, session_, | 195 FROM_HERE, base::Bind(&PrivetV3Session::DeleteFetcher, session_, |
194 base::Unretained(this))); | 196 base::Unretained(this))); |
195 session_.reset(); | 197 session_.reset(); |
196 } | 198 } |
197 } | 199 } |
198 | 200 |
199 void PrivetV3Session::FetcherDelegate::OnTimeout() { | 201 void PrivetV3Session::FetcherDelegate::OnTimeout() { |
200 LOG(ERROR) << "PrivetURLFetcher timeout, url: " << url_fetcher_->url(); | 202 LOG(ERROR) << "PrivetURLFetcher timeout, url: " << url_fetcher_->url(); |
201 ReplyAndDestroyItself(Result::STATUS_CONNECTIONERROR, | 203 ReplyAndDestroyItself(Result::STATUS_CONNECTIONERROR, |
202 base::DictionaryValue()); | 204 base::DictionaryValue()); |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 void PrivetV3Session::Cancel() { | 440 void PrivetV3Session::Cancel() { |
439 // Cancel started unconfirmed sessions. | 441 // Cancel started unconfirmed sessions. |
440 if (session_id_.empty() || !fingerprint_.empty()) | 442 if (session_id_.empty() || !fingerprint_.empty()) |
441 return; | 443 return; |
442 base::DictionaryValue input; | 444 base::DictionaryValue input; |
443 input.SetString(kPrivetV3KeySessionId, session_id_); | 445 input.SetString(kPrivetV3KeySessionId, session_id_); |
444 StartPostRequest(kPrivetV3PairingCancelPath, input, MessageCallback()); | 446 StartPostRequest(kPrivetV3PairingCancelPath, input, MessageCallback()); |
445 } | 447 } |
446 | 448 |
447 } // namespace local_discovery | 449 } // namespace local_discovery |
OLD | NEW |