Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 BLIMP_CLIENT_SESSION_ASSIGNMENT_SOURCE_H_ | 5 #ifndef BLIMP_CLIENT_SESSION_ASSIGNMENT_SOURCE_H_ |
| 6 #define BLIMP_CLIENT_SESSION_ASSIGNMENT_SOURCE_H_ | 6 #define BLIMP_CLIENT_SESSION_ASSIGNMENT_SOURCE_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "blimp/client/blimp_client_export.h" | 11 #include "blimp/client/blimp_client_export.h" |
| 12 #include "net/base/ip_endpoint.h" | 12 #include "net/base/ip_endpoint.h" |
| 13 #include "net/url_request/url_fetcher.h" | |
| 14 #include "net/url_request/url_fetcher_delegate.h" | |
| 13 | 15 |
| 14 namespace base { | 16 namespace base { |
| 15 class SingleThreadTaskRunner; | 17 class SingleThreadTaskRunner; |
| 16 } | 18 } |
| 17 | 19 |
| 20 namespace net { | |
| 21 class URLFetcher; | |
| 22 class URLRequestContextGetter; | |
| 23 } | |
| 24 | |
| 18 namespace blimp { | 25 namespace blimp { |
| 19 namespace client { | 26 namespace client { |
| 20 | 27 |
| 28 // TODO(kmarshall): Take values from configuration data. | |
| 29 const char kDummyClientToken[] = "MyVoiceIsMyPassport"; | |
| 30 | |
| 31 // Potential assigner URLs. | |
| 32 const char kDefaultAssignerURL[] = | |
| 33 "https://blimp-pa.googleapis.com/v1/assignment"; | |
| 34 | |
| 21 // An Assignment contains the configuration data needed for a client | 35 // An Assignment contains the configuration data needed for a client |
| 22 // to connect to the engine. | 36 // to connect to the engine. |
| 23 struct BLIMP_CLIENT_EXPORT Assignment { | 37 struct BLIMP_CLIENT_EXPORT Assignment { |
| 38 enum TransportProtocol { | |
| 39 UNKNOWN = 0, | |
| 40 SSL = 1, | |
| 41 TCP = 2, | |
| 42 QUIC = 3, | |
| 43 }; | |
| 44 | |
| 45 Assignment(); | |
| 46 ~Assignment(); | |
| 47 | |
| 48 TransportProtocol transport_protocol; | |
| 24 net::IPEndPoint ip_endpoint; | 49 net::IPEndPoint ip_endpoint; |
| 25 std::string client_token; | 50 std::string client_token; |
| 51 std::string certificate; | |
| 52 std::string certificate_fingerprint; | |
| 53 | |
| 54 // Returns true if the net::IPEndPoint has an unspecified IP, port, or | |
| 55 // transport protocol. | |
| 56 bool is_null() const; | |
| 26 }; | 57 }; |
| 27 | 58 |
| 28 // AssignmentSource provides functionality to find out how a client should | 59 // AssignmentSource provides functionality to find out how a client should |
| 29 // connect to an engine. | 60 // connect to an engine. |
| 30 class BLIMP_CLIENT_EXPORT AssignmentSource { | 61 class BLIMP_CLIENT_EXPORT AssignmentSource : public net::URLFetcherDelegate { |
| 31 public: | 62 public: |
| 32 typedef const base::Callback<void(const Assignment&)> AssignmentCallback; | 63 // A Java counterpart will be generated for this enum. |
| 64 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.blimp.assignment | |
| 65 enum Result { | |
| 66 RESULT_UNKNOWN = 0, | |
| 67 RESULT_OK = 1, | |
| 68 RESULT_BAD_REQUEST = 2, | |
| 69 RESULT_BAD_RESPONSE = 3, | |
| 70 RESULT_INVALID_PROTOCOL_VERSION = 4, | |
| 71 RESULT_EXPIRED_ACCESS_TOKEN = 5, | |
| 72 RESULT_USER_INVALID = 6, | |
| 73 RESULT_OUT_OF_VMS = 7, | |
| 74 RESULT_SERVER_ERROR = 8, | |
| 75 RESULT_SERVER_INTERRUPTED = 9, | |
| 76 RESULT_NETWORK_FAILURE = 10 | |
| 77 }; | |
| 78 | |
| 79 typedef base::Callback<void(AssignmentSource::Result, const Assignment&)> | |
| 80 AssignmentCallback; | |
| 33 | 81 |
| 34 // The |main_task_runner| should be the task runner for the UI thread because | 82 // The |main_task_runner| should be the task runner for the UI thread because |
| 35 // this will in some cases be used to trigger user interaction on the UI | 83 // this will in some cases be used to trigger user interaction on the UI |
| 36 // thread. | 84 // thread. |
| 37 AssignmentSource( | 85 AssignmentSource( |
| 38 const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner); | 86 const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner, |
| 39 virtual ~AssignmentSource(); | 87 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner); |
| 88 ~AssignmentSource() override; | |
| 40 | 89 |
| 41 // Retrieves a valid assignment for the client and posts the result to the | 90 // Retrieves a valid assignment for the client and posts the result to the |
| 42 // given callback. | 91 // given callback. |client_auth_token| is the authentication token to send to |
|
nyquist
2016/02/18 01:58:40
Nit: s/authentication/OAuth2 access/
David Trainor- moved to gerrit
2016/02/18 16:01:54
Done.
| |
| 43 void GetAssignment(const AssignmentCallback& callback); | 92 // the assigner when requesting an assignment. |
| 93 void GetAssignment(const std::string& client_auth_token, | |
|
nyquist
2016/02/18 01:58:40
Optional nit: Should you mention that you're only
David Trainor- moved to gerrit
2016/02/18 16:01:54
Done.
| |
| 94 const AssignmentCallback& callback); | |
| 95 | |
| 96 // net::URLFetcherDelegate implementation: | |
| 97 void OnURLFetchComplete(const net::URLFetcher* source) override; | |
| 44 | 98 |
| 45 private: | 99 private: |
| 100 void ParseAssignerResponse(); | |
| 101 | |
| 46 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; | 102 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; |
| 47 | 103 |
| 104 scoped_refptr<net::URLRequestContextGetter> url_request_context_; | |
| 105 scoped_ptr<net::URLFetcher> url_fetcher_; | |
| 106 | |
| 107 AssignmentCallback callback_; | |
|
nyquist
2016/02/18 01:58:40
Could you add a comment about the lifetime of this
David Trainor- moved to gerrit
2016/02/18 16:01:54
Done.
| |
| 108 | |
| 48 DISALLOW_COPY_AND_ASSIGN(AssignmentSource); | 109 DISALLOW_COPY_AND_ASSIGN(AssignmentSource); |
| 49 }; | 110 }; |
| 50 | 111 |
| 51 } // namespace client | 112 } // namespace client |
| 52 } // namespace blimp | 113 } // namespace blimp |
| 53 | 114 |
| 54 #endif // BLIMP_CLIENT_SESSION_ASSIGNMENT_SOURCE_H_ | 115 #endif // BLIMP_CLIENT_SESSION_ASSIGNMENT_SOURCE_H_ |
| OLD | NEW |