| 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_LOCAL_DISCOVERY_PRIVETV3_SESSION_H_ | 5 #ifndef CHROME_BROWSER_LOCAL_DISCOVERY_PRIVETV3_SESSION_H_ |
| 6 #define CHROME_BROWSER_LOCAL_DISCOVERY_PRIVETV3_SESSION_H_ | 6 #define CHROME_BROWSER_LOCAL_DISCOVERY_PRIVETV3_SESSION_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/gtest_prod_util.h" |
| 11 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/memory/scoped_vector.h" | 13 #include "base/memory/scoped_vector.h" |
| 13 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 14 #include "chrome/common/extensions/api/gcd_private.h" | 15 #include "chrome/common/extensions/api/gcd_private.h" |
| 15 #include "net/url_request/url_fetcher.h" | 16 #include "net/url_request/url_fetcher.h" |
| 16 | 17 |
| 17 namespace base { | 18 namespace base { |
| 18 class DictionaryValue; | 19 class DictionaryValue; |
| 19 } | 20 } |
| 20 | 21 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 49 ~PrivetV3Session(); | 50 ~PrivetV3Session(); |
| 50 | 51 |
| 51 // Initializes session. Queries /privet/info and returns supported pairing | 52 // Initializes session. Queries /privet/info and returns supported pairing |
| 52 // types in callback. | 53 // types in callback. |
| 53 void Init(const InitCallback& callback); | 54 void Init(const InitCallback& callback); |
| 54 | 55 |
| 55 // Starts pairing by calling /privet/v3/pairing/start. | 56 // Starts pairing by calling /privet/v3/pairing/start. |
| 56 void StartPairing(PairingType pairing_type, const ResultCallback& callback); | 57 void StartPairing(PairingType pairing_type, const ResultCallback& callback); |
| 57 | 58 |
| 58 // Confirms pairing code by calling /privet/v3/pairing/confirm. | 59 // Confirms pairing code by calling /privet/v3/pairing/confirm. |
| 59 // TODO(vitalybuka): Call /privet/v3/pairing/auth after pairing. | 60 // Calls /privet/v3/pairing/auth after pairing. |
| 60 void ConfirmCode(const std::string& code, const ResultCallback& callback); | 61 void ConfirmCode(const std::string& code, const ResultCallback& callback); |
| 61 | 62 |
| 62 // TODO(vitalybuka): Make HTTPS request to device with certificate validation. | 63 // TODO(vitalybuka): Make HTTPS request to device with certificate validation. |
| 63 void SendMessage(const std::string& api, | 64 void SendMessage(const std::string& api, |
| 64 const base::DictionaryValue& input, | 65 const base::DictionaryValue& input, |
| 65 const MessageCallback& callback); | 66 const MessageCallback& callback); |
| 66 | 67 |
| 67 private: | 68 private: |
| 68 friend class PrivetV3SessionTest; | 69 friend class PrivetV3SessionTest; |
| 70 FRIEND_TEST_ALL_PREFIXES(PrivetV3SessionTest, Pairing); |
| 69 | 71 |
| 70 void OnInfoDone(const InitCallback& callback, | 72 void OnInfoDone(const InitCallback& callback, |
| 71 Result result, | 73 Result result, |
| 72 const base::DictionaryValue& response); | 74 const base::DictionaryValue& response); |
| 73 void OnPairingStartDone(const ResultCallback& callback, | 75 void OnPairingStartDone(const ResultCallback& callback, |
| 74 Result result, | 76 Result result, |
| 75 const base::DictionaryValue& response); | 77 const base::DictionaryValue& response); |
| 76 void OnPairingConfirmDone(const ResultCallback& callback, | 78 void OnPairingConfirmDone(const ResultCallback& callback, |
| 77 Result result, | 79 Result result, |
| 78 const base::DictionaryValue& response); | 80 const base::DictionaryValue& response); |
| 81 void OnAuthenticateDone(const ResultCallback& callback, |
| 82 Result result, |
| 83 const base::DictionaryValue& response); |
| 84 |
| 79 void RunCallback(const base::Closure& callback); | 85 void RunCallback(const base::Closure& callback); |
| 80 void StartGetRequest(const std::string& api, const MessageCallback& callback); | 86 void StartGetRequest(const std::string& api, const MessageCallback& callback); |
| 81 void StartPostRequest(const std::string& api, | 87 void StartPostRequest(const std::string& api, |
| 82 const base::DictionaryValue& input, | 88 const base::DictionaryValue& input, |
| 83 const MessageCallback& callback); | 89 const MessageCallback& callback); |
| 84 PrivetURLFetcher* CreateFetcher(const std::string& api, | 90 PrivetURLFetcher* CreateFetcher(const std::string& api, |
| 85 net::URLFetcher::RequestType request_type, | 91 net::URLFetcher::RequestType request_type, |
| 86 const MessageCallback& callback); | 92 const MessageCallback& callback); |
| 87 void DeleteFetcher(const FetcherDelegate* fetcher); | 93 void DeleteFetcher(const FetcherDelegate* fetcher); |
| 88 | 94 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 110 // Intercepts POST requests. Used by tests only. | 116 // Intercepts POST requests. Used by tests only. |
| 111 base::Callback<void(const base::DictionaryValue&)> on_post_data_; | 117 base::Callback<void(const base::DictionaryValue&)> on_post_data_; |
| 112 | 118 |
| 113 base::WeakPtrFactory<PrivetV3Session> weak_ptr_factory_; | 119 base::WeakPtrFactory<PrivetV3Session> weak_ptr_factory_; |
| 114 DISALLOW_COPY_AND_ASSIGN(PrivetV3Session); | 120 DISALLOW_COPY_AND_ASSIGN(PrivetV3Session); |
| 115 }; | 121 }; |
| 116 | 122 |
| 117 } // namespace local_discovery | 123 } // namespace local_discovery |
| 118 | 124 |
| 119 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_PRIVETV3_SESSION_H_ | 125 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_PRIVETV3_SESSION_H_ |
| OLD | NEW |