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 // A Java counterpart will be generated for this enum. | |
| 29 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.blimp | |
|
Kevin M
2016/02/12 19:45:27
You can move this enum into AssignmentSource and j
David Trainor- moved to gerrit
2016/02/17 21:09:48
Done. The java classname is a little odd but I ad
| |
| 30 enum AssignmentSourceResult { | |
| 31 ASSIGNMENT_SOURCE_RESULT_UNKNOWN = 0, | |
| 32 ASSIGNMENT_SOURCE_RESULT_OKAY = 1, | |
| 33 ASSIGNMENT_SOURCE_RESULT_BAD_REQUEST = 2, | |
| 34 ASSIGNMENT_SOURCE_RESULT_BAD_RESPONSE = 3, | |
| 35 ASSIGNMENT_SOURCE_RESULT_INVALID_PROTOCOL_VERSION = 4, | |
| 36 ASSIGNMENT_SOURCE_RESULT_EXPIRED_ACCESS_TOKEN = 5, | |
| 37 ASSIGNMENT_SOURCE_RESULT_USER_INVALID = 6, | |
| 38 ASSIGNMENT_SOURCE_RESULT_OUT_OF_VMS = 7, | |
| 39 ASSIGNMENT_SOURCE_RESULT_SERVER_ERROR = 8, | |
| 40 ASSIGNMENT_SOURCE_RESULT_SERVER_INTERRUPTED = 9, | |
| 41 ASSIGNMENT_SOURCE_RESULT_NETWORK_FAILURE = 10 | |
| 42 }; | |
| 43 | |
| 21 // An Assignment contains the configuration data needed for a client | 44 // An Assignment contains the configuration data needed for a client |
| 22 // to connect to the engine. | 45 // to connect to the engine. |
| 23 struct BLIMP_CLIENT_EXPORT Assignment { | 46 struct BLIMP_CLIENT_EXPORT Assignment { |
| 24 net::IPEndPoint ip_endpoint; | 47 net::IPEndPoint ip_endpoint; |
| 25 std::string client_token; | 48 std::string client_token; |
| 49 std::string certificate; | |
| 50 std::string certificate_fingerprint; | |
| 26 }; | 51 }; |
| 27 | 52 |
| 28 // AssignmentSource provides functionality to find out how a client should | 53 // AssignmentSource provides functionality to find out how a client should |
| 29 // connect to an engine. | 54 // connect to an engine. |
| 30 class BLIMP_CLIENT_EXPORT AssignmentSource { | 55 class BLIMP_CLIENT_EXPORT AssignmentSource : public net::URLFetcherDelegate { |
| 31 public: | 56 public: |
| 32 typedef const base::Callback<void(const Assignment&)> AssignmentCallback; | 57 typedef const base::Callback<void(AssignmentSourceResult, const Assignment&)> |
| 58 AssignmentCallback; | |
| 33 | 59 |
| 34 // The |main_task_runner| should be the task runner for the UI thread because | 60 // 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 | 61 // this will in some cases be used to trigger user interaction on the UI |
| 36 // thread. | 62 // thread. |
| 37 AssignmentSource( | 63 AssignmentSource( |
| 38 const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner); | 64 const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner, |
| 65 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner); | |
| 39 virtual ~AssignmentSource(); | 66 virtual ~AssignmentSource(); |
| 40 | 67 |
| 41 // Retrieves a valid assignment for the client and posts the result to the | 68 // Retrieves a valid assignment for the client and posts the result to the |
| 42 // given callback. | 69 // given callback. |token| is the authentication token to send to the |
| 43 void GetAssignment(const AssignmentCallback& callback); | 70 // assigner when requesting an assignment. |
| 71 void GetAssignment(const std::string& token, | |
| 72 const AssignmentCallback& callback); | |
| 73 | |
| 74 // net::URLFetcherDelegate implementation: | |
| 75 void OnURLFetchComplete(const net::URLFetcher* source) override; | |
| 44 | 76 |
| 45 private: | 77 private: |
| 78 void RespondWithAssignment(const Assignment& assignment); | |
| 79 void RespondWithError(AssignmentSourceResult result); | |
| 80 | |
| 46 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; | 81 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; |
| 47 | 82 |
| 83 scoped_refptr<net::URLRequestContextGetter> url_request_context_; | |
| 84 scoped_ptr<net::URLFetcher> url_fetcher_; | |
| 85 | |
| 86 scoped_ptr<AssignmentCallback> callback_; | |
|
Kevin M
2016/02/12 19:45:27
No need to put it in a scoped ptr
David Trainor- moved to gerrit
2016/02/17 21:09:48
Done.
| |
| 87 | |
| 48 DISALLOW_COPY_AND_ASSIGN(AssignmentSource); | 88 DISALLOW_COPY_AND_ASSIGN(AssignmentSource); |
| 49 }; | 89 }; |
| 50 | 90 |
| 51 } // namespace client | 91 } // namespace client |
| 52 } // namespace blimp | 92 } // namespace blimp |
| 53 | 93 |
| 54 #endif // BLIMP_CLIENT_SESSION_ASSIGNMENT_SOURCE_H_ | 94 #endif // BLIMP_CLIENT_SESSION_ASSIGNMENT_SOURCE_H_ |
| OLD | NEW |