[email protected] | 5bdaa2d | 2014-05-19 14:59:51 | [diff] [blame] | 1 | // Copyright 2014 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 CHROME_BROWSER_METRICS_CHROME_METRICS_SERVICE_CLIENT_H_ |
| 6 | #define CHROME_BROWSER_METRICS_CHROME_METRICS_SERVICE_CLIENT_H_ |
| 7 | |
| 8 | #include <string> |
| 9 | |
| 10 | #include "base/basictypes.h" |
[email protected] | 4b4892b | 2014-05-22 15:06:15 | [diff] [blame] | 11 | #include "base/callback.h" |
| 12 | #include "base/memory/weak_ptr.h" |
[email protected] | d7ea39e | 2014-05-22 03:59:18 | [diff] [blame] | 13 | #include "base/threading/thread_checker.h" |
[email protected] | 7392942 | 2014-05-22 08:19:05 | [diff] [blame] | 14 | #include "chrome/browser/metrics/network_stats_uploader.h" |
[email protected] | 5bdaa2d | 2014-05-19 14:59:51 | [diff] [blame] | 15 | #include "components/metrics/metrics_service_client.h" |
[email protected] | d7ea39e | 2014-05-22 03:59:18 | [diff] [blame] | 16 | #include "content/public/browser/notification_observer.h" |
| 17 | #include "content/public/browser/notification_registrar.h" |
| 18 | |
| 19 | class MetricsService; |
[email protected] | 5bdaa2d | 2014-05-19 14:59:51 | [diff] [blame] | 20 | |
| 21 | // ChromeMetricsServiceClient provides an implementation of MetricsServiceClient |
| 22 | // that depends on chrome/. |
[email protected] | d7ea39e | 2014-05-22 03:59:18 | [diff] [blame] | 23 | class ChromeMetricsServiceClient : public metrics::MetricsServiceClient, |
| 24 | public content::NotificationObserver { |
[email protected] | 5bdaa2d | 2014-05-19 14:59:51 | [diff] [blame] | 25 | public: |
| 26 | ChromeMetricsServiceClient(); |
| 27 | virtual ~ChromeMetricsServiceClient(); |
| 28 | |
| 29 | // metrics::MetricsServiceClient: |
| 30 | virtual void SetClientID(const std::string& client_id) OVERRIDE; |
| 31 | virtual bool IsOffTheRecordSessionActive() OVERRIDE; |
| 32 | virtual std::string GetApplicationLocale() OVERRIDE; |
| 33 | virtual bool GetBrand(std::string* brand_code) OVERRIDE; |
| 34 | virtual metrics::SystemProfileProto::Channel GetChannel() OVERRIDE; |
| 35 | virtual std::string GetVersionString() OVERRIDE; |
[email protected] | 7392942 | 2014-05-22 08:19:05 | [diff] [blame] | 36 | virtual void OnLogUploadComplete() OVERRIDE; |
[email protected] | 4b4892b | 2014-05-22 15:06:15 | [diff] [blame] | 37 | virtual void CollectFinalMetrics(const base::Closure& done_callback) |
| 38 | OVERRIDE; |
[email protected] | 5bdaa2d | 2014-05-19 14:59:51 | [diff] [blame] | 39 | |
[email protected] | d7ea39e | 2014-05-22 03:59:18 | [diff] [blame] | 40 | // Stores a weak pointer to the given |service|. |
| 41 | // TODO(isherman): Fix the memory ownership model so that this method is not |
| 42 | // needed: http://crbug.com/375248 |
| 43 | void set_service(MetricsService* service) { service_ = service; } |
| 44 | |
[email protected] | 5bdaa2d | 2014-05-19 14:59:51 | [diff] [blame] | 45 | private: |
[email protected] | 4b4892b | 2014-05-22 15:06:15 | [diff] [blame] | 46 | // Callbacks for various stages of final log info collection. Do not call |
| 47 | // these directly. |
| 48 | void OnMemoryDetailCollectionDone(); |
| 49 | void OnHistogramSynchronizationDone(); |
| 50 | |
[email protected] | daed87e | 2014-05-22 19:41:22 | [diff] [blame^] | 51 | // Records metrics about the switches present on the command line. |
| 52 | void RecordCommandLineMetrics(); |
| 53 | |
[email protected] | d7ea39e | 2014-05-22 03:59:18 | [diff] [blame] | 54 | // Registers |this| as an observer for notifications which indicate that a |
| 55 | // user is performing work. This is useful to allow some features to sleep, |
| 56 | // until the machine becomes active, such as precluding UMA uploads unless |
| 57 | // there was recent activity. |
| 58 | void RegisterForNotifications(); |
| 59 | |
| 60 | // content::NotificationObserver: |
| 61 | virtual void Observe(int type, |
| 62 | const content::NotificationSource& source, |
| 63 | const content::NotificationDetails& details) OVERRIDE; |
| 64 | |
[email protected] | 4b4892b | 2014-05-22 15:06:15 | [diff] [blame] | 65 | base::ThreadChecker thread_checker_; |
| 66 | |
[email protected] | d7ea39e | 2014-05-22 03:59:18 | [diff] [blame] | 67 | // The MetricsService that |this| is a client of. Weak pointer. |
| 68 | MetricsService* service_; |
| 69 | |
| 70 | content::NotificationRegistrar registrar_; |
[email protected] | d7ea39e | 2014-05-22 03:59:18 | [diff] [blame] | 71 | |
[email protected] | 7392942 | 2014-05-22 08:19:05 | [diff] [blame] | 72 | NetworkStatsUploader network_stats_uploader_; |
| 73 | |
[email protected] | 4b4892b | 2014-05-22 15:06:15 | [diff] [blame] | 74 | // Saved callback received from CollectFinalMetrics(). |
| 75 | base::Closure collect_final_metrics_done_callback_; |
| 76 | |
| 77 | // Indicates that collect final metrics step is running. |
| 78 | bool waiting_for_collect_final_metrics_step_; |
| 79 | |
| 80 | // Number of async histogram fetch requests in progress. |
| 81 | int num_async_histogram_fetches_in_progress_; |
| 82 | |
| 83 | base::WeakPtrFactory<ChromeMetricsServiceClient> weak_ptr_factory_; |
| 84 | |
[email protected] | 5bdaa2d | 2014-05-19 14:59:51 | [diff] [blame] | 85 | DISALLOW_COPY_AND_ASSIGN(ChromeMetricsServiceClient); |
| 86 | }; |
| 87 | |
| 88 | #endif // CHROME_BROWSER_METRICS_CHROME_METRICS_SERVICE_CLIENT_H_ |