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 // Provides functionality from the embedder. |
44 BlimpClientContextDelegate* delegate_; | 63 BlimpClientContextDelegate* delegate_; |
45 | 64 |
| 65 // The task runner to use for IO operations. |
| 66 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner_; |
| 67 |
| 68 // Collects details of network, such as number of commits and bytes |
| 69 // transferred over network. Owned by ClientNetworkComponents. |
| 70 BlimpConnectionStatistics* blimp_connection_statistics_; |
| 71 |
| 72 // Container struct for network components. |
| 73 // Must be deleted on the IO thread. |
| 74 std::unique_ptr<ClientNetworkComponents> net_components_; |
| 75 |
| 76 std::unique_ptr<ThreadPipeManager> thread_pipe_manager_; |
| 77 |
| 78 base::WeakPtrFactory<BlimpClientContextImpl> weak_factory_; |
| 79 |
46 DISALLOW_COPY_AND_ASSIGN(BlimpClientContextImpl); | 80 DISALLOW_COPY_AND_ASSIGN(BlimpClientContextImpl); |
47 }; | 81 }; |
48 | 82 |
49 } // namespace client | 83 } // namespace client |
50 } // namespace blimp | 84 } // namespace blimp |
51 | 85 |
52 #endif // BLIMP_CLIENT_CORE_BLIMP_CLIENT_CONTEXT_IMPL_H_ | 86 #endif // BLIMP_CLIENT_CORE_BLIMP_CLIENT_CONTEXT_IMPL_H_ |
OLD | NEW |