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

Side by Side Diff: android_webview/native/aw_metrics_service_client_impl.h

Issue 2611883002: Prepare to call GMS APIs from WebView (Closed)
Patch Set: explicit destructor for style checker Created 3 years, 11 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_IMPL_H_ 5 #ifndef ANDROID_WEBVIEW_NATIVE_AW_METRICS_SERVICE_CLIENT_IMPL_
6 #define ANDROID_WEBVIEW_BROWSER_AW_METRICS_SERVICE_CLIENT_IMPL_H_ 6 #define ANDROID_WEBVIEW_NATIVE_AW_METRICS_SERVICE_CLIENT_IMPL_
7 7
8 #include <memory> 8 #include "android_webview/browser/aw_metrics_service_client.h"
9
10 #include <jni.h>
9 #include <string> 11 #include <string>
10 12
11 #include "android_webview/browser/aw_metrics_service_client.h"
12 #include "base/lazy_instance.h" 13 #include "base/lazy_instance.h"
13 #include "base/macros.h" 14 #include "base/macros.h"
14 #include "components/metrics/enabled_state_provider.h"
15 #include "components/metrics/metrics_service_client.h"
16
17 class PrefService;
18
19 namespace base {
20 class FilePath;
21 }
22 15
23 namespace metrics { 16 namespace metrics {
24 class MetricsStateManager; 17 class MetricsStateManager;
25 } 18 }
26 19
27 namespace net {
28 class URLRequestContextGetter;
29 }
30
31 namespace android_webview { 20 namespace android_webview {
32 21
33 // This singleton manages metrics for an app using any number of WebViews. The 22 // This singleton manages metrics for an app using any number of WebViews. It
34 // homonymous Java class is responsible for turning metrics on and off. This 23 // must always be used on the same thread. (Currently the UI thread is enforced,
35 // singleton must always be used on the same thread. (Currently the UI thread 24 // but it could be any thread.) This is to prevent enable/disable race
36 // is enforced, but it could be any thread.) This is to prevent enable/disable 25 // conditions, and because MetricsService is single-threaded. Initialization is
37 // race conditions, and because MetricsService is single-threaded. 26 // asynchronous; even after Initialize has returned, some methods may not be
38 // Initialization is asynchronous; even after Initialize has returned, some 27 // ready to use (see below).
39 // methods may not be ready to use (see below). 28 class AwMetricsServiceClientImpl : public AwMetricsServiceClient {
40 class AwMetricsServiceClient : public metrics::MetricsServiceClient, 29 friend struct base::DefaultLazyInstanceTraits<AwMetricsServiceClientImpl>;
41 public metrics::EnabledStateProvider {
42 friend struct base::DefaultLazyInstanceTraits<AwMetricsServiceClient>;
43 30
44 public: 31 public:
45 // These may be called at any time.
46 static AwMetricsServiceClient* GetInstance();
47 void Initialize(PrefService* pref_service, 32 void Initialize(PrefService* pref_service,
48 net::URLRequestContextGetter* request_context, 33 net::URLRequestContextGetter* request_context,
49 const base::FilePath guid_file_path); 34 const base::FilePath guid_file_path) override;
35
36 // metrics::EnabledStateProvider implementation
37 bool IsConsentGiven() override;
38
39 // The below functions must not be called until initialization has
40 // asynchronously finished.
41
50 void SetMetricsEnabled(bool enabled); 42 void SetMetricsEnabled(bool enabled);
51 43
52 // metrics::EnabledStateProvider: 44 // metrics::MetricsServiceClient implementation
53 bool IsConsentGiven() override;
54
55 // These implement metrics::MetricsServiceClient. They must not be called
56 // until initialization has asynchronously finished.
57 metrics::MetricsService* GetMetricsService() override; 45 metrics::MetricsService* GetMetricsService() override;
58 void SetMetricsClientId(const std::string& client_id) override; 46 void SetMetricsClientId(const std::string& client_id) override;
59 int32_t GetProduct() override; 47 int32_t GetProduct() override;
60 std::string GetApplicationLocale() override; 48 std::string GetApplicationLocale() override;
61 bool GetBrand(std::string* brand_code) override; 49 bool GetBrand(std::string* brand_code) override;
62 metrics::SystemProfileProto::Channel GetChannel() override; 50 metrics::SystemProfileProto::Channel GetChannel() override;
63 std::string GetVersionString() override; 51 std::string GetVersionString() override;
64 void InitializeSystemProfileMetrics( 52 void InitializeSystemProfileMetrics(
65 const base::Closure& done_callback) override; 53 const base::Closure& done_callback) override;
66 void CollectFinalMetricsForLog(const base::Closure& done_callback) override; 54 void CollectFinalMetricsForLog(const base::Closure& done_callback) override;
67 std::unique_ptr<metrics::MetricsLogUploader> CreateUploader( 55 std::unique_ptr<metrics::MetricsLogUploader> CreateUploader(
68 const std::string& server_url, 56 const std::string& server_url,
69 const std::string& mime_type, 57 const std::string& mime_type,
70 const base::Callback<void(int)>& on_upload_complete) override; 58 const base::Callback<void(int)>& on_upload_complete) override;
71 base::TimeDelta GetStandardUploadInterval() override; 59 base::TimeDelta GetStandardUploadInterval() override;
72 60
73 private: 61 private:
74 AwMetricsServiceClient(); 62 AwMetricsServiceClientImpl();
75 ~AwMetricsServiceClient() override; 63 ~AwMetricsServiceClientImpl() override;
76 64
77 void InitializeWithGUID(std::string* guid); 65 void InitializeWithGUID(std::string* guid);
78 66
79 bool is_initialized_;
80 bool is_enabled_; 67 bool is_enabled_;
81 PrefService* pref_service_; 68 PrefService* pref_service_;
82 net::URLRequestContextGetter* request_context_; 69 net::URLRequestContextGetter* request_context_;
83 std::unique_ptr<metrics::MetricsStateManager> metrics_state_manager_; 70 std::unique_ptr<metrics::MetricsStateManager> metrics_state_manager_;
84 std::unique_ptr<metrics::MetricsService> metrics_service_; 71 std::unique_ptr<metrics::MetricsService> metrics_service_;
85 72
86 DISALLOW_COPY_AND_ASSIGN(AwMetricsServiceClient); 73 DISALLOW_COPY_AND_ASSIGN(AwMetricsServiceClientImpl);
87 }; 74 };
88 75
76 bool RegisterAwMetricsServiceClient(JNIEnv* env);
77
89 } // namespace android_webview 78 } // namespace android_webview
90 79
91 #endif // ANDROID_WEBVIEW_BROWSER_AW_METRICS_SERVICE_CLIENT_IMPL_H_ 80 #endif // ANDROID_WEBVIEW_NATIVE_AW_METRICS_SWITCH_
OLDNEW
« no previous file with comments | « android_webview/native/android_webview_jni_registrar.cc ('k') | android_webview/native/aw_metrics_service_client_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698