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/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_reader.h" | 8 #include "base/json/json_reader.h" |
9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/ptr_util.h" | |
13 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
14 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
15 #include "base/threading/thread_task_runner_handle.h" | 16 #include "base/threading/thread_task_runner_handle.h" |
16 #include "chrome/browser/extensions/api/gcd_private/privet_v3_context_getter.h" | 17 #include "chrome/browser/extensions/api/gcd_private/privet_v3_context_getter.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 "net/base/load_flags.h" | 20 #include "net/base/load_flags.h" |
20 #include "net/http/http_response_headers.h" | 21 #include "net/http/http_response_headers.h" |
21 #include "net/url_request/url_fetcher_delegate.h" | 22 #include "net/url_request/url_fetcher_delegate.h" |
22 #include "url/gurl.h" | 23 #include "url/gurl.h" |
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
479 if (!url.is_valid()) { | 480 if (!url.is_valid()) { |
480 callback.Run(Result::STATUS_SESSIONERROR, base::DictionaryValue()); | 481 callback.Run(Result::STATUS_SESSIONERROR, base::DictionaryValue()); |
481 return nullptr; | 482 return nullptr; |
482 } | 483 } |
483 | 484 |
484 // Don't abort cancel requests after session object is destroyed. | 485 // Don't abort cancel requests after session object is destroyed. |
485 const bool orphaned = (api == kPrivetV3PairingCancelPath); | 486 const bool orphaned = (api == kPrivetV3PairingCancelPath); |
486 FetcherDelegate* fetcher = | 487 FetcherDelegate* fetcher = |
487 new FetcherDelegate(weak_ptr_factory_.GetWeakPtr(), callback); | 488 new FetcherDelegate(weak_ptr_factory_.GetWeakPtr(), callback); |
488 if (!orphaned) | 489 if (!orphaned) |
489 fetchers_.push_back(fetcher); | 490 fetchers_.push_back(base::WrapUnique(fetcher)); |
490 net::URLFetcher* url_fetcher = | 491 net::URLFetcher* url_fetcher = |
491 fetcher->CreateURLFetcher(url, request_type, orphaned); | 492 fetcher->CreateURLFetcher(url, request_type, orphaned); |
492 url_fetcher->SetLoadFlags(url_fetcher->GetLoadFlags() | | 493 url_fetcher->SetLoadFlags(url_fetcher->GetLoadFlags() | |
493 net::LOAD_BYPASS_PROXY | net::LOAD_DISABLE_CACHE | | 494 net::LOAD_BYPASS_PROXY | net::LOAD_DISABLE_CACHE | |
494 net::LOAD_DO_NOT_SEND_COOKIES); | 495 net::LOAD_DO_NOT_SEND_COOKIES); |
495 url_fetcher->SetRequestContext(context_getter_.get()); | 496 url_fetcher->SetRequestContext(context_getter_.get()); |
496 url_fetcher->AddExtraRequestHeader( | 497 url_fetcher->AddExtraRequestHeader( |
497 std::string(kPrivetV3AuthTokenHeaderPrefix) + privet_auth_token_); | 498 std::string(kPrivetV3AuthTokenHeaderPrefix) + privet_auth_token_); |
498 | 499 |
499 return url_fetcher; | 500 return url_fetcher; |
500 } | 501 } |
501 | 502 |
502 void PrivetV3Session::DeleteFetcher(const FetcherDelegate* fetcher) { | 503 void PrivetV3Session::DeleteFetcher(const FetcherDelegate* fetcher) { |
503 fetchers_.erase(std::find(fetchers_.begin(), fetchers_.end(), fetcher)); | 504 fetchers_.erase(std::find_if( |
505 fetchers_.begin(), fetchers_.end(), | |
506 [fetcher](const std::unique_ptr<FetcherDelegate>& fetcher_delegate) { | |
507 return fetcher_delegate.get() == fetcher; | |
508 })); | |
asargent_no_longer_on_chrome
2016/09/06 22:12:40
optional: The following equivalent code seems a li
lazyboy
2016/09/06 23:49:38
Done.
| |
504 } | 509 } |
505 | 510 |
506 void PrivetV3Session::Cancel() { | 511 void PrivetV3Session::Cancel() { |
507 // Only session with pairing in process needs to be canceled. Paired sessions | 512 // Only session with pairing in process needs to be canceled. Paired sessions |
508 // (in https mode) does not need to be canceled. | 513 // (in https mode) does not need to be canceled. |
509 if (session_id_.empty() || use_https_) | 514 if (session_id_.empty() || use_https_) |
510 return; | 515 return; |
511 base::DictionaryValue input; | 516 base::DictionaryValue input; |
512 input.SetString(kPrivetV3KeySessionId, session_id_); | 517 input.SetString(kPrivetV3KeySessionId, session_id_); |
513 StartPostRequest(kPrivetV3PairingCancelPath, input, MessageCallback()); | 518 StartPostRequest(kPrivetV3PairingCancelPath, input, MessageCallback()); |
514 } | 519 } |
515 | 520 |
516 } // namespace extensions | 521 } // namespace extensions |
OLD | NEW |