OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef ANDROID_WEBVIEW_BROWSER_AW_METRICS_SERVICE_CLIENT_IMPL_H_ |
| 6 #define ANDROID_WEBVIEW_BROWSER_AW_METRICS_SERVICE_CLIENT_IMPL_H_ |
| 7 |
| 8 #include "android_webview/browser/aw_metrics_service_client.h" |
| 9 |
| 10 #include <string> |
| 11 |
| 12 #include "base/lazy_instance.h" |
| 13 #include "base/macros.h" |
| 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "components/metrics/metrics_service_client.h" |
| 16 |
| 17 class PrefService; |
| 18 |
| 19 namespace metrics { |
| 20 struct ClientInfo; |
| 21 class MetricsStateManager; |
| 22 } |
| 23 |
| 24 namespace net { |
| 25 class URLRequestContextGetter; |
| 26 } |
| 27 |
| 28 namespace android_webview { |
| 29 |
| 30 // This singleton manages metrics for an app using any number of WebViews. |
| 31 // Metrics is turned on and off by the homonymous Java class. It should only be |
| 32 // used on the main thread. In particular, Initialize, Finalize, and |
| 33 // SetMetricsEnabled must be called from the same thread, in order to prevent |
| 34 // enable/disable race conditions, and because MetricsService is |
| 35 // single-threaded. |
| 36 class AwMetricsServiceClient : public metrics::MetricsServiceClient { |
| 37 friend struct base::DefaultLazyInstanceTraits<AwMetricsServiceClient>; |
| 38 |
| 39 public: |
| 40 static AwMetricsServiceClient* GetInstance(); |
| 41 |
| 42 void Initialize(PrefService* pref_service, |
| 43 net::URLRequestContextGetter* request_context); |
| 44 void Finalize(); |
| 45 void SetMetricsEnabled(bool enabled); |
| 46 |
| 47 // metrics::MetricsServiceClient implementation |
| 48 metrics::MetricsService* GetMetricsService() override; |
| 49 void SetMetricsClientId(const std::string& client_id) override; |
| 50 void OnRecordingDisabled() override; |
| 51 bool IsOffTheRecordSessionActive() override; |
| 52 int32_t GetProduct() override; |
| 53 std::string GetApplicationLocale() override; |
| 54 bool GetBrand(std::string* brand_code) override; |
| 55 metrics::SystemProfileProto::Channel GetChannel() override; |
| 56 std::string GetVersionString() override; |
| 57 void OnLogUploadComplete() override; |
| 58 void InitializeSystemProfileMetrics( |
| 59 const base::Closure& done_callback) override; |
| 60 void CollectFinalMetricsForLog(const base::Closure& done_callback) override; |
| 61 scoped_ptr<metrics::MetricsLogUploader> CreateUploader( |
| 62 const base::Callback<void(int)>& on_upload_complete) override; |
| 63 base::TimeDelta GetStandardUploadInterval() override; |
| 64 |
| 65 private: |
| 66 AwMetricsServiceClient(); |
| 67 ~AwMetricsServiceClient() override; |
| 68 |
| 69 // Callback for metrics::MetricsStateManager::Create |
| 70 bool is_reporting_enabled(); |
| 71 |
| 72 bool is_initialized_; |
| 73 bool is_enabled_; |
| 74 PrefService* pref_service_; |
| 75 net::URLRequestContextGetter* request_context_; |
| 76 scoped_ptr<metrics::MetricsStateManager> metrics_state_manager_; |
| 77 scoped_ptr<metrics::MetricsService> metrics_service_; |
| 78 |
| 79 DISALLOW_COPY_AND_ASSIGN(AwMetricsServiceClient); |
| 80 }; |
| 81 |
| 82 } // namespace android_webview |
| 83 |
| 84 #endif // ANDROID_WEBVIEW_BROWSER_AW_METRICS_SERVICE_CLIENT_IMPL_H_ |
OLD | NEW |