Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 ANDROID_WEBVIEW_BROWSER_AW_METRICS_SERVICE_CLIENT_IMPL_H_ | 5 #ifndef ANDROID_WEBVIEW_BROWSER_AW_METRICS_SERVICE_CLIENT_IMPL_H_ |
| 6 #define ANDROID_WEBVIEW_BROWSER_AW_METRICS_SERVICE_CLIENT_IMPL_H_ | 6 #define ANDROID_WEBVIEW_BROWSER_AW_METRICS_SERVICE_CLIENT_IMPL_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "android_webview/browser/aw_metrics_service_client.h" | 11 #include "android_webview/browser/aw_metrics_service_client.h" |
| 12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "components/metrics/enabled_state_provider.h" | |
| 14 #include "components/metrics/metrics_service_client.h" | 15 #include "components/metrics/metrics_service_client.h" |
| 15 | 16 |
| 16 class PrefService; | 17 class PrefService; |
| 17 | 18 |
| 18 namespace base { | 19 namespace base { |
| 19 class FilePath; | 20 class FilePath; |
| 20 } | 21 } |
| 21 | 22 |
| 22 namespace metrics { | 23 namespace metrics { |
| 23 struct ClientInfo; | 24 struct ClientInfo; |
| 24 class MetricsStateManager; | 25 class MetricsStateManager; |
| 25 } | 26 } |
| 26 | 27 |
| 27 namespace net { | 28 namespace net { |
| 28 class URLRequestContextGetter; | 29 class URLRequestContextGetter; |
| 29 } | 30 } |
| 30 | 31 |
| 31 namespace android_webview { | 32 namespace android_webview { |
| 32 | 33 |
| 33 // This singleton manages metrics for an app using any number of WebViews. The | 34 // This singleton manages metrics for an app using any number of WebViews. The |
| 34 // homonymous Java class is responsible for turning metrics on and off. This | 35 // homonymous Java class is responsible for turning metrics on and off. This |
| 35 // singleton must always be used on the same thread. (Currently the UI thread | 36 // singleton must always be used on the same thread. (Currently the UI thread |
| 36 // is enforced, but it could be any thread.) This is to prevent enable/disable | 37 // is enforced, but it could be any thread.) This is to prevent enable/disable |
| 37 // race conditions, and because MetricsService is single-threaded. | 38 // race conditions, and because MetricsService is single-threaded. |
| 38 // Initialization is asynchronous; even after Initialize has returned, some | 39 // Initialization is asynchronous; even after Initialize has returned, some |
| 39 // methods may not be ready to use (see below). | 40 // methods may not be ready to use (see below). |
| 40 class AwMetricsServiceClient : public metrics::MetricsServiceClient { | 41 class AwMetricsServiceClient : public metrics::MetricsServiceClient, |
| 42 public metrics::EnabledStateProvider { | |
| 41 friend struct base::DefaultLazyInstanceTraits<AwMetricsServiceClient>; | 43 friend struct base::DefaultLazyInstanceTraits<AwMetricsServiceClient>; |
| 42 | 44 |
| 43 public: | 45 public: |
| 44 // These may be called at any time. | 46 // These may be called at any time. |
| 45 static AwMetricsServiceClient* GetInstance(); | 47 static AwMetricsServiceClient* GetInstance(); |
| 46 void Initialize(PrefService* pref_service, | 48 void Initialize(PrefService* pref_service, |
| 47 net::URLRequestContextGetter* request_context, | 49 net::URLRequestContextGetter* request_context, |
| 48 const base::FilePath guid_file_path); | 50 const base::FilePath guid_file_path); |
| 49 void SetMetricsEnabled(bool enabled); | 51 void SetMetricsEnabled(bool enabled); |
| 50 | 52 |
| 51 // These implement metrics::MetricsServiceClient. They must not be called | 53 // These implement metrics::MetricsServiceClient. They must not be called |
| 52 // until initialization has asynchronously finished. | 54 // until initialization has asynchronously finished. |
| 53 metrics::MetricsService* GetMetricsService() override; | 55 metrics::MetricsService* GetMetricsService() override; |
| 54 void SetMetricsClientId(const std::string& client_id) override; | 56 void SetMetricsClientId(const std::string& client_id) override; |
| 55 void OnRecordingDisabled() override; | 57 void OnRecordingDisabled() override; |
| 56 bool IsOffTheRecordSessionActive() override; | 58 bool IsOffTheRecordSessionActive() override; |
| 57 int32_t GetProduct() override; | 59 int32_t GetProduct() override; |
| 58 std::string GetApplicationLocale() override; | 60 std::string GetApplicationLocale() override; |
| 59 bool GetBrand(std::string* brand_code) override; | 61 bool GetBrand(std::string* brand_code) override; |
| 60 metrics::SystemProfileProto::Channel GetChannel() override; | 62 metrics::SystemProfileProto::Channel GetChannel() override; |
| 61 std::string GetVersionString() override; | 63 std::string GetVersionString() override; |
| 62 void OnLogUploadComplete() override; | 64 void OnLogUploadComplete() override; |
| 63 void InitializeSystemProfileMetrics( | 65 void InitializeSystemProfileMetrics( |
| 64 const base::Closure& done_callback) override; | 66 const base::Closure& done_callback) override; |
| 65 void CollectFinalMetricsForLog(const base::Closure& done_callback) override; | 67 void CollectFinalMetricsForLog(const base::Closure& done_callback) override; |
| 66 std::unique_ptr<metrics::MetricsLogUploader> CreateUploader( | 68 std::unique_ptr<metrics::MetricsLogUploader> CreateUploader( |
| 67 const base::Callback<void(int)>& on_upload_complete) override; | 69 const base::Callback<void(int)>& on_upload_complete) override; |
| 68 base::TimeDelta GetStandardUploadInterval() override; | 70 base::TimeDelta GetStandardUploadInterval() override; |
| 69 | 71 |
| 72 // metrics::EnabledStateProvider implementation: | |
|
Alexei Svitkine (slow)
2016/05/11 18:37:26
Nit: New suggested syntax for these comments is ju
jwd
2016/05/11 19:17:04
Done.
| |
| 73 bool IsConsentGiven() override; | |
| 74 | |
| 70 private: | 75 private: |
| 71 AwMetricsServiceClient(); | 76 AwMetricsServiceClient(); |
| 72 ~AwMetricsServiceClient() override; | 77 ~AwMetricsServiceClient() override; |
| 73 | 78 |
| 74 void InitializeWithGUID(std::string* guid); | 79 void InitializeWithGUID(std::string* guid); |
| 75 | 80 |
| 76 // Callback for metrics::MetricsStateManager::Create | |
| 77 bool is_reporting_enabled(); | |
| 78 | |
| 79 bool is_initialized_; | 81 bool is_initialized_; |
| 80 bool is_enabled_; | 82 bool is_enabled_; |
| 81 PrefService* pref_service_; | 83 PrefService* pref_service_; |
| 82 net::URLRequestContextGetter* request_context_; | 84 net::URLRequestContextGetter* request_context_; |
| 83 std::unique_ptr<metrics::MetricsStateManager> metrics_state_manager_; | |
| 84 std::unique_ptr<metrics::MetricsService> metrics_service_; | 85 std::unique_ptr<metrics::MetricsService> metrics_service_; |
| 86 std::unique_ptr<AwEnabledStateProvider> enabled_state_provider_; | |
| 85 | 87 |
| 86 DISALLOW_COPY_AND_ASSIGN(AwMetricsServiceClient); | 88 DISALLOW_COPY_AND_ASSIGN(AwMetricsServiceClient); |
| 87 }; | 89 }; |
| 88 | 90 |
| 89 } // namespace android_webview | 91 } // namespace android_webview |
| 90 | 92 |
| 91 #endif // ANDROID_WEBVIEW_BROWSER_AW_METRICS_SERVICE_CLIENT_IMPL_H_ | 93 #endif // ANDROID_WEBVIEW_BROWSER_AW_METRICS_SERVICE_CLIENT_IMPL_H_ |
| OLD | NEW |