Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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_H_ | 5 #ifndef ANDROID_WEBVIEW_BROWSER_AW_METRICS_SERVICE_CLIENT_H_ |
| 6 #define ANDROID_WEBVIEW_BROWSER_AW_METRICS_SERVICE_CLIENT_H_ | 6 #define ANDROID_WEBVIEW_BROWSER_AW_METRICS_SERVICE_CLIENT_H_ |
| 7 | 7 |
| 8 #include <jni.h> | |
| 9 #include <memory> | |
| 10 #include <string> | |
| 11 | |
| 12 #include "android_webview/browser/aw_metrics_service_client.h" | |
|
paulmiller
2017/05/19 17:27:06
Recursion! :)
boliu
2017/05/19 17:37:21
oh yeah, fix that too
maybe double check if previ
| |
| 13 #include "base/lazy_instance.h" | |
| 14 #include "base/macros.h" | |
| 8 #include "components/metrics/enabled_state_provider.h" | 15 #include "components/metrics/enabled_state_provider.h" |
| 16 #include "components/metrics/metrics_log_uploader.h" | |
| 9 #include "components/metrics/metrics_service_client.h" | 17 #include "components/metrics/metrics_service_client.h" |
| 10 | 18 |
| 11 class PrefService; | 19 class PrefService; |
| 12 | 20 |
| 13 namespace base { | 21 namespace base { |
| 14 class FilePath; | 22 class FilePath; |
| 15 } | 23 } |
| 16 | 24 |
| 17 namespace net { | 25 namespace net { |
| 18 class URLRequestContextGetter; | 26 class URLRequestContextGetter; |
| 19 } | 27 } |
| 20 | 28 |
| 29 namespace metrics { | |
| 30 class MetricsStateManager; | |
| 31 } | |
| 32 | |
| 21 namespace android_webview { | 33 namespace android_webview { |
| 22 | 34 |
| 35 // This singleton manages metrics for an app using any number of WebViews. It | |
| 36 // must always be used on the same thread. (Currently the UI thread is enforced, | |
| 37 // but it could be any thread.) This is to prevent enable/disable race | |
| 38 // conditions, and because MetricsService is single-threaded. Initialization is | |
| 39 // asynchronous; even after Initialize has returned, some methods may not be | |
| 40 // ready to use (see below). | |
| 23 class AwMetricsServiceClient : public metrics::MetricsServiceClient, | 41 class AwMetricsServiceClient : public metrics::MetricsServiceClient, |
| 24 public metrics::EnabledStateProvider { | 42 public metrics::EnabledStateProvider { |
| 43 friend struct base::LazyInstanceTraitsBase<AwMetricsServiceClient>; | |
| 44 | |
| 25 public: | 45 public: |
| 26 static AwMetricsServiceClient* GetInstance(); | 46 static AwMetricsServiceClient* GetInstance(); |
| 27 virtual void Initialize(PrefService* pref_service, | 47 void Initialize(PrefService* pref_service, |
| 28 net::URLRequestContextGetter* request_context, | 48 net::URLRequestContextGetter* request_context, |
| 29 const base::FilePath guid_file_path) = 0; | 49 const base::FilePath guid_file_path); |
| 30 | 50 |
| 31 protected: | 51 // metrics::EnabledStateProvider implementation |
| 52 bool IsConsentGiven() override; | |
| 53 | |
| 54 // The below functions must not be called until initialization has | |
| 55 // asynchronously finished. | |
| 56 | |
| 57 void SetMetricsEnabled(bool enabled); | |
| 58 | |
| 59 // metrics::MetricsServiceClient implementation | |
| 60 metrics::MetricsService* GetMetricsService() override; | |
| 61 void SetMetricsClientId(const std::string& client_id) override; | |
| 62 int32_t GetProduct() override; | |
| 63 std::string GetApplicationLocale() override; | |
| 64 bool GetBrand(std::string* brand_code) override; | |
| 65 metrics::SystemProfileProto::Channel GetChannel() override; | |
| 66 std::string GetVersionString() override; | |
| 67 void InitializeSystemProfileMetrics( | |
| 68 const base::Closure& done_callback) override; | |
| 69 void CollectFinalMetricsForLog(const base::Closure& done_callback) override; | |
| 70 std::unique_ptr<metrics::MetricsLogUploader> CreateUploader( | |
| 71 base::StringPiece server_url, | |
| 72 base::StringPiece mime_type, | |
| 73 metrics::MetricsLogUploader::MetricServiceType service_type, | |
| 74 const metrics::MetricsLogUploader::UploadCallback& on_upload_complete) | |
| 75 override; | |
| 76 base::TimeDelta GetStandardUploadInterval() override; | |
| 77 | |
| 78 private: | |
| 32 AwMetricsServiceClient(); | 79 AwMetricsServiceClient(); |
| 33 ~AwMetricsServiceClient() override; | 80 ~AwMetricsServiceClient() override; |
| 34 | 81 |
| 35 private: | 82 void InitializeWithGUID(std::string* guid); |
| 83 | |
| 84 bool is_enabled_; | |
| 85 PrefService* pref_service_; | |
| 86 net::URLRequestContextGetter* request_context_; | |
| 87 std::unique_ptr<metrics::MetricsStateManager> metrics_state_manager_; | |
| 88 std::unique_ptr<metrics::MetricsService> metrics_service_; | |
| 89 | |
| 36 DISALLOW_COPY_AND_ASSIGN(AwMetricsServiceClient); | 90 DISALLOW_COPY_AND_ASSIGN(AwMetricsServiceClient); |
| 37 }; | 91 }; |
| 38 | 92 |
| 93 bool RegisterAwMetricsServiceClient(JNIEnv* env); | |
| 94 | |
| 39 } // namespace android_webview | 95 } // namespace android_webview |
| 40 | 96 |
| 41 #endif // ANDROID_WEBVIEW_BROWSER_AW_METRICS_SERVICE_CLIENT_H_ | 97 #endif // ANDROID_WEBVIEW_BROWSER_AW_METRICS_SERVICE_CLIENT_H_ |
| OLD | NEW |