OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // This file defines a service that collects information about the user | 5 // This file defines a service that collects information about the user |
6 // experience in order to help improve future versions of the app. | 6 // experience in order to help improve future versions of the app. |
7 | 7 |
8 #ifndef CHROME_BROWSER_METRICS_METRICS_SERVICE_H_ | 8 #ifndef CHROME_BROWSER_METRICS_METRICS_SERVICE_H_ |
9 #define CHROME_BROWSER_METRICS_METRICS_SERVICE_H_ | 9 #define CHROME_BROWSER_METRICS_METRICS_SERVICE_H_ |
10 #pragma once | 10 #pragma once |
11 | 11 |
12 #include <map> | 12 #include <map> |
13 #include <string> | 13 #include <string> |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
16 #include "base/basictypes.h" | 16 #include "base/basictypes.h" |
17 #include "base/gtest_prod_util.h" | 17 #include "base/gtest_prod_util.h" |
| 18 #include "base/memory/weak_ptr.h" |
18 #include "base/memory/scoped_ptr.h" | 19 #include "base/memory/scoped_ptr.h" |
19 #include "base/memory/weak_ptr.h" | 20 #include "base/memory/weak_ptr.h" |
20 #include "base/process_util.h" | 21 #include "base/process_util.h" |
21 #include "chrome/browser/metrics/tracking_synchronizer_observer.h" | |
22 #include "chrome/common/metrics/metrics_service_base.h" | 22 #include "chrome/common/metrics/metrics_service_base.h" |
| 23 #include "content/public/common/process_type.h" |
| 24 #include "content/public/common/url_fetcher_delegate.h" |
23 #include "content/public/browser/notification_observer.h" | 25 #include "content/public/browser/notification_observer.h" |
24 #include "content/public/browser/notification_registrar.h" | 26 #include "content/public/browser/notification_registrar.h" |
25 #include "content/public/common/url_fetcher_delegate.h" | |
26 | 27 |
27 #if defined(OS_CHROMEOS) | 28 #if defined(OS_CHROMEOS) |
28 #include "chrome/browser/chromeos/external_metrics.h" | 29 #include "chrome/browser/chromeos/external_metrics.h" |
29 #endif | 30 #endif |
30 | 31 |
31 class BookmarkModel; | 32 class BookmarkModel; |
32 class BookmarkNode; | 33 class BookmarkNode; |
33 class MetricsLog; | |
34 class MetricsReportingScheduler; | 34 class MetricsReportingScheduler; |
35 class PrefService; | 35 class PrefService; |
36 class Profile; | 36 class Profile; |
37 class TemplateURLService; | 37 class TemplateURLService; |
38 | 38 |
39 namespace base { | 39 namespace base { |
40 class DictionaryValue; | 40 class DictionaryValue; |
41 class MessageLoopProxy; | 41 class MessageLoopProxy; |
42 } | 42 } |
43 | 43 |
44 namespace content { | 44 namespace content { |
45 class RenderProcessHost; | 45 class RenderProcessHost; |
46 } | 46 } |
47 | 47 |
48 namespace extensions { | 48 namespace extensions { |
49 class ExtensionDownloader; | 49 class ExtensionDownloader; |
50 } | 50 } |
51 | 51 |
52 namespace prerender { | 52 namespace prerender { |
53 bool IsOmniboxEnabled(Profile* profile); | 53 bool IsOmniboxEnabled(Profile* profile); |
54 } | 54 } |
55 | 55 |
56 namespace tracked_objects { | |
57 struct ProcessDataSnapshot; | |
58 } | |
59 | |
60 namespace webkit { | 56 namespace webkit { |
61 struct WebPluginInfo; | 57 struct WebPluginInfo; |
62 } | 58 } |
63 | 59 |
64 class MetricsService | 60 |
65 : public chrome_browser_metrics::TrackingSynchronizerObserver, | 61 class MetricsService : public content::NotificationObserver, |
66 public content::NotificationObserver, | 62 public content::URLFetcherDelegate, |
67 public content::URLFetcherDelegate, | 63 public MetricsServiceBase { |
68 public MetricsServiceBase { | |
69 public: | 64 public: |
70 MetricsService(); | 65 MetricsService(); |
71 virtual ~MetricsService(); | 66 virtual ~MetricsService(); |
72 | 67 |
73 // Start/stop the metrics recording and uploading machine. These should be | 68 // Start/stop the metrics recording and uploading machine. These should be |
74 // used on startup and when the user clicks the checkbox in the prefs. | 69 // used on startup and when the user clicks the checkbox in the prefs. |
75 // StartRecordingOnly starts the metrics recording but not reporting, for use | 70 // StartRecordingOnly starts the metrics recording but not reporting, for use |
76 // in tests only. | 71 // in tests only. |
77 void Start(); | 72 void Start(); |
78 void StartRecordingOnly(); | 73 void StartRecordingOnly(); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 | 154 |
160 // First part of the init task. Called on the FILE thread to load hardware | 155 // First part of the init task. Called on the FILE thread to load hardware |
161 // class information. | 156 // class information. |
162 static void InitTaskGetHardwareClass(base::WeakPtr<MetricsService> self, | 157 static void InitTaskGetHardwareClass(base::WeakPtr<MetricsService> self, |
163 base::MessageLoopProxy* target_loop); | 158 base::MessageLoopProxy* target_loop); |
164 | 159 |
165 // Callback from InitTaskGetHardwareClass() that continues the init task by | 160 // Callback from InitTaskGetHardwareClass() that continues the init task by |
166 // loading plugin information. | 161 // loading plugin information. |
167 void OnInitTaskGotHardwareClass(const std::string& hardware_class); | 162 void OnInitTaskGotHardwareClass(const std::string& hardware_class); |
168 | 163 |
169 // Callback from PluginService::GetPlugins() that continues the init task by | 164 // Callback from PluginService::GetPlugins() that moves the state to |
170 // loading profiler data. | 165 // INIT_TASK_DONE. |
171 void OnInitTaskGotPluginInfo( | 166 void OnInitTaskGotPluginInfo( |
172 const std::vector<webkit::WebPluginInfo>& plugins); | 167 const std::vector<webkit::WebPluginInfo>& plugins); |
173 | 168 |
174 // TrackingSynchronizerObserver: | |
175 virtual void ReceivedProfilerData( | |
176 const tracked_objects::ProcessDataSnapshot& process_data, | |
177 content::ProcessType process_type) OVERRIDE; | |
178 // Callback that moves the state to INIT_TASK_DONE. | |
179 virtual void FinishedReceivingProfilerData() OVERRIDE; | |
180 | |
181 // When we start a new version of Chromium (different from our last run), we | 169 // When we start a new version of Chromium (different from our last run), we |
182 // need to discard the old crash stats so that we don't attribute crashes etc. | 170 // need to discard the old crash stats so that we don't attribute crashes etc. |
183 // in the old version to the current version (via current logs). | 171 // in the old version to the current version (via current logs). |
184 // Without this, a common reason to finally start a new version is to crash | 172 // Without this, a common reason to finally start a new version is to crash |
185 // the old version (after an autoupdate has arrived), and so we'd bias | 173 // the old version (after an autoupdate has arrived), and so we'd bias |
186 // initial results towards showing crashes :-(. | 174 // initial results towards showing crashes :-(. |
187 static void DiscardOldStabilityStats(PrefService* local_state); | 175 static void DiscardOldStabilityStats(PrefService* local_state); |
188 | 176 |
189 // Sets and gets whether metrics recording is active. | 177 // Sets and gets whether metrics recording is active. |
190 // SetRecording(false) also forces a persistent save of logging state (if | 178 // SetRecording(false) also forces a persistent save of logging state (if |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 | 340 |
353 // Chrome OS hardware class (e.g., hardware qualification ID). This | 341 // Chrome OS hardware class (e.g., hardware qualification ID). This |
354 // class identifies the configured system components such as CPU, | 342 // class identifies the configured system components such as CPU, |
355 // WiFi adapter, etc. For non Chrome OS hosts, this will be an | 343 // WiFi adapter, etc. For non Chrome OS hosts, this will be an |
356 // empty string. | 344 // empty string. |
357 std::string hardware_class_; | 345 std::string hardware_class_; |
358 | 346 |
359 // The list of plugins which was retrieved on the file thread. | 347 // The list of plugins which was retrieved on the file thread. |
360 std::vector<webkit::WebPluginInfo> plugins_; | 348 std::vector<webkit::WebPluginInfo> plugins_; |
361 | 349 |
362 // The initial log, used to record startup metrics. | |
363 scoped_ptr<MetricsLog> initial_log_; | |
364 | |
365 // The outstanding transmission appears as a URL Fetch operation. | 350 // The outstanding transmission appears as a URL Fetch operation. |
366 scoped_ptr<content::URLFetcher> current_fetch_xml_; | 351 scoped_ptr<content::URLFetcher> current_fetch_xml_; |
367 scoped_ptr<content::URLFetcher> current_fetch_proto_; | 352 scoped_ptr<content::URLFetcher> current_fetch_proto_; |
368 | 353 |
369 // Cached responses from the XML request while we wait for a response to the | 354 // Cached responses from the XML request while we wait for a response to the |
370 // protubuf request. | 355 // protubuf request. |
371 int response_code_; | 356 int response_code_; |
372 std::string response_status_; | 357 std::string response_status_; |
373 std::string response_data_; | 358 std::string response_data_; |
374 | 359 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 friend bool prerender::IsOmniboxEnabled(Profile* profile); | 432 friend bool prerender::IsOmniboxEnabled(Profile* profile); |
448 friend class extensions::ExtensionDownloader; | 433 friend class extensions::ExtensionDownloader; |
449 | 434 |
450 // Returns true if prefs::kMetricsReportingEnabled is set. | 435 // Returns true if prefs::kMetricsReportingEnabled is set. |
451 static bool IsMetricsReportingEnabled(); | 436 static bool IsMetricsReportingEnabled(); |
452 | 437 |
453 DISALLOW_IMPLICIT_CONSTRUCTORS(MetricsServiceHelper); | 438 DISALLOW_IMPLICIT_CONSTRUCTORS(MetricsServiceHelper); |
454 }; | 439 }; |
455 | 440 |
456 #endif // CHROME_BROWSER_METRICS_METRICS_SERVICE_H_ | 441 #endif // CHROME_BROWSER_METRICS_METRICS_SERVICE_H_ |
OLD | NEW |