| 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_CORE_BLIMP_CLIENT_CONTEXT_IMPL_H_ | 5 #ifndef BLIMP_CLIENT_CORE_BLIMP_CLIENT_CONTEXT_IMPL_H_ |
| 6 #define BLIMP_CLIENT_CORE_BLIMP_CLIENT_CONTEXT_IMPL_H_ | 6 #define BLIMP_CLIENT_CORE_BLIMP_CLIENT_CONTEXT_IMPL_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
| 14 #include "base/threading/thread.h" | 14 #include "base/threading/thread.h" |
| 15 #include "blimp/client/core/session/client_network_components.h" | 15 #include "blimp/client/core/session/client_network_components.h" |
| 16 #include "blimp/client/core/session/identity_source.h" |
| 16 #include "blimp/client/core/session/network_event_observer.h" | 17 #include "blimp/client/core/session/network_event_observer.h" |
| 17 #include "blimp/client/public/blimp_client_context.h" | 18 #include "blimp/client/public/blimp_client_context.h" |
| 18 #include "blimp/client/public/contents/blimp_contents.h" | 19 #include "blimp/client/public/contents/blimp_contents.h" |
| 19 #include "blimp/client/public/session/assignment.h" | 20 #include "blimp/client/public/session/assignment.h" |
| 20 #include "blimp/net/thread_pipe_manager.h" | 21 #include "blimp/net/thread_pipe_manager.h" |
| 21 #include "url/gurl.h" | 22 #include "url/gurl.h" |
| 22 | 23 |
| 23 namespace blimp { | 24 namespace blimp { |
| 24 namespace client { | 25 namespace client { |
| 25 | 26 |
| 26 class BlimpContentsManager; | 27 class BlimpContentsManager; |
| 27 | 28 |
| 28 // BlimpClientContextImpl is the implementation of the main context-class for | 29 // BlimpClientContextImpl is the implementation of the main context-class for |
| 29 // the blimp client. | 30 // the blimp client. |
| 30 class BlimpClientContextImpl : public BlimpClientContext, | 31 class BlimpClientContextImpl : public BlimpClientContext, |
| 31 public NetworkEventObserver { | 32 public NetworkEventObserver { |
| 32 public: | 33 public: |
| 33 // The |io_thread_task_runner| must be the task runner to use for IO | 34 // The |io_thread_task_runner| must be the task runner to use for IO |
| 34 // operations. | 35 // operations. |
| 35 // The |file_thread_task_runner| must be the task runner to use for file | 36 // The |file_thread_task_runner| must be the task runner to use for file |
| 36 // operations. | 37 // operations. |
| 37 BlimpClientContextImpl( | 38 BlimpClientContextImpl( |
| 38 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner, | 39 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner, |
| 39 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner); | 40 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner); |
| 40 ~BlimpClientContextImpl() override; | 41 ~BlimpClientContextImpl() override; |
| 41 | 42 |
| 42 // BlimpClientContext implementation. | 43 // BlimpClientContext implementation. |
| 43 void SetDelegate(BlimpClientContextDelegate* delegate) override; | 44 void SetDelegate(BlimpClientContextDelegate* delegate) override; |
| 44 std::unique_ptr<BlimpContents> CreateBlimpContents() override; | 45 std::unique_ptr<BlimpContents> CreateBlimpContents() override; |
| 45 void Connect(const std::string& client_auth_token) override; | 46 void Connect() override; |
| 46 | 47 |
| 47 // NetworkEventObserver implementation. | 48 // NetworkEventObserver implementation. |
| 48 void OnConnected() override; | 49 void OnConnected() override; |
| 49 void OnDisconnected(int result) override; | 50 void OnDisconnected(int result) override; |
| 50 | 51 |
| 51 protected: | 52 protected: |
| 52 // Returns the URL to use for connections to the assigner. Used to construct | 53 // Returns the URL to use for connections to the assigner. Used to construct |
| 53 // the AssignmentSource. | 54 // the AssignmentSource. |
| 54 virtual GURL GetAssignerURL(); | 55 virtual GURL GetAssignerURL(); |
| 55 | 56 |
| 56 private: | 57 private: |
| 58 // Connect to assignment source with OAuth2 token to get an assignment. |
| 59 virtual void ConnectToAssignmentSource(const std::string& client_auth_token); |
| 60 |
| 57 // The AssignmentCallback for when an assignment is ready. This will trigger | 61 // The AssignmentCallback for when an assignment is ready. This will trigger |
| 58 // a connection to the engine. | 62 // a connection to the engine. |
| 59 virtual void ConnectWithAssignment(AssignmentRequestResult result, | 63 virtual void ConnectWithAssignment(AssignmentRequestResult result, |
| 60 const Assignment& assignment); | 64 const Assignment& assignment); |
| 61 | 65 |
| 62 // Provides functionality from the embedder. | 66 // Provides functionality from the embedder. |
| 63 BlimpClientContextDelegate* delegate_ = nullptr; | 67 BlimpClientContextDelegate* delegate_ = nullptr; |
| 64 | 68 |
| 65 // The task runner to use for IO operations. | 69 // The task runner to use for IO operations. |
| 66 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner_; | 70 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner_; |
| 67 | 71 |
| 68 // The task runner to use for file operations. | 72 // The task runner to use for file operations. |
| 69 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner_; | 73 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner_; |
| 70 | 74 |
| 71 // The AssignmentSource is used when the user of BlimpClientContextImpl calls | 75 // The AssignmentSource is used when the user of BlimpClientContextImpl calls |
| 72 // Connect() to get a valid assignment and later connect to the engine. | 76 // Connect() to get a valid assignment and later connect to the engine. |
| 73 std::unique_ptr<AssignmentSource> assignment_source_; | 77 std::unique_ptr<AssignmentSource> assignment_source_; |
| 74 | 78 |
| 75 std::unique_ptr<BlimpContentsManager> blimp_contents_manager_; | 79 std::unique_ptr<BlimpContentsManager> blimp_contents_manager_; |
| 76 | 80 |
| 77 // Container struct for network components. | 81 // Container struct for network components. |
| 78 // Must be deleted on the IO thread. | 82 // Must be deleted on the IO thread. |
| 79 std::unique_ptr<ClientNetworkComponents> net_components_; | 83 std::unique_ptr<ClientNetworkComponents> net_components_; |
| 80 | 84 |
| 81 std::unique_ptr<ThreadPipeManager> thread_pipe_manager_; | 85 std::unique_ptr<ThreadPipeManager> thread_pipe_manager_; |
| 82 | 86 |
| 87 // Provide OAuth2 token and propagate account sign in states change. |
| 88 std::unique_ptr<IdentitySource> identity_source_; |
| 89 |
| 83 base::WeakPtrFactory<BlimpClientContextImpl> weak_factory_; | 90 base::WeakPtrFactory<BlimpClientContextImpl> weak_factory_; |
| 84 | 91 |
| 85 DISALLOW_COPY_AND_ASSIGN(BlimpClientContextImpl); | 92 DISALLOW_COPY_AND_ASSIGN(BlimpClientContextImpl); |
| 86 }; | 93 }; |
| 87 | 94 |
| 88 } // namespace client | 95 } // namespace client |
| 89 } // namespace blimp | 96 } // namespace blimp |
| 90 | 97 |
| 91 #endif // BLIMP_CLIENT_CORE_BLIMP_CLIENT_CONTEXT_IMPL_H_ | 98 #endif // BLIMP_CLIENT_CORE_BLIMP_CLIENT_CONTEXT_IMPL_H_ |
| OLD | NEW |