Chromium Code Reviews| Index: blimp/client/session/assignment_source.h |
| diff --git a/blimp/client/session/assignment_source.h b/blimp/client/session/assignment_source.h |
| index 9891d4a2d49c0d91cf1ffecfc4f2966bb9fd75ac..a7e7c89f66afa5cd7ac9db98dc82f89904f20f42 100644 |
| --- a/blimp/client/session/assignment_source.h |
| +++ b/blimp/client/session/assignment_source.h |
| @@ -10,41 +10,102 @@ |
| #include "base/callback.h" |
| #include "blimp/client/blimp_client_export.h" |
| #include "net/base/ip_endpoint.h" |
| +#include "net/url_request/url_fetcher.h" |
| +#include "net/url_request/url_fetcher_delegate.h" |
| namespace base { |
| class SingleThreadTaskRunner; |
| } |
| +namespace net { |
| +class URLFetcher; |
| +class URLRequestContextGetter; |
| +} |
| + |
| namespace blimp { |
| namespace client { |
| +// TODO(kmarshall): Take values from configuration data. |
| +const char kDummyClientToken[] = "MyVoiceIsMyPassport"; |
| + |
| +// Potential assigner URLs. |
| +const char kDefaultAssignerURL[] = |
| + "https://blimp-pa.googleapis.com/v1/assignment"; |
| + |
| // An Assignment contains the configuration data needed for a client |
| // to connect to the engine. |
| struct BLIMP_CLIENT_EXPORT Assignment { |
| + enum TransportProtocol { |
| + UNKNOWN = 0, |
| + SSL = 1, |
| + TCP = 2, |
| + QUIC = 3, |
| + }; |
| + |
| + Assignment(); |
| + ~Assignment(); |
| + |
| + TransportProtocol transport_protocol; |
| net::IPEndPoint ip_endpoint; |
| std::string client_token; |
| + std::string certificate; |
| + std::string certificate_fingerprint; |
| + |
| + // Returns true if the net::IPEndPoint has an unspecified IP, port, or |
| + // transport protocol. |
| + bool is_null() const; |
| }; |
| // AssignmentSource provides functionality to find out how a client should |
| // connect to an engine. |
| -class BLIMP_CLIENT_EXPORT AssignmentSource { |
| +class BLIMP_CLIENT_EXPORT AssignmentSource : public net::URLFetcherDelegate { |
| public: |
| - typedef const base::Callback<void(const Assignment&)> AssignmentCallback; |
| + // A Java counterpart will be generated for this enum. |
| + // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.blimp.assignment |
| + enum Result { |
| + RESULT_UNKNOWN = 0, |
| + RESULT_OK = 1, |
| + RESULT_BAD_REQUEST = 2, |
| + RESULT_BAD_RESPONSE = 3, |
| + RESULT_INVALID_PROTOCOL_VERSION = 4, |
| + RESULT_EXPIRED_ACCESS_TOKEN = 5, |
| + RESULT_USER_INVALID = 6, |
| + RESULT_OUT_OF_VMS = 7, |
| + RESULT_SERVER_ERROR = 8, |
| + RESULT_SERVER_INTERRUPTED = 9, |
| + RESULT_NETWORK_FAILURE = 10 |
| + }; |
| + |
| + typedef base::Callback<void(AssignmentSource::Result, const Assignment&)> |
| + AssignmentCallback; |
| // The |main_task_runner| should be the task runner for the UI thread because |
| // this will in some cases be used to trigger user interaction on the UI |
| // thread. |
| AssignmentSource( |
| - const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner); |
| - virtual ~AssignmentSource(); |
| + const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner, |
| + const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner); |
| + ~AssignmentSource() override; |
| // Retrieves a valid assignment for the client and posts the result to the |
| - // given callback. |
| - void GetAssignment(const AssignmentCallback& callback); |
| + // given callback. |client_auth_token| is the authentication token to send to |
|
nyquist
2016/02/18 01:58:40
Nit: s/authentication/OAuth2 access/
David Trainor- moved to gerrit
2016/02/18 16:01:54
Done.
|
| + // the assigner when requesting an assignment. |
| + void GetAssignment(const std::string& client_auth_token, |
|
nyquist
2016/02/18 01:58:40
Optional nit: Should you mention that you're only
David Trainor- moved to gerrit
2016/02/18 16:01:54
Done.
|
| + const AssignmentCallback& callback); |
| + |
| + // net::URLFetcherDelegate implementation: |
| + void OnURLFetchComplete(const net::URLFetcher* source) override; |
| private: |
| + void ParseAssignerResponse(); |
| + |
| scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; |
| + scoped_refptr<net::URLRequestContextGetter> url_request_context_; |
| + scoped_ptr<net::URLFetcher> url_fetcher_; |
| + |
| + AssignmentCallback callback_; |
|
nyquist
2016/02/18 01:58:40
Could you add a comment about the lifetime of this
David Trainor- moved to gerrit
2016/02/18 16:01:54
Done.
|
| + |
| DISALLOW_COPY_AND_ASSIGN(AssignmentSource); |
| }; |