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> |
| 9 |
8 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/single_thread_task_runner.h" |
9 #include "base/supports_user_data.h" | 14 #include "base/supports_user_data.h" |
| 15 #include "base/threading/thread.h" |
| 16 #include "blimp/client/core/session/client_network_components.h" |
| 17 #include "blimp/client/core/session/network_event_observer.h" |
10 #include "blimp/client/public/blimp_client_context.h" | 18 #include "blimp/client/public/blimp_client_context.h" |
11 #include "blimp/client/public/contents/blimp_contents.h" | 19 #include "blimp/client/public/contents/blimp_contents.h" |
| 20 #include "blimp/net/blimp_connection_statistics.h" |
| 21 #include "blimp/net/thread_pipe_manager.h" |
12 | 22 |
13 #if defined(OS_ANDROID) | 23 #if defined(OS_ANDROID) |
14 #include "base/android/jni_android.h" | 24 #include "base/android/jni_android.h" |
15 #endif // defined(OS_ANDROID) | 25 #endif // defined(OS_ANDROID) |
16 | 26 |
17 namespace blimp { | 27 namespace blimp { |
18 namespace client { | 28 namespace client { |
19 | 29 |
20 #if defined(OS_ANDROID) | 30 #if defined(OS_ANDROID) |
21 class BlimpClientContextImplAndroid; | 31 class BlimpClientContextImplAndroid; |
22 #endif // defined(OS_ANDROID) | 32 #endif // defined(OS_ANDROID) |
23 | 33 |
24 // BlimpClientContextImpl is the implementation of the main context-class for | 34 // BlimpClientContextImpl is the implementation of the main context-class for |
25 // the blimp client. | 35 // the blimp client. |
26 class BlimpClientContextImpl : public BlimpClientContext, | 36 class BlimpClientContextImpl : public BlimpClientContext, |
| 37 public NetworkEventObserver, |
27 base::SupportsUserData { | 38 base::SupportsUserData { |
28 public: | 39 public: |
29 BlimpClientContextImpl(); | 40 // The |io_thread_task_runner| must be the task runner to use for IO |
| 41 // operations. |
| 42 explicit BlimpClientContextImpl( |
| 43 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner); |
30 ~BlimpClientContextImpl() override; | 44 ~BlimpClientContextImpl() override; |
31 | 45 |
32 #if defined(OS_ANDROID) | 46 #if defined(OS_ANDROID) |
33 BlimpClientContextImplAndroid* GetBlimpClientContextImplAndroid(); | 47 BlimpClientContextImplAndroid* GetBlimpClientContextImplAndroid(); |
34 #endif // defined(OS_ANDROID) | 48 #endif // defined(OS_ANDROID) |
35 | 49 |
36 // BlimpClientContext implementation. | 50 // BlimpClientContext implementation. |
37 #if defined(OS_ANDROID) | 51 #if defined(OS_ANDROID) |
38 base::android::ScopedJavaLocalRef<jobject> GetJavaObject() override; | 52 base::android::ScopedJavaLocalRef<jobject> GetJavaObject() override; |
39 #endif // defined(OS_ANDROID) | 53 #endif // defined(OS_ANDROID) |
40 void SetDelegate(BlimpClientContextDelegate* delegate) override; | 54 void SetDelegate(BlimpClientContextDelegate* delegate) override; |
41 std::unique_ptr<BlimpContents> CreateBlimpContents() override; | 55 std::unique_ptr<BlimpContents> CreateBlimpContents() override; |
42 | 56 |
| 57 // NetworkEventObserver implementation. |
| 58 void OnConnected() override; |
| 59 void OnDisconnected(int result) override; |
| 60 |
43 private: | 61 private: |
| 62 // Registers the Blimp features. Called during construction to set up |
| 63 // pointers to the network code. |
| 64 void RegisterFeatures(); |
| 65 |
44 BlimpClientContextDelegate* delegate_; | 66 BlimpClientContextDelegate* delegate_; |
45 | 67 |
| 68 // The task runner to use for IO operations. |
| 69 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner_; |
| 70 |
| 71 // Collects details of network, such as number of commits and bytes |
| 72 // transferred over network. Ownership is maintained on the IO thread. |
| 73 BlimpConnectionStatistics* blimp_connection_statistics_; |
| 74 |
| 75 // Container struct for network components. |
| 76 // Must be deleted on the IO thread. |
| 77 std::unique_ptr<ClientNetworkComponents> net_components_; |
| 78 |
| 79 std::unique_ptr<ThreadPipeManager> thread_pipe_manager_; |
| 80 |
| 81 base::WeakPtrFactory<BlimpClientContextImpl> weak_factory_; |
| 82 |
46 DISALLOW_COPY_AND_ASSIGN(BlimpClientContextImpl); | 83 DISALLOW_COPY_AND_ASSIGN(BlimpClientContextImpl); |
47 }; | 84 }; |
48 | 85 |
49 } // namespace client | 86 } // namespace client |
50 } // namespace blimp | 87 } // namespace blimp |
51 | 88 |
52 #endif // BLIMP_CLIENT_CORE_BLIMP_CLIENT_CONTEXT_IMPL_H_ | 89 #endif // BLIMP_CLIENT_CORE_BLIMP_CLIENT_CONTEXT_IMPL_H_ |
OLD | NEW |