Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Side by Side Diff: android_webview/browser/aw_metrics_service_client.h

Issue 2886283005: [WebView] Merge AwMetricsServiceClient and move few files to new place (Closed)
Patch Set: remove recursive include Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/lazy_instance.h"
13 #include "base/macros.h"
8 #include "components/metrics/enabled_state_provider.h" 14 #include "components/metrics/enabled_state_provider.h"
15 #include "components/metrics/metrics_log_uploader.h"
9 #include "components/metrics/metrics_service_client.h" 16 #include "components/metrics/metrics_service_client.h"
10 17
11 class PrefService; 18 class PrefService;
12 19
13 namespace base { 20 namespace base {
14 class FilePath; 21 class FilePath;
15 } 22 }
16 23
17 namespace net { 24 namespace net {
18 class URLRequestContextGetter; 25 class URLRequestContextGetter;
19 } 26 }
20 27
28 namespace metrics {
29 class MetricsStateManager;
30 }
31
21 namespace android_webview { 32 namespace android_webview {
22 33
34 // This singleton manages metrics for an app using any number of WebViews. It
35 // must always be used on the same thread. (Currently the UI thread is enforced,
36 // but it could be any thread.) This is to prevent enable/disable race
37 // conditions, and because MetricsService is single-threaded. Initialization is
38 // asynchronous; even after Initialize has returned, some methods may not be
39 // ready to use (see below).
23 class AwMetricsServiceClient : public metrics::MetricsServiceClient, 40 class AwMetricsServiceClient : public metrics::MetricsServiceClient,
24 public metrics::EnabledStateProvider { 41 public metrics::EnabledStateProvider {
42 friend struct base::LazyInstanceTraitsBase<AwMetricsServiceClient>;
43
25 public: 44 public:
26 static AwMetricsServiceClient* GetInstance(); 45 static AwMetricsServiceClient* GetInstance();
27 virtual void Initialize(PrefService* pref_service, 46 void Initialize(PrefService* pref_service,
28 net::URLRequestContextGetter* request_context, 47 net::URLRequestContextGetter* request_context,
29 const base::FilePath guid_file_path) = 0; 48 const base::FilePath guid_file_path);
30 49
31 protected: 50 // metrics::EnabledStateProvider implementation
51 bool IsConsentGiven() override;
52
53 // The below functions must not be called until initialization has
54 // asynchronously finished.
55
56 void SetMetricsEnabled(bool enabled);
57
58 // metrics::MetricsServiceClient implementation
59 metrics::MetricsService* GetMetricsService() override;
60 void SetMetricsClientId(const std::string& client_id) override;
61 int32_t GetProduct() override;
62 std::string GetApplicationLocale() override;
63 bool GetBrand(std::string* brand_code) override;
64 metrics::SystemProfileProto::Channel GetChannel() override;
65 std::string GetVersionString() override;
66 void InitializeSystemProfileMetrics(
67 const base::Closure& done_callback) override;
68 void CollectFinalMetricsForLog(const base::Closure& done_callback) override;
69 std::unique_ptr<metrics::MetricsLogUploader> CreateUploader(
70 base::StringPiece server_url,
71 base::StringPiece mime_type,
72 metrics::MetricsLogUploader::MetricServiceType service_type,
73 const metrics::MetricsLogUploader::UploadCallback& on_upload_complete)
74 override;
75 base::TimeDelta GetStandardUploadInterval() override;
76
77 private:
32 AwMetricsServiceClient(); 78 AwMetricsServiceClient();
33 ~AwMetricsServiceClient() override; 79 ~AwMetricsServiceClient() override;
34 80
35 private: 81 void InitializeWithGUID(std::string* guid);
82
83 bool is_enabled_;
84 PrefService* pref_service_;
85 net::URLRequestContextGetter* request_context_;
86 std::unique_ptr<metrics::MetricsStateManager> metrics_state_manager_;
87 std::unique_ptr<metrics::MetricsService> metrics_service_;
88
36 DISALLOW_COPY_AND_ASSIGN(AwMetricsServiceClient); 89 DISALLOW_COPY_AND_ASSIGN(AwMetricsServiceClient);
37 }; 90 };
38 91
92 bool RegisterAwMetricsServiceClient(JNIEnv* env);
93
39 } // namespace android_webview 94 } // namespace android_webview
40 95
41 #endif // ANDROID_WEBVIEW_BROWSER_AW_METRICS_SERVICE_CLIENT_H_ 96 #endif // ANDROID_WEBVIEW_BROWSER_AW_METRICS_SERVICE_CLIENT_H_
OLDNEW
« no previous file with comments | « android_webview/browser/android_webview_jni_registrar.cc ('k') | android_webview/browser/aw_metrics_service_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698