diff options
Diffstat (limited to 'chromecast')
-rw-r--r-- | chromecast/metrics/cast_metrics_service_client.cc | 10 | ||||
-rw-r--r-- | chromecast/metrics/cast_metrics_service_client.h | 2 | ||||
-rw-r--r-- | chromecast/service/cast_service.cc | 5 | ||||
-rw-r--r-- | chromecast/service/cast_service.h | 16 | ||||
-rw-r--r-- | chromecast/service/cast_service_android.cc | 15 | ||||
-rw-r--r-- | chromecast/service/cast_service_android.h | 3 | ||||
-rw-r--r-- | chromecast/service/cast_service_simple.cc | 11 | ||||
-rw-r--r-- | chromecast/service/cast_service_simple.h | 3 | ||||
-rw-r--r-- | chromecast/shell/browser/cast_browser_main_parts.cc | 5 |
9 files changed, 53 insertions, 17 deletions
diff --git a/chromecast/metrics/cast_metrics_service_client.cc b/chromecast/metrics/cast_metrics_service_client.cc index 637cd40..50bbf47 100644 --- a/chromecast/metrics/cast_metrics_service_client.cc +++ b/chromecast/metrics/cast_metrics_service_client.cc @@ -105,6 +105,15 @@ CastMetricsServiceClient::CreateUploader( } void CastMetricsServiceClient::EnableMetricsService(bool enabled) { + if (!metrics_service_loop_->BelongsToCurrentThread()) { + metrics_service_loop_->PostTask( + FROM_HERE, + base::Bind(&CastMetricsServiceClient::EnableMetricsService, + base::Unretained(this), + enabled)); + return; + } + if (enabled) { metrics_service_->Start(); } else { @@ -126,6 +135,7 @@ CastMetricsServiceClient::CastMetricsServiceClient( metrics_state_manager_.get(), this, pref_service)), + metrics_service_loop_(base::MessageLoopProxy::current()), request_context_(request_context) { // Always create a client id as it may also be used by crash reporting, // (indirectly) included in feedback, and can be queried during setup. diff --git a/chromecast/metrics/cast_metrics_service_client.h b/chromecast/metrics/cast_metrics_service_client.h index fc55aea..eb6e0cf 100644 --- a/chromecast/metrics/cast_metrics_service_client.h +++ b/chromecast/metrics/cast_metrics_service_client.h @@ -15,6 +15,7 @@ class PrefService; namespace base { +class MessageLoopProxy; class TaskRunner; } @@ -69,6 +70,7 @@ class CastMetricsServiceClient : public ::metrics::MetricsServiceClient { scoped_ptr< ::metrics::MetricsStateManager> metrics_state_manager_; scoped_ptr< ::metrics::MetricsService> metrics_service_; + scoped_refptr<base::MessageLoopProxy> metrics_service_loop_; net::URLRequestContextGetter* request_context_; DISALLOW_COPY_AND_ASSIGN(CastMetricsServiceClient); diff --git a/chromecast/service/cast_service.cc b/chromecast/service/cast_service.cc index 1533b20..0490b0f 100644 --- a/chromecast/service/cast_service.cc +++ b/chromecast/service/cast_service.cc @@ -9,8 +9,11 @@ namespace chromecast { -CastService::CastService(content::BrowserContext* browser_context) +CastService::CastService( + content::BrowserContext* browser_context, + const OptInStatsChangedCallback& opt_in_stats_callback) : browser_context_(browser_context), + opt_in_stats_callback_(opt_in_stats_callback), stopped_(true), thread_checker_(new base::ThreadChecker()) { } diff --git a/chromecast/service/cast_service.h b/chromecast/service/cast_service.h index 2f94bc5..0b646f4 100644 --- a/chromecast/service/cast_service.h +++ b/chromecast/service/cast_service.h @@ -5,6 +5,7 @@ #ifndef CHROMECAST_SERVICE_CAST_SERVICE_H_ #define CHROMECAST_SERVICE_CAST_SERVICE_H_ +#include "base/callback.h" #include "base/macros.h" #include "base/memory/scoped_ptr.h" @@ -27,6 +28,10 @@ class CastNetworkDelegate; class CastService { public: + // A callback that will be invoked when the user changes the opt-in stats + // value. + typedef base::Callback<void(bool)> OptInStatsChangedCallback; + // Create() takes a separate url request context getter because the request // context getter obtained through the browser context might not be // appropriate for the url requests made by the cast service/reciever. @@ -36,7 +41,8 @@ class CastService { static CastService* Create( content::BrowserContext* browser_context, net::URLRequestContextGetter* request_context_getter, - shell::CastNetworkDelegate* network_delegate); + shell::CastNetworkDelegate* network_delegate, + const OptInStatsChangedCallback& opt_in_stats_callback); virtual ~CastService(); @@ -45,7 +51,8 @@ class CastService { void Stop(); protected: - explicit CastService(content::BrowserContext* browser_context); + CastService(content::BrowserContext* browser_context, + const OptInStatsChangedCallback& opt_in_stats_callback); virtual void Initialize() = 0; // Implementation-specific start/stop behavior. @@ -53,11 +60,14 @@ class CastService { virtual void StopInternal() = 0; content::BrowserContext* browser_context() const { return browser_context_; } + const OptInStatsChangedCallback& opt_in_stats_callback() const { + return opt_in_stats_callback_; + } private: content::BrowserContext* const browser_context_; + const OptInStatsChangedCallback opt_in_stats_callback_; bool stopped_; - const scoped_ptr<base::ThreadChecker> thread_checker_; DISALLOW_COPY_AND_ASSIGN(CastService); diff --git a/chromecast/service/cast_service_android.cc b/chromecast/service/cast_service_android.cc index 4c936c3..bd68861 100644 --- a/chromecast/service/cast_service_android.cc +++ b/chromecast/service/cast_service_android.cc @@ -12,20 +12,23 @@ namespace chromecast { CastService* CastService::Create( content::BrowserContext* browser_context, net::URLRequestContextGetter* request_context_getter, - shell::CastNetworkDelegate* network_delegate) { - return new CastServiceAndroid(browser_context); + shell::CastNetworkDelegate* network_delegate, + const OptInStatsChangedCallback& opt_in_stats_callback) { + return new CastServiceAndroid(browser_context, opt_in_stats_callback); } -CastServiceAndroid::CastServiceAndroid(content::BrowserContext* browser_context) - : CastService(browser_context) { +CastServiceAndroid::CastServiceAndroid( + content::BrowserContext* browser_context, + const OptInStatsChangedCallback& opt_in_stats_callback) + : CastService(browser_context, opt_in_stats_callback) { } CastServiceAndroid::~CastServiceAndroid() { } void CastServiceAndroid::Initialize() { - // TODO(gunsch): Wire this the SendUsageStatsChanged callback once - // CastService::Delegate is added. + android::ChromecastConfigAndroid::GetInstance()-> + SetSendUsageStatsChangedCallback(opt_in_stats_callback()); } void CastServiceAndroid::StartInternal() { diff --git a/chromecast/service/cast_service_android.h b/chromecast/service/cast_service_android.h index 234b012..eee82e8 100644 --- a/chromecast/service/cast_service_android.h +++ b/chromecast/service/cast_service_android.h @@ -12,7 +12,8 @@ namespace chromecast { class CastServiceAndroid : public CastService { public: - explicit CastServiceAndroid(content::BrowserContext* browser_context); + CastServiceAndroid(content::BrowserContext* browser_context, + const OptInStatsChangedCallback& opt_in_stats_callback); virtual ~CastServiceAndroid(); protected: diff --git a/chromecast/service/cast_service_simple.cc b/chromecast/service/cast_service_simple.cc index 126596d..c11449e 100644 --- a/chromecast/service/cast_service_simple.cc +++ b/chromecast/service/cast_service_simple.cc @@ -73,12 +73,15 @@ class FillLayout : public aura::LayoutManager { CastService* CastService::Create( content::BrowserContext* browser_context, net::URLRequestContextGetter* request_context_getter, - shell::CastNetworkDelegate* network_delegate) { - return new CastServiceSimple(browser_context); + shell::CastNetworkDelegate* network_delegate, + const OptInStatsChangedCallback& opt_in_stats_callback) { + return new CastServiceSimple(browser_context, opt_in_stats_callback); } -CastServiceSimple::CastServiceSimple(content::BrowserContext* browser_context) - : CastService(browser_context) { +CastServiceSimple::CastServiceSimple( + content::BrowserContext* browser_context, + const OptInStatsChangedCallback& opt_in_stats_callback) + : CastService(browser_context, opt_in_stats_callback) { } CastServiceSimple::~CastServiceSimple() { diff --git a/chromecast/service/cast_service_simple.h b/chromecast/service/cast_service_simple.h index 534b2c0..8ebfc06 100644 --- a/chromecast/service/cast_service_simple.h +++ b/chromecast/service/cast_service_simple.h @@ -20,7 +20,8 @@ namespace chromecast { class CastServiceSimple : public CastService { public: - explicit CastServiceSimple(content::BrowserContext* browser_context); + CastServiceSimple(content::BrowserContext* browser_context, + const OptInStatsChangedCallback& opt_in_stats_callback); virtual ~CastServiceSimple(); protected: diff --git a/chromecast/shell/browser/cast_browser_main_parts.cc b/chromecast/shell/browser/cast_browser_main_parts.cc index 6d1a96b..17708f0 100644 --- a/chromecast/shell/browser/cast_browser_main_parts.cc +++ b/chromecast/shell/browser/cast_browser_main_parts.cc @@ -113,7 +113,10 @@ void CastBrowserMainParts::PreMainMessageLoopRun() { cast_browser_process_->SetCastService(CastService::Create( cast_browser_process_->browser_context(), url_request_context_factory_->GetSystemGetter(), - url_request_context_factory_->app_network_delegate())); + url_request_context_factory_->app_network_delegate(), + base::Bind( + &metrics::CastMetricsServiceClient::EnableMetricsService, + base::Unretained(cast_browser_process_->metrics_service_client())))); // Initializing network delegates must happen after Cast service is created. url_request_context_factory_->InitializeNetworkDelegates(); |