Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(569)

Side by Side Diff: blimp/client/session/assignment_source.h

Issue 1696563002: Blimp: add support for SSL connections. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: wez/bauerb feedback Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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,
42 }; 45 };
43 46
44 Assignment(); 47 Assignment();
45 ~Assignment(); 48 ~Assignment();
46 49
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 50 // Returns true if the net::IPEndPoint has an unspecified IP, port, or
54 // transport protocol. 51 // transport protocol.
55 bool is_null() const; 52 bool IsValid() const;
53
54 // Specifies the transport to use to connect to the engine.
55 TransportProtocol transport_protocol;
56
57 // Specifies the IP address and port on which to reach the engine.
58 net::IPEndPoint engine_endpoint;
59
60 // Used to authenticate to the specified engine.
61 std::string client_token;
62
63 // Specifies the X.509 certificate that the engine must report.
64 scoped_refptr<net::X509Certificate> cert;
56 }; 65 };
57 66
58 // AssignmentSource provides functionality to find out how a client should 67 // AssignmentSource provides functionality to find out how a client should
59 // connect to an engine. 68 // connect to an engine.
60 class BLIMP_CLIENT_EXPORT AssignmentSource : public net::URLFetcherDelegate { 69 class BLIMP_CLIENT_EXPORT AssignmentSource : public net::URLFetcherDelegate {
61 public: 70 public:
62 // A Java counterpart will be generated for this enum. 71 // A Java counterpart will be generated for this enum.
63 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.blimp.assignment 72 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.blimp.assignment
64 enum Result { 73 enum Result {
65 RESULT_UNKNOWN = 0, 74 RESULT_UNKNOWN = 0,
66 RESULT_OK = 1, 75 RESULT_OK = 1,
67 RESULT_BAD_REQUEST = 2, 76 RESULT_BAD_REQUEST = 2,
68 RESULT_BAD_RESPONSE = 3, 77 RESULT_BAD_RESPONSE = 3,
69 RESULT_INVALID_PROTOCOL_VERSION = 4, 78 RESULT_INVALID_PROTOCOL_VERSION = 4,
70 RESULT_EXPIRED_ACCESS_TOKEN = 5, 79 RESULT_EXPIRED_ACCESS_TOKEN = 5,
71 RESULT_USER_INVALID = 6, 80 RESULT_USER_INVALID = 6,
72 RESULT_OUT_OF_VMS = 7, 81 RESULT_OUT_OF_VMS = 7,
73 RESULT_SERVER_ERROR = 8, 82 RESULT_SERVER_ERROR = 8,
74 RESULT_SERVER_INTERRUPTED = 9, 83 RESULT_SERVER_INTERRUPTED = 9,
75 RESULT_NETWORK_FAILURE = 10 84 RESULT_NETWORK_FAILURE = 10,
85 RESULT_INVALID_CERT = 11,
76 }; 86 };
77 87
78 typedef base::Callback<void(AssignmentSource::Result, const Assignment&)> 88 typedef base::Callback<void(AssignmentSource::Result, const Assignment&)>
79 AssignmentCallback; 89 AssignmentCallback;
80 90
81 // The |main_task_runner| should be the task runner for the UI thread because 91 // |network_task_runner|: The task runner to use for querying the Assigner API
82 // this will in some cases be used to trigger user interaction on the UI 92 // over the network.
83 // thread. 93 // |file_task_runner|: The task runner to use for reading cert files from disk
94 // (specified on the command line.)
84 AssignmentSource( 95 AssignmentSource(
85 const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner, 96 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner,
86 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner); 97 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner);
Wez 2016/03/01 00:23:56 nit: Any reason not to pass these const&?
Kevin M 2016/03/01 18:23:17 Done.
98
87 ~AssignmentSource() override; 99 ~AssignmentSource() override;
88 100
89 // Retrieves a valid assignment for the client and posts the result to the 101 // 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 102 // 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 103 // the assigner when requesting an assignment. If this is called before a
92 // previous call has completed, the old callback will be called with 104 // previous call has completed, the old callback will be called with
93 // RESULT_SERVER_INTERRUPTED and no Assignment. 105 // RESULT_SERVER_INTERRUPTED and no Assignment.
94 void GetAssignment(const std::string& client_auth_token, 106 void GetAssignment(const std::string& client_auth_token,
95 const AssignmentCallback& callback); 107 const AssignmentCallback& callback);
96 108
97 // net::URLFetcherDelegate implementation: 109 // net::URLFetcherDelegate implementation:
98 void OnURLFetchComplete(const net::URLFetcher* source) override; 110 void OnURLFetchComplete(const net::URLFetcher* source) override;
Wez 2016/03/01 00:23:56 nit: Looks like this is also an implementation det
Kevin M 2016/03/01 18:23:17 Done.
Kevin M 2016/03/01 18:23:17 Done.
99 111
100 private: 112 private:
113 void OnGetAssignmentFromCommandLineDone(const std::string& client_auth_token,
114 Assignment parsed_assignment);
101 void ParseAssignerResponse(); 115 void ParseAssignerResponse();
116 void OnJSONParsed(scoped_ptr<base::Value> json);
117 void OnJSONParseError(const std::string& error);
Wez 2016/03/01 00:23:56 nit: Prefer to capitalize acronyms as single words
Kevin M 2016/03/01 18:23:17 Done.
102 118
103 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; 119 // GetAssignment() callback, invoked after URLFetcher completion.
120 AssignmentCallback callback_;
104 121
122 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_;
105 scoped_refptr<net::URLRequestContextGetter> url_request_context_; 123 scoped_refptr<net::URLRequestContextGetter> url_request_context_;
106 scoped_ptr<net::URLFetcher> url_fetcher_; 124 scoped_ptr<net::URLFetcher> url_fetcher_;
107 125
108 // This callback is set during a call to GetAssignment() and is cleared after 126 base::WeakPtrFactory<AssignmentSource> weak_factory_;
109 // the request has completed (whether it be a success or failure).
110 AssignmentCallback callback_;
111 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_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698