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 "base/memory/weak_ptr.h" | |
11 #include "blimp/client/blimp_client_export.h" | 12 #include "blimp/client/blimp_client_export.h" |
12 #include "net/base/ip_endpoint.h" | 13 #include "net/base/ip_endpoint.h" |
13 #include "net/url_request/url_fetcher_delegate.h" | 14 #include "net/url_request/url_fetcher_delegate.h" |
14 | 15 |
15 namespace base { | 16 namespace base { |
17 class FilePath; | |
16 class SingleThreadTaskRunner; | 18 class SingleThreadTaskRunner; |
19 class Value; | |
17 } | 20 } |
18 | 21 |
19 namespace net { | 22 namespace net { |
20 class URLFetcher; | 23 class URLFetcher; |
21 class URLRequestContextGetter; | 24 class URLRequestContextGetter; |
25 class X509Certificate; | |
22 } | 26 } |
23 | 27 |
24 namespace blimp { | 28 namespace blimp { |
25 namespace client { | 29 namespace client { |
26 | 30 |
27 // TODO(kmarshall): Take values from configuration data. | 31 // TODO(kmarshall): Take values from configuration data. |
28 const char kDummyClientToken[] = "MyVoiceIsMyPassport"; | 32 const char kDummyClientToken[] = "MyVoiceIsMyPassport"; |
29 | 33 |
30 // Potential assigner URLs. | 34 // Potential assigner URLs. |
31 const char kDefaultAssignerURL[] = | 35 const char kDefaultAssignerURL[] = |
32 "https://blimp-pa.googleapis.com/v1/assignment"; | 36 "https://blimp-pa.googleapis.com/v1/assignment"; |
33 | 37 |
34 // An Assignment contains the configuration data needed for a client | 38 // An Assignment contains the configuration data needed for a client |
35 // to connect to the engine. | 39 // to connect to the engine. |
36 struct BLIMP_CLIENT_EXPORT Assignment { | 40 struct BLIMP_CLIENT_EXPORT Assignment { |
37 enum TransportProtocol { | 41 enum TransportProtocol { |
38 UNKNOWN = 0, | 42 UNKNOWN = 0, |
39 SSL = 1, | 43 SSL = 1, |
40 TCP = 2, | 44 TCP = 2, |
41 QUIC = 3, | 45 QUIC = 3, |
Wez
2016/02/26 18:32:09
We don't have a QUIC transport, so let's remove th
Kevin M
2016/02/26 19:57:23
Done.
| |
42 }; | 46 }; |
43 | 47 |
44 Assignment(); | 48 Assignment(); |
45 ~Assignment(); | 49 ~Assignment(); |
46 | 50 |
47 TransportProtocol transport_protocol; | |
48 net::IPEndPoint ip_endpoint; | |
49 std::string client_token; | |
50 std::string certificate; | |
51 std::string certificate_fingerprint; | |
52 | |
53 // Returns true if the net::IPEndPoint has an unspecified IP, port, or | 51 // Returns true if the net::IPEndPoint has an unspecified IP, port, or |
54 // transport protocol. | 52 // transport protocol. |
55 bool is_null() const; | 53 bool is_null() const; |
Ryan Sleevi
2016/02/25 22:16:25
DESIGN NIT: I would have suggested this be called
Wez
2016/02/26 18:32:09
nit: is_valid() seems a more appropriate name for
Kevin M
2016/02/26 19:57:23
Done.
| |
54 | |
55 // The transport protocol used to contact the engine. | |
Wez
2016/02/26 18:32:09
nit: This is a somewhat tautologous and ambiguous
Kevin M
2016/02/26 19:57:23
Done.
| |
56 TransportProtocol transport_protocol; | |
57 | |
58 // The IP address of the engine. | |
Wez
2016/02/26 18:32:09
nit: This comment also seems tautologous, especial
Kevin M
2016/02/26 19:57:23
Done.
| |
59 net::IPEndPoint ip_endpoint; | |
60 | |
61 // The token used to authenticate the client to the engine. | |
Wez
2016/02/26 18:32:09
Suggest simply: Used to authenticate to the specif
Kevin M
2016/02/26 19:57:23
Done.
| |
62 std::string client_token; | |
Wez
2016/02/26 18:32:09
Also suggest renaming this to auth_token.
Kevin M
2016/02/26 19:57:23
That would make this inconsistent with the Assigne
Wez
2016/03/01 00:23:55
Yes, but we're already inconsistent with the names
Kevin M
2016/03/01 18:23:16
It's not just the Assigner response; "client_token
| |
63 | |
64 // The expected certificate of the engine. The peer certificate must match | |
65 // |cert| exactly, otherwise the connection will be dropped. | |
Wez
2016/02/26 18:32:09
The suggestions I've given above switch the sense
Kevin M
2016/02/26 19:57:23
Done.
| |
66 scoped_refptr<net::X509Certificate> cert; | |
56 }; | 67 }; |
57 | 68 |
58 // AssignmentSource provides functionality to find out how a client should | 69 // AssignmentSource provides functionality to find out how a client should |
59 // connect to an engine. | 70 // connect to an engine. |
60 class BLIMP_CLIENT_EXPORT AssignmentSource : public net::URLFetcherDelegate { | 71 class BLIMP_CLIENT_EXPORT AssignmentSource : public net::URLFetcherDelegate { |
61 public: | 72 public: |
62 // A Java counterpart will be generated for this enum. | 73 // A Java counterpart will be generated for this enum. |
63 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.blimp.assignment | 74 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.blimp.assignment |
64 enum Result { | 75 enum Result { |
65 RESULT_UNKNOWN = 0, | 76 RESULT_UNKNOWN = 0, |
66 RESULT_OK = 1, | 77 RESULT_OK = 1, |
67 RESULT_BAD_REQUEST = 2, | 78 RESULT_BAD_REQUEST = 2, |
68 RESULT_BAD_RESPONSE = 3, | 79 RESULT_BAD_RESPONSE = 3, |
69 RESULT_INVALID_PROTOCOL_VERSION = 4, | 80 RESULT_INVALID_PROTOCOL_VERSION = 4, |
70 RESULT_EXPIRED_ACCESS_TOKEN = 5, | 81 RESULT_EXPIRED_ACCESS_TOKEN = 5, |
71 RESULT_USER_INVALID = 6, | 82 RESULT_USER_INVALID = 6, |
72 RESULT_OUT_OF_VMS = 7, | 83 RESULT_OUT_OF_VMS = 7, |
73 RESULT_SERVER_ERROR = 8, | 84 RESULT_SERVER_ERROR = 8, |
74 RESULT_SERVER_INTERRUPTED = 9, | 85 RESULT_SERVER_INTERRUPTED = 9, |
75 RESULT_NETWORK_FAILURE = 10 | 86 RESULT_NETWORK_FAILURE = 10, |
87 RESULT_INVALID_CERT = 11, | |
76 }; | 88 }; |
77 | 89 |
78 typedef base::Callback<void(AssignmentSource::Result, const Assignment&)> | 90 typedef base::Callback<void(AssignmentSource::Result, const Assignment&)> |
79 AssignmentCallback; | 91 AssignmentCallback; |
80 | 92 |
81 // The |main_task_runner| should be the task runner for the UI thread because | 93 explicit AssignmentSource( |
82 // this will in some cases be used to trigger user interaction on the UI | 94 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner); |
Wez
2016/02/26 18:32:09
nit: Document why the |io_task_runner| is needed,
Kevin M
2016/02/26 19:57:23
Done.
| |
83 // thread. | |
84 AssignmentSource( | |
85 const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner, | |
86 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner); | |
87 ~AssignmentSource() override; | 95 ~AssignmentSource() override; |
88 | 96 |
89 // Retrieves a valid assignment for the client and posts the result to the | 97 // Retrieves a valid assignment for the client and posts the result to the |
90 // given callback. |client_auth_token| is the OAuth2 access token to send to | 98 // given callback. |client_auth_token| is the OAuth2 access token to send to |
91 // the assigner when requesting an assignment. If this is called before a | 99 // the assigner when requesting an assignment. If this is called before a |
92 // previous call has completed, the old callback will be called with | 100 // previous call has completed, the old callback will be called with |
93 // RESULT_SERVER_INTERRUPTED and no Assignment. | 101 // RESULT_SERVER_INTERRUPTED and no Assignment. |
94 void GetAssignment(const std::string& client_auth_token, | 102 void GetAssignment(const std::string& client_auth_token, |
95 const AssignmentCallback& callback); | 103 const AssignmentCallback& callback); |
96 | 104 |
105 // Called when GetCustomAssignment() has completed. | |
Wez
2016/02/26 18:32:09
GetCustomAssignment() isn't declared here, so it d
Kevin M
2016/02/26 19:57:23
Doesn't need to be public. "custom assignment" mea
| |
106 // Uses |custom_assignment| if provided; queries the Assigner for one | |
107 // otherwise. | |
108 void OnGetCustomAssignmentDone(const std::string& client_auth_token, | |
109 Assignment custom_assignment); | |
110 | |
97 // net::URLFetcherDelegate implementation: | 111 // net::URLFetcherDelegate implementation: |
98 void OnURLFetchComplete(const net::URLFetcher* source) override; | 112 void OnURLFetchComplete(const net::URLFetcher* source) override; |
99 | 113 |
100 private: | 114 private: |
101 void ParseAssignerResponse(); | 115 void ParseAssignerResponse(); |
102 | 116 void AssignerJSONParseOK(scoped_ptr<base::Value> json); |
103 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; | 117 void AssignerJSONParseError(const std::string& error); |
Wez
2016/02/26 18:32:09
These names don't scan - do you mean OnJsonParsed(
| |
104 | |
105 scoped_refptr<net::URLRequestContextGetter> url_request_context_; | |
106 scoped_ptr<net::URLFetcher> url_fetcher_; | |
107 | 118 |
108 // This callback is set during a call to GetAssignment() and is cleared after | 119 // This callback is set during a call to GetAssignment() and is cleared after |
109 // the request has completed (whether it be a success or failure). | 120 // the request has completed (whether it be a success or failure). |
Wez
2016/02/26 18:32:09
nit: (And I realise this was already here) This co
Kevin M
2016/02/26 19:57:23
Mostly because URLFetcher takes a delegate object
| |
110 AssignmentCallback callback_; | 121 AssignmentCallback callback_; |
111 | 122 |
123 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; | |
124 scoped_refptr<net::URLRequestContextGetter> url_request_context_; | |
125 scoped_ptr<net::URLFetcher> url_fetcher_; | |
126 base::WeakPtrFactory<AssignmentSource> weak_factory_; | |
Wez
2016/02/26 18:32:09
nit: Suggest separating the weak_factory_ from the
Kevin M
2016/02/26 19:57:23
Done.
| |
127 | |
112 DISALLOW_COPY_AND_ASSIGN(AssignmentSource); | 128 DISALLOW_COPY_AND_ASSIGN(AssignmentSource); |
113 }; | 129 }; |
114 | 130 |
115 } // namespace client | 131 } // namespace client |
116 } // namespace blimp | 132 } // namespace blimp |
117 | 133 |
118 #endif // BLIMP_CLIENT_SESSION_ASSIGNMENT_SOURCE_H_ | 134 #endif // BLIMP_CLIENT_SESSION_ASSIGNMENT_SOURCE_H_ |
OLD | NEW |