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

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

Issue 1687393002: Add assigner support to Blimp (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix evil build break? Created 4 years, 10 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
« no previous file with comments | « blimp/client/app/linux/blimp_main.cc ('k') | blimp/client/session/assignment_source.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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_delegate.h"
13 14
14 namespace base { 15 namespace base {
15 class SingleThreadTaskRunner; 16 class SingleThreadTaskRunner;
16 } 17 }
17 18
19 namespace net {
20 class URLFetcher;
21 class URLRequestContextGetter;
22 }
23
18 namespace blimp { 24 namespace blimp {
19 namespace client { 25 namespace client {
20 26
27 // TODO(kmarshall): Take values from configuration data.
28 const char kDummyClientToken[] = "MyVoiceIsMyPassport";
29
30 // Potential assigner URLs.
31 const char kDefaultAssignerURL[] =
32 "https://blimp-pa.googleapis.com/v1/assignment";
33
21 // An Assignment contains the configuration data needed for a client 34 // An Assignment contains the configuration data needed for a client
22 // to connect to the engine. 35 // to connect to the engine.
23 struct BLIMP_CLIENT_EXPORT Assignment { 36 struct BLIMP_CLIENT_EXPORT Assignment {
37 enum TransportProtocol {
38 UNKNOWN = 0,
39 SSL = 1,
40 TCP = 2,
41 QUIC = 3,
42 };
43
44 Assignment();
45 ~Assignment();
46
47 TransportProtocol transport_protocol;
24 net::IPEndPoint ip_endpoint; 48 net::IPEndPoint ip_endpoint;
25 std::string client_token; 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
54 // transport protocol.
55 bool is_null() const;
26 }; 56 };
27 57
28 // AssignmentSource provides functionality to find out how a client should 58 // AssignmentSource provides functionality to find out how a client should
29 // connect to an engine. 59 // connect to an engine.
30 class BLIMP_CLIENT_EXPORT AssignmentSource { 60 class BLIMP_CLIENT_EXPORT AssignmentSource : public net::URLFetcherDelegate {
31 public: 61 public:
32 typedef const base::Callback<void(const Assignment&)> AssignmentCallback; 62 // A Java counterpart will be generated for this enum.
63 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.blimp.assignment
64 enum Result {
65 RESULT_UNKNOWN = 0,
66 RESULT_OK = 1,
67 RESULT_BAD_REQUEST = 2,
68 RESULT_BAD_RESPONSE = 3,
69 RESULT_INVALID_PROTOCOL_VERSION = 4,
70 RESULT_EXPIRED_ACCESS_TOKEN = 5,
71 RESULT_USER_INVALID = 6,
72 RESULT_OUT_OF_VMS = 7,
73 RESULT_SERVER_ERROR = 8,
74 RESULT_SERVER_INTERRUPTED = 9,
75 RESULT_NETWORK_FAILURE = 10
76 };
77
78 typedef base::Callback<void(AssignmentSource::Result, const Assignment&)>
79 AssignmentCallback;
33 80
34 // The |main_task_runner| should be the task runner for the UI thread because 81 // 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 82 // this will in some cases be used to trigger user interaction on the UI
36 // thread. 83 // thread.
37 AssignmentSource( 84 AssignmentSource(
38 const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner); 85 const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner,
39 virtual ~AssignmentSource(); 86 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner);
87 ~AssignmentSource() override;
40 88
41 // Retrieves a valid assignment for the client and posts the result to the 89 // Retrieves a valid assignment for the client and posts the result to the
42 // given callback. 90 // given callback. |client_auth_token| is the OAuth2 access token to send to
43 void GetAssignment(const AssignmentCallback& callback); 91 // the assigner when requesting an assignment. If this is called before a
92 // previous call has completed, the old callback will be called with
93 // RESULT_SERVER_INTERRUPTED and no Assignment.
94 void GetAssignment(const std::string& client_auth_token,
95 const AssignmentCallback& callback);
96
97 // net::URLFetcherDelegate implementation:
98 void OnURLFetchComplete(const net::URLFetcher* source) override;
44 99
45 private: 100 private:
101 void ParseAssignerResponse();
102
46 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; 103 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_;
47 104
105 scoped_refptr<net::URLRequestContextGetter> url_request_context_;
106 scoped_ptr<net::URLFetcher> url_fetcher_;
107
108 // 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).
110 AssignmentCallback callback_;
111
48 DISALLOW_COPY_AND_ASSIGN(AssignmentSource); 112 DISALLOW_COPY_AND_ASSIGN(AssignmentSource);
49 }; 113 };
50 114
51 } // namespace client 115 } // namespace client
52 } // namespace blimp 116 } // namespace blimp
53 117
54 #endif // BLIMP_CLIENT_SESSION_ASSIGNMENT_SOURCE_H_ 118 #endif // BLIMP_CLIENT_SESSION_ASSIGNMENT_SOURCE_H_
OLDNEW
« no previous file with comments | « blimp/client/app/linux/blimp_main.cc ('k') | blimp/client/session/assignment_source.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698