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 Assignment(); |
| 39 ~Assignment(); |
| 40 |
24 net::IPEndPoint ip_endpoint; | 41 net::IPEndPoint ip_endpoint; |
25 std::string client_token; | 42 std::string client_token; |
| 43 std::string certificate; |
| 44 std::string certificate_fingerprint; |
| 45 |
| 46 // Returns true if the net::IPEndPoint has an unspecified IP and port. |
| 47 bool is_null() const; |
26 }; | 48 }; |
27 | 49 |
28 // AssignmentSource provides functionality to find out how a client should | 50 // AssignmentSource provides functionality to find out how a client should |
29 // connect to an engine. | 51 // connect to an engine. |
30 class BLIMP_CLIENT_EXPORT AssignmentSource { | 52 class BLIMP_CLIENT_EXPORT AssignmentSource : public net::URLFetcherDelegate { |
31 public: | 53 public: |
32 typedef const base::Callback<void(const Assignment&)> AssignmentCallback; | 54 // A Java counterpart will be generated for this enum. |
| 55 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.blimp.assignment |
| 56 enum Result { |
| 57 RESULT_UNKNOWN = 0, |
| 58 RESULT_OK = 1, |
| 59 RESULT_BAD_REQUEST = 2, |
| 60 RESULT_BAD_RESPONSE = 3, |
| 61 RESULT_INVALID_PROTOCOL_VERSION = 4, |
| 62 RESULT_EXPIRED_ACCESS_TOKEN = 5, |
| 63 RESULT_USER_INVALID = 6, |
| 64 RESULT_OUT_OF_VMS = 7, |
| 65 RESULT_SERVER_ERROR = 8, |
| 66 RESULT_SERVER_INTERRUPTED = 9, |
| 67 RESULT_NETWORK_FAILURE = 10 |
| 68 }; |
| 69 |
| 70 typedef base::Callback<void(AssignmentSource::Result, const Assignment&)> |
| 71 AssignmentCallback; |
33 | 72 |
34 // The |main_task_runner| should be the task runner for the UI thread because | 73 // 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 | 74 // this will in some cases be used to trigger user interaction on the UI |
36 // thread. | 75 // thread. |
37 AssignmentSource( | 76 AssignmentSource( |
38 const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner); | 77 const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner, |
39 virtual ~AssignmentSource(); | 78 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner); |
| 79 ~AssignmentSource() override; |
40 | 80 |
41 // Retrieves a valid assignment for the client and posts the result to the | 81 // Retrieves a valid assignment for the client and posts the result to the |
42 // given callback. | 82 // given callback. |client_auth_token| is the authentication token to send to |
43 void GetAssignment(const AssignmentCallback& callback); | 83 // the assigner when requesting an assignment. |
| 84 void GetAssignment(const std::string& client_auth_token, |
| 85 const AssignmentCallback& callback); |
| 86 |
| 87 // net::URLFetcherDelegate implementation: |
| 88 void OnURLFetchComplete(const net::URLFetcher* source) override; |
44 | 89 |
45 private: | 90 private: |
| 91 void ParseAssignerResponse(); |
| 92 |
46 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; | 93 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; |
47 | 94 |
| 95 scoped_refptr<net::URLRequestContextGetter> url_request_context_; |
| 96 scoped_ptr<net::URLFetcher> url_fetcher_; |
| 97 |
| 98 AssignmentCallback callback_; |
| 99 |
48 DISALLOW_COPY_AND_ASSIGN(AssignmentSource); | 100 DISALLOW_COPY_AND_ASSIGN(AssignmentSource); |
49 }; | 101 }; |
50 | 102 |
51 } // namespace client | 103 } // namespace client |
52 } // namespace blimp | 104 } // namespace blimp |
53 | 105 |
54 #endif // BLIMP_CLIENT_SESSION_ASSIGNMENT_SOURCE_H_ | 106 #endif // BLIMP_CLIENT_SESSION_ASSIGNMENT_SOURCE_H_ |
OLD | NEW |