| 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 #ifndef CHROME_BROWSER_EXTENSIONS_API_GCD_PRIVATE_PRIVET_V3_SESSION_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_GCD_PRIVATE_PRIVET_V3_SESSION_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_GCD_PRIVATE_PRIVET_V3_SESSION_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_GCD_PRIVATE_PRIVET_V3_SESSION_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 } | 25 } |
| 26 | 26 |
| 27 namespace local_discovery { | 27 namespace local_discovery { |
| 28 class PrivetHTTPClient; | 28 class PrivetHTTPClient; |
| 29 class PrivetJSONOperation; | 29 class PrivetJSONOperation; |
| 30 class PrivetURLFetcher; | 30 class PrivetURLFetcher; |
| 31 } | 31 } |
| 32 | 32 |
| 33 namespace extensions { | 33 namespace extensions { |
| 34 | 34 |
| 35 class PrivetV3ContextGetter; |
| 36 |
| 35 // Manages secure communication between browser and local Privet device. | 37 // Manages secure communication between browser and local Privet device. |
| 36 class PrivetV3Session { | 38 class PrivetV3Session { |
| 37 private: | 39 private: |
| 38 class FetcherDelegate; | 40 class FetcherDelegate; |
| 39 | 41 |
| 40 public: | 42 public: |
| 41 typedef extensions::api::gcd_private::PairingType PairingType; | 43 typedef extensions::api::gcd_private::PairingType PairingType; |
| 42 typedef extensions::api::gcd_private::Status Result; | 44 typedef extensions::api::gcd_private::Status Result; |
| 43 | 45 |
| 44 typedef base::Callback< | 46 typedef base::Callback< |
| 45 void(Result result, const base::DictionaryValue& response)> InitCallback; | 47 void(Result result, const base::DictionaryValue& response)> InitCallback; |
| 46 | 48 |
| 47 typedef base::Callback<void(Result result)> ResultCallback; | 49 typedef base::Callback<void(Result result)> ResultCallback; |
| 48 typedef base::Callback<void(Result result, | 50 typedef base::Callback<void(Result result, |
| 49 const base::DictionaryValue& response)> | 51 const base::DictionaryValue& response)> |
| 50 MessageCallback; | 52 MessageCallback; |
| 51 | 53 |
| 52 PrivetV3Session( | 54 PrivetV3Session(const scoped_refptr<PrivetV3ContextGetter>& context_getter, |
| 53 const scoped_refptr<net::URLRequestContextGetter>& context_getter, | 55 const net::HostPortPair& host_port); |
| 54 const net::HostPortPair& host_port); | |
| 55 ~PrivetV3Session(); | 56 ~PrivetV3Session(); |
| 56 | 57 |
| 57 // Initializes session. Queries /privet/info and returns supported pairing | 58 // Initializes session. Queries /privet/info and returns supported pairing |
| 58 // types in callback. | 59 // types in callback. |
| 59 void Init(const InitCallback& callback); | 60 void Init(const InitCallback& callback); |
| 60 | 61 |
| 61 // Starts pairing by calling /privet/v3/pairing/start. | 62 // Starts pairing by calling /privet/v3/pairing/start. |
| 62 void StartPairing(PairingType pairing_type, const ResultCallback& callback); | 63 void StartPairing(PairingType pairing_type, const ResultCallback& callback); |
| 63 | 64 |
| 64 // Confirms pairing code by calling /privet/v3/pairing/confirm. | 65 // Confirms pairing code by calling /privet/v3/pairing/confirm. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 76 | 77 |
| 77 void OnInfoDone(const InitCallback& callback, | 78 void OnInfoDone(const InitCallback& callback, |
| 78 Result result, | 79 Result result, |
| 79 const base::DictionaryValue& response); | 80 const base::DictionaryValue& response); |
| 80 void OnPairingStartDone(const ResultCallback& callback, | 81 void OnPairingStartDone(const ResultCallback& callback, |
| 81 Result result, | 82 Result result, |
| 82 const base::DictionaryValue& response); | 83 const base::DictionaryValue& response); |
| 83 void OnPairingConfirmDone(const ResultCallback& callback, | 84 void OnPairingConfirmDone(const ResultCallback& callback, |
| 84 Result result, | 85 Result result, |
| 85 const base::DictionaryValue& response); | 86 const base::DictionaryValue& response); |
| 87 void OnPairedHostAddedToContext(const std::string& auth_code, |
| 88 const ResultCallback& callback); |
| 86 void OnAuthenticateDone(const ResultCallback& callback, | 89 void OnAuthenticateDone(const ResultCallback& callback, |
| 87 Result result, | 90 Result result, |
| 88 const base::DictionaryValue& response); | 91 const base::DictionaryValue& response); |
| 89 | 92 |
| 90 void RunCallback(const base::Closure& callback); | 93 void RunCallback(const base::Closure& callback); |
| 91 void StartGetRequest(const std::string& api, const MessageCallback& callback); | 94 void StartGetRequest(const std::string& api, const MessageCallback& callback); |
| 92 void StartPostRequest(const std::string& api, | 95 void StartPostRequest(const std::string& api, |
| 93 const base::DictionaryValue& input, | 96 const base::DictionaryValue& input, |
| 94 const MessageCallback& callback); | 97 const MessageCallback& callback); |
| 95 local_discovery::PrivetURLFetcher* CreateFetcher( | 98 local_discovery::PrivetURLFetcher* CreateFetcher( |
| 96 const std::string& api, | 99 const std::string& api, |
| 97 net::URLFetcher::RequestType request_type, | 100 net::URLFetcher::RequestType request_type, |
| 98 const MessageCallback& callback); | 101 const MessageCallback& callback); |
| 99 void DeleteFetcher(const FetcherDelegate* fetcher); | 102 void DeleteFetcher(const FetcherDelegate* fetcher); |
| 100 void Cancel(); | 103 void Cancel(); |
| 101 | 104 |
| 102 // Creates instances of PrivetURLFetcher. | 105 // Creates instances of PrivetURLFetcher. |
| 103 scoped_ptr<local_discovery::PrivetHTTPClient> client_; | 106 scoped_ptr<local_discovery::PrivetHTTPClient> client_; |
| 104 | 107 |
| 108 // Provides context for client_. |
| 109 scoped_refptr<PrivetV3ContextGetter> context_getter_; |
| 110 |
| 105 // Current authentication token. | 111 // Current authentication token. |
| 106 std::string privet_auth_token_; | 112 std::string privet_auth_token_; |
| 107 | 113 |
| 108 // ID of the session received from pairing/start. | 114 // ID of the session received from pairing/start. |
| 109 std::string session_id_; | 115 std::string session_id_; |
| 110 | 116 |
| 111 // Device commitment received from pairing/start. | 117 // Device commitment received from pairing/start. |
| 112 std::string commitment_; | 118 std::string commitment_; |
| 113 | 119 |
| 114 // Key exchange algorithm for pairing. | 120 // Key exchange algorithm for pairing. |
| 115 scoped_ptr<crypto::P224EncryptedKeyExchange> spake_; | 121 scoped_ptr<crypto::P224EncryptedKeyExchange> spake_; |
| 116 | 122 |
| 117 // HTTPS port of the device. | 123 // HTTPS port of the device. |
| 118 uint16_t https_port_ = 0; | 124 uint16_t https_port_ = 0; |
| 119 | 125 |
| 120 // List of fetches to cancel when session is destroyed. | 126 // List of fetches to cancel when session is destroyed. |
| 121 ScopedVector<FetcherDelegate> fetchers_; | 127 ScopedVector<FetcherDelegate> fetchers_; |
| 122 | 128 |
| 123 // Intercepts POST requests. Used by tests only. | 129 // Intercepts POST requests. Used by tests only. |
| 124 base::Callback<void(const base::DictionaryValue&)> on_post_data_; | 130 base::Callback<void(const base::DictionaryValue&)> on_post_data_; |
| 125 | 131 |
| 126 base::WeakPtrFactory<PrivetV3Session> weak_ptr_factory_; | 132 base::WeakPtrFactory<PrivetV3Session> weak_ptr_factory_; |
| 127 DISALLOW_COPY_AND_ASSIGN(PrivetV3Session); | 133 DISALLOW_COPY_AND_ASSIGN(PrivetV3Session); |
| 128 }; | 134 }; |
| 129 | 135 |
| 130 } // namespace extensions | 136 } // namespace extensions |
| 131 | 137 |
| 132 #endif // CHROME_BROWSER_EXTENSIONS_API_GCD_PRIVATE_PRIVET_V3_SESSION_H_ | 138 #endif // CHROME_BROWSER_EXTENSIONS_API_GCD_PRIVATE_PRIVET_V3_SESSION_H_ |
| OLD | NEW |