OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 CHROMECAST_BROWSER_SERVICE_CAST_SERVICE_H_ | 5 #ifndef CHROMECAST_BROWSER_SERVICE_CAST_SERVICE_H_ |
6 #define CHROMECAST_BROWSER_SERVICE_CAST_SERVICE_H_ | 6 #define CHROMECAST_BROWSER_SERVICE_CAST_SERVICE_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 | 11 |
12 class PrefService; | 12 class PrefService; |
13 | 13 |
14 namespace base { | 14 namespace base { |
15 class ThreadChecker; | 15 class ThreadChecker; |
16 } | 16 } |
17 | 17 |
18 namespace content { | 18 namespace content { |
19 class BrowserContext; | 19 class BrowserContext; |
20 } | 20 } |
21 | 21 |
22 namespace net { | 22 namespace net { |
23 class URLRequestContextGetter; | 23 class URLRequestContextGetter; |
24 } | 24 } |
25 | 25 |
26 namespace chromecast { | 26 namespace chromecast { |
27 | 27 |
28 namespace metrics { | |
29 class CastMetricsServiceClient; | |
30 } | |
31 | |
32 class CastService { | 28 class CastService { |
33 public: | 29 public: |
34 // Create() takes a separate url request context getter because the request | |
35 // context getter obtained through the browser context might not be | |
36 // appropriate for the url requests made by the cast service/reciever. | |
37 // For example, on Chromecast, it is needed to pass in a system url request | |
38 // context getter that would set the request context for NSS, which the main | |
39 // getter doesn't do. | |
40 static scoped_ptr<CastService> Create( | |
41 content::BrowserContext* browser_context, | |
42 PrefService* pref_service, | |
43 metrics::CastMetricsServiceClient* metrics_service_client, | |
44 net::URLRequestContextGetter* request_context_getter); | |
45 | |
46 virtual ~CastService(); | 30 virtual ~CastService(); |
47 | 31 |
48 // Initializes/finalizes the cast service. | 32 // Initializes/finalizes the cast service. |
49 void Initialize(); | 33 void Initialize(); |
50 void Finalize(); | 34 void Finalize(); |
51 | 35 |
52 // Starts/stops the cast service. | 36 // Starts/stops the cast service. |
53 void Start(); | 37 void Start(); |
54 void Stop(); | 38 void Stop(); |
55 | 39 |
56 protected: | 40 protected: |
57 CastService(content::BrowserContext* browser_context, | 41 CastService(content::BrowserContext* browser_context, |
58 PrefService* pref_service, | 42 PrefService* pref_service); |
59 metrics::CastMetricsServiceClient* metrics_service_client); | |
60 | 43 |
61 // Implementation-specific initialization. Initialization of cast service's | 44 // Implementation-specific initialization. Initialization of cast service's |
62 // sub-components, and anything that requires IO operations should go here. | 45 // sub-components, and anything that requires IO operations should go here. |
63 // Anything that should happen before cast service is started but doesn't need | 46 // Anything that should happen before cast service is started but doesn't need |
64 // the sub-components to finish initializing should also go here. | 47 // the sub-components to finish initializing should also go here. |
65 virtual void InitializeInternal() = 0; | 48 virtual void InitializeInternal() = 0; |
66 | 49 |
67 // Implementation-specific finalization. Any initializations done by | 50 // Implementation-specific finalization. Any initializations done by |
68 // InitializeInternal() should be finalized here. | 51 // InitializeInternal() should be finalized here. |
69 virtual void FinalizeInternal() = 0; | 52 virtual void FinalizeInternal() = 0; |
70 | 53 |
71 // Implementation-specific start behavior. It basically starts the | 54 // Implementation-specific start behavior. It basically starts the |
72 // sub-component services and does additional initialization that cannot be | 55 // sub-component services and does additional initialization that cannot be |
73 // done in the InitializationInternal(). | 56 // done in the InitializationInternal(). |
74 virtual void StartInternal() = 0; | 57 virtual void StartInternal() = 0; |
75 | 58 |
76 // Implementation-specific stop behavior. Any initializations done by | 59 // Implementation-specific stop behavior. Any initializations done by |
77 // StartInternal() should be finalized here. | 60 // StartInternal() should be finalized here. |
78 virtual void StopInternal() = 0; | 61 virtual void StopInternal() = 0; |
79 | 62 |
80 content::BrowserContext* browser_context() const { return browser_context_; } | 63 content::BrowserContext* browser_context() const { return browser_context_; } |
81 PrefService* pref_service() const { return pref_service_; } | 64 PrefService* pref_service() const { return pref_service_; } |
82 metrics::CastMetricsServiceClient* metrics_service_client() const { | |
83 return metrics_service_client_; | |
84 } | |
85 | 65 |
86 private: | 66 private: |
87 content::BrowserContext* const browser_context_; | 67 content::BrowserContext* const browser_context_; |
88 PrefService* const pref_service_; | 68 PrefService* const pref_service_; |
89 metrics::CastMetricsServiceClient* const metrics_service_client_; | |
90 bool stopped_; | 69 bool stopped_; |
91 const scoped_ptr<base::ThreadChecker> thread_checker_; | 70 const scoped_ptr<base::ThreadChecker> thread_checker_; |
92 | 71 |
93 DISALLOW_COPY_AND_ASSIGN(CastService); | 72 DISALLOW_COPY_AND_ASSIGN(CastService); |
94 }; | 73 }; |
95 | 74 |
96 } // namespace chromecast | 75 } // namespace chromecast |
97 | 76 |
98 #endif // CHROMECAST_BROWSER_SERVICE_CAST_SERVICE_H_ | 77 #endif // CHROMECAST_BROWSER_SERVICE_CAST_SERVICE_H_ |
OLD | NEW |