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

Side by Side Diff: chrome/browser/metrics/metrics_service.h

Issue 10830241: Inform GetEntropySource of whether or not metrics reporting will be enabled. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: thakis nit Created 8 years, 4 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
« no previous file with comments | « chrome/browser/chrome_browser_main.cc ('k') | chrome/browser/metrics/metrics_service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 10
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 // in tests only. 80 // in tests only.
81 void Start(); 81 void Start();
82 void StartRecordingOnly(); 82 void StartRecordingOnly();
83 void Stop(); 83 void Stop();
84 84
85 // Returns the client ID for this client, or the empty string if metrics 85 // Returns the client ID for this client, or the empty string if metrics
86 // recording is not currently running. 86 // recording is not currently running.
87 std::string GetClientId(); 87 std::string GetClientId();
88 88
89 // Returns the preferred entropy source used to seed persistent activities 89 // Returns the preferred entropy source used to seed persistent activities
90 // based on whether or not metrics reporting is permitted on this client. If 90 // based on whether or not metrics reporting will permitted on this client.
91 // it is permitted, this returns the client ID concatenated with the low 91 // The caller must determine if metrics reporting will be enabled for this
92 // entropy source. Otherwise, this just returns the low entropy source. 92 // client and pass that state in as |reporting_will_be_enabled|. If
93 std::string GetEntropySource(); 93 // |reporting_will_be_enabled| is true, this method returns the client ID
94 // concatenated with the low entropy source. Otherwise, this method just
95 // returns the low entropy source. Note that this reporting state can not be
96 // checked by reporting_active() because this method may need to be called
97 // before the MetricsService needs to be started.
98 std::string GetEntropySource(bool reporting_will_be_enabled);
94 99
95 // Force the client ID to be generated. This is useful in case it's needed 100 // Force the client ID to be generated. This is useful in case it's needed
96 // before recording. 101 // before recording.
97 void ForceClientIdCreation(); 102 void ForceClientIdCreation();
98 103
99 // At startup, prefs needs to be called with a list of all the pref names and 104 // At startup, prefs needs to be called with a list of all the pref names and
100 // types we'll be using. 105 // types we'll be using.
101 static void RegisterPrefs(PrefService* local_state); 106 static void RegisterPrefs(PrefService* local_state);
102 107
103 // Set up notifications which indicate that a user is performing work. This is 108 // Set up notifications which indicate that a user is performing work. This is
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 INITIAL_LOG_READY, // Initial log generated, and waiting for reply. 175 INITIAL_LOG_READY, // Initial log generated, and waiting for reply.
171 SENDING_OLD_LOGS, // Sending unsent logs from previous session. 176 SENDING_OLD_LOGS, // Sending unsent logs from previous session.
172 SENDING_CURRENT_LOGS, // Sending standard current logs as they acrue. 177 SENDING_CURRENT_LOGS, // Sending standard current logs as they acrue.
173 }; 178 };
174 179
175 enum ShutdownCleanliness { 180 enum ShutdownCleanliness {
176 CLEANLY_SHUTDOWN = 0xdeadbeef, 181 CLEANLY_SHUTDOWN = 0xdeadbeef,
177 NEED_TO_SHUTDOWN = ~CLEANLY_SHUTDOWN 182 NEED_TO_SHUTDOWN = ~CLEANLY_SHUTDOWN
178 }; 183 };
179 184
185 // Designates which entropy source was returned from this MetricsService.
186 // This is used for testing to validate that we return the correct source
187 // depending on the state of the service.
188 enum EntropySourceReturned {
189 LAST_ENTROPY_NONE,
190 LAST_ENTROPY_LOW,
191 LAST_ENTROPY_HIGH,
192 };
193
180 // First part of the init task. Called on the FILE thread to load hardware 194 // First part of the init task. Called on the FILE thread to load hardware
181 // class information. 195 // class information.
182 static void InitTaskGetHardwareClass(base::WeakPtr<MetricsService> self, 196 static void InitTaskGetHardwareClass(base::WeakPtr<MetricsService> self,
183 base::MessageLoopProxy* target_loop); 197 base::MessageLoopProxy* target_loop);
184 198
185 // Callback from InitTaskGetHardwareClass() that continues the init task by 199 // Callback from InitTaskGetHardwareClass() that continues the init task by
186 // loading plugin information. 200 // loading plugin information.
187 void OnInitTaskGotHardwareClass(const std::string& hardware_class); 201 void OnInitTaskGotHardwareClass(const std::string& hardware_class);
188 202
189 // Callback from PluginService::GetPlugins() that continues the init task by 203 // Callback from PluginService::GetPlugins() that continues the init task by
(...skipping 16 matching lines...) Expand all
206 const tracked_objects::ProcessDataSnapshot& process_data, 220 const tracked_objects::ProcessDataSnapshot& process_data,
207 content::ProcessType process_type) OVERRIDE; 221 content::ProcessType process_type) OVERRIDE;
208 // Callback that moves the state to INIT_TASK_DONE. 222 // Callback that moves the state to INIT_TASK_DONE.
209 virtual void FinishedReceivingProfilerData() OVERRIDE; 223 virtual void FinishedReceivingProfilerData() OVERRIDE;
210 224
211 // Returns the low entropy source for this client. This is a random value 225 // Returns the low entropy source for this client. This is a random value
212 // that is non-identifying amongst browser clients. This method will 226 // that is non-identifying amongst browser clients. This method will
213 // generate the entropy source value if it has not been called before. 227 // generate the entropy source value if it has not been called before.
214 int GetLowEntropySource(); 228 int GetLowEntropySource();
215 229
230 // Returns the last entropy source that was returned by this service since
231 // start up, or NONE if neither was returned yet. This is exposed for testing
232 // only.
233 EntropySourceReturned entropy_source_returned() const {
234 return entropy_source_returned_;
235 }
236
216 // When we start a new version of Chromium (different from our last run), we 237 // When we start a new version of Chromium (different from our last run), we
217 // need to discard the old crash stats so that we don't attribute crashes etc. 238 // need to discard the old crash stats so that we don't attribute crashes etc.
218 // in the old version to the current version (via current logs). 239 // in the old version to the current version (via current logs).
219 // Without this, a common reason to finally start a new version is to crash 240 // Without this, a common reason to finally start a new version is to crash
220 // the old version (after an autoupdate has arrived), and so we'd bias 241 // the old version (after an autoupdate has arrived), and so we'd bias
221 // initial results towards showing crashes :-(. 242 // initial results towards showing crashes :-(.
222 static void DiscardOldStabilityStats(PrefService* local_state); 243 static void DiscardOldStabilityStats(PrefService* local_state);
223 244
224 // Sets and gets whether metrics recording is active. 245 // Sets and gets whether metrics recording is active.
225 // SetRecording(false) also forces a persistent save of logging state (if 246 // SetRecording(false) also forces a persistent save of logging state (if
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 476
456 // Indicates that an asynchronous reporting step is running. 477 // Indicates that an asynchronous reporting step is running.
457 // This is used only for debugging. 478 // This is used only for debugging.
458 bool waiting_for_asynchronous_reporting_step_; 479 bool waiting_for_asynchronous_reporting_step_;
459 480
460 #if defined(OS_CHROMEOS) 481 #if defined(OS_CHROMEOS)
461 // The external metric service is used to log ChromeOS UMA events. 482 // The external metric service is used to log ChromeOS UMA events.
462 scoped_refptr<chromeos::ExternalMetrics> external_metrics_; 483 scoped_refptr<chromeos::ExternalMetrics> external_metrics_;
463 #endif 484 #endif
464 485
486 // The last entropy source returned by this service, used for testing.
487 EntropySourceReturned entropy_source_returned_;
488
465 // Reduntant marker to check that we completed our shutdown, and set the 489 // Reduntant marker to check that we completed our shutdown, and set the
466 // exited-cleanly bit in the prefs. 490 // exited-cleanly bit in the prefs.
467 static ShutdownCleanliness clean_shutdown_status_; 491 static ShutdownCleanliness clean_shutdown_status_;
468 492
469 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, ClientIdCorrectlyFormatted); 493 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, ClientIdCorrectlyFormatted);
470 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, IsPluginProcess); 494 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, IsPluginProcess);
495 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, CheckLowEntropySourceUsed);
496 FRIEND_TEST_ALL_PREFIXES(MetricsServiceReportingTest,
497 CheckHighEntropySourceUsed);
471 498
472 DISALLOW_COPY_AND_ASSIGN(MetricsService); 499 DISALLOW_COPY_AND_ASSIGN(MetricsService);
473 }; 500 };
474 501
475 // This class limits and documents access to the IsMetricsReportingEnabled() 502 // This class limits and documents access to the IsMetricsReportingEnabled()
476 // method. Since the method is private, each user has to be explicitly declared 503 // method. Since the method is private, each user has to be explicitly declared
477 // as a 'friend' below. 504 // as a 'friend' below.
478 class MetricsServiceHelper { 505 class MetricsServiceHelper {
479 private: 506 private:
480 friend bool prerender::IsOmniboxEnabled(Profile* profile); 507 friend bool prerender::IsOmniboxEnabled(Profile* profile);
481 friend class extensions::ExtensionDownloader; 508 friend class extensions::ExtensionDownloader;
482 509
483 // Returns true if prefs::kMetricsReportingEnabled is set. 510 // Returns true if prefs::kMetricsReportingEnabled is set.
484 static bool IsMetricsReportingEnabled(); 511 static bool IsMetricsReportingEnabled();
485 512
486 DISALLOW_IMPLICIT_CONSTRUCTORS(MetricsServiceHelper); 513 DISALLOW_IMPLICIT_CONSTRUCTORS(MetricsServiceHelper);
487 }; 514 };
488 515
489 #endif // CHROME_BROWSER_METRICS_METRICS_SERVICE_H_ 516 #endif // CHROME_BROWSER_METRICS_METRICS_SERVICE_H_
OLDNEW
« no previous file with comments | « chrome/browser/chrome_browser_main.cc ('k') | chrome/browser/metrics/metrics_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698