Chromium Code Reviews

Side by Side Diff: chrome/browser/extensions/api/gcd_private/privet_v3_session.cc

Issue 1441993004: Hide PrivetHttpClient inside of PrivetV3Session (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@context4
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
OLDNEW
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/extensions/api/gcd_private/privet_v3_session.h" 5 #include "chrome/browser/extensions/api/gcd_private/privet_v3_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/location.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/single_thread_task_runner.h" 11 #include "base/single_thread_task_runner.h"
12 #include "base/thread_task_runner_handle.h" 12 #include "base/thread_task_runner_handle.h"
13 #include "chrome/browser/local_discovery/privet_constants.h" 13 #include "chrome/browser/local_discovery/privet_constants.h"
14 #include "chrome/browser/local_discovery/privet_http.h" 14 #include "chrome/browser/local_discovery/privet_http.h"
15 #include "chrome/browser/local_discovery/privet_http_impl.h"
15 #include "chrome/browser/local_discovery/privet_url_fetcher.h" 16 #include "chrome/browser/local_discovery/privet_url_fetcher.h"
16 #include "chrome/common/cloud_print/cloud_print_constants.h" 17 #include "chrome/common/cloud_print/cloud_print_constants.h"
17 #include "crypto/hmac.h" 18 #include "crypto/hmac.h"
18 #include "crypto/p224_spake.h" 19 #include "crypto/p224_spake.h"
19 #include "url/gurl.h" 20 #include "url/gurl.h"
20 21
21 using local_discovery::PrivetURLFetcher; 22 using local_discovery::PrivetURLFetcher;
22 23
23 namespace extensions { 24 namespace extensions {
24 25
(...skipping 166 matching lines...)
191 if (session_) { 192 if (session_) {
192 if (!callback_.is_null()) { 193 if (!callback_.is_null()) {
193 callback_.Run(result, value); 194 callback_.Run(result, value);
194 callback_.Reset(); 195 callback_.Reset();
195 } 196 }
196 base::ThreadTaskRunnerHandle::Get()->PostTask( 197 base::ThreadTaskRunnerHandle::Get()->PostTask(
197 FROM_HERE, base::Bind(&PrivetV3Session::DeleteFetcher, session_, 198 FROM_HERE, base::Bind(&PrivetV3Session::DeleteFetcher, session_,
198 base::Unretained(this))); 199 base::Unretained(this)));
199 session_.reset(); 200 session_.reset();
200 } 201 }
202 url_fetcher_.reset();
201 } 203 }
202 204
203 void PrivetV3Session::FetcherDelegate::OnTimeout() { 205 void PrivetV3Session::FetcherDelegate::OnTimeout() {
204 LOG(ERROR) << "PrivetURLFetcher timeout, url: " << url_fetcher_->url(); 206 LOG(ERROR) << "PrivetURLFetcher timeout, url: " << url_fetcher_->url();
205 ReplyAndDestroyItself(Result::STATUS_CONNECTIONERROR, 207 ReplyAndDestroyItself(Result::STATUS_CONNECTIONERROR,
206 base::DictionaryValue()); 208 base::DictionaryValue());
207 } 209 }
208 210
209 PrivetV3Session::PrivetV3Session( 211 PrivetV3Session::PrivetV3Session(
210 scoped_ptr<local_discovery::PrivetHTTPClient> client) 212 const scoped_refptr<net::URLRequestContextGetter>& context_getter,
211 : client_(client.Pass()), weak_ptr_factory_(this) {} 213 const net::HostPortPair& host_port)
214 : client_(new local_discovery::PrivetHTTPClientImpl("",
215 host_port,
216 context_getter)),
217 weak_ptr_factory_(this) {}
212 218
213 PrivetV3Session::~PrivetV3Session() { 219 PrivetV3Session::~PrivetV3Session() {
214 Cancel(); 220 Cancel();
215 } 221 }
216 222
217 void PrivetV3Session::Init(const InitCallback& callback) { 223 void PrivetV3Session::Init(const InitCallback& callback) {
218 DCHECK(fetchers_.empty()); 224 DCHECK(fetchers_.empty());
219 DCHECK(!client_->IsInHttpsMode()); 225 DCHECK(!client_->IsInHttpsMode());
220 DCHECK(session_id_.empty()); 226 DCHECK(session_id_.empty());
221 DCHECK(privet_auth_token_.empty()); 227 DCHECK(privet_auth_token_.empty());
(...skipping 234 matching lines...)
456 void PrivetV3Session::Cancel() { 462 void PrivetV3Session::Cancel() {
457 // Cancel started unconfirmed sessions. 463 // Cancel started unconfirmed sessions.
458 if (session_id_.empty() || client_->IsInHttpsMode()) 464 if (session_id_.empty() || client_->IsInHttpsMode())
459 return; 465 return;
460 base::DictionaryValue input; 466 base::DictionaryValue input;
461 input.SetString(kPrivetV3KeySessionId, session_id_); 467 input.SetString(kPrivetV3KeySessionId, session_id_);
462 StartPostRequest(kPrivetV3PairingCancelPath, input, MessageCallback()); 468 StartPostRequest(kPrivetV3PairingCancelPath, input, MessageCallback());
463 } 469 }
464 470
465 } // namespace extensions 471 } // namespace extensions
OLDNEW

Powered by Google App Engine