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