blob: 220102f274fa75b338e2852f01e92195f3b2dda0 [file] [log] [blame]
license.botbf09a502008-08-24 00:55:551// Copyright (c) 2006-2008 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.
initial.commit09911bf2008-07-26 23:55:294
5
6
7//------------------------------------------------------------------------------
8// Description of the life cycle of a instance of MetricsService.
9//
10// OVERVIEW
11//
12// A MetricsService instance is typically created at application startup. It
13// is the central controller for the acquisition of log data, and the automatic
14// transmission of that log data to an external server. Its major job is to
15// manage logs, grouping them for transmission, and transmitting them. As part
16// of its grouping, MS finalizes logs by including some just-in-time gathered
17// memory statistics, snapshotting the current stats of numerous histograms,
18// closing the logs, translating to XML text, and compressing the results for
19// transmission. Transmission includes submitting a compressed log as data in a
[email protected]281d2882009-01-20 20:32:4220// URL-post, and retransmitting (or retaining at process termination) if the
initial.commit09911bf2008-07-26 23:55:2921// attempted transmission failed. Retention across process terminations is done
22// using the the PrefServices facilities. The format for the retained
23// logs (ones that never got transmitted) is always the uncompressed textual
24// representation.
25//
[email protected]281d2882009-01-20 20:32:4226// Logs fall into one of two categories: "initial logs," and "ongoing logs."
27// There is at most one initial log sent for each complete run of the chromium
initial.commit09911bf2008-07-26 23:55:2928// product (from startup, to browser shutdown). An initial log is generally
29// transmitted some short time (1 minute?) after startup, and includes stats
30// such as recent crash info, the number and types of plugins, etc. The
[email protected]281d2882009-01-20 20:32:4231// external server's response to the initial log conceptually tells this MS if
32// it should continue transmitting logs (during this session). The server
33// response can actually be much more detailed, and always includes (at a
34// minimum) how often additional ongoing logs should be sent.
initial.commit09911bf2008-07-26 23:55:2935//
36// After the above initial log, a series of ongoing logs will be transmitted.
37// The first ongoing log actually begins to accumulate information stating when
38// the MS was first constructed. Note that even though the initial log is
39// commonly sent a full minute after startup, the initial log does not include
40// much in the way of user stats. The most common interlog period (delay)
[email protected]0b33f80b2008-12-17 21:34:3641// is 20 minutes. That time period starts when the first user action causes a
initial.commit09911bf2008-07-26 23:55:2942// logging event. This means that if there is no user action, there may be long
[email protected]281d2882009-01-20 20:32:4243// periods without any (ongoing) log transmissions. Ongoing logs typically
initial.commit09911bf2008-07-26 23:55:2944// contain very detailed records of user activities (ex: opened tab, closed
45// tab, fetched URL, maximized window, etc.) In addition, just before an
46// ongoing log is closed out, a call is made to gather memory statistics. Those
47// memory statistics are deposited into a histogram, and the log finalization
48// code is then called. In the finalization, a call to a Histogram server
49// acquires a list of all local histograms that have been flagged for upload
[email protected]281d2882009-01-20 20:32:4250// to the UMA server. The finalization also acquires a the most recent number
51// of page loads, along with any counts of renderer or plugin crashes.
initial.commit09911bf2008-07-26 23:55:2952//
53// When the browser shuts down, there will typically be a fragment of an ongoing
54// log that has not yet been transmitted. At shutdown time, that fragment
55// is closed (including snapshotting histograms), and converted to text. Note
56// that memory stats are not gathered during shutdown, as gathering *might* be
57// too time consuming. The textual representation of the fragment of the
58// ongoing log is then stored persistently as a string in the PrefServices, for
59// potential transmission during a future run of the product.
60//
61// There are two slightly abnormal shutdown conditions. There is a
62// "disconnected scenario," and a "really fast startup and shutdown" scenario.
63// In the "never connected" situation, the user has (during the running of the
64// process) never established an internet connection. As a result, attempts to
65// transmit the initial log have failed, and a lot(?) of data has accumulated in
66// the ongoing log (which didn't yet get closed, because there was never even a
67// contemplation of sending it). There is also a kindred "lost connection"
68// situation, where a loss of connection prevented an ongoing log from being
69// transmitted, and a (still open) log was stuck accumulating a lot(?) of data,
70// while the earlier log retried its transmission. In both of these
71// disconnected situations, two logs need to be, and are, persistently stored
72// for future transmission.
73//
74// The other unusual shutdown condition, termed "really fast startup and
75// shutdown," involves the deliberate user termination of the process before
76// the initial log is even formed or transmitted. In that situation, no logging
77// is done, but the historical crash statistics remain (unlogged) for inclusion
78// in a future run's initial log. (i.e., we don't lose crash stats).
79//
80// With the above overview, we can now describe the state machine's various
81// stats, based on the State enum specified in the state_ member. Those states
82// are:
83//
84// INITIALIZED, // Constructor was called.
[email protected]28ab7f92009-01-06 21:39:0485// PLUGIN_LIST_REQUESTED, // Waiting for plugin list to be loaded.
initial.commit09911bf2008-07-26 23:55:2986// PLUGIN_LIST_ARRIVED, // Waiting for timer to send initial log.
87// INITIAL_LOG_READY, // Initial log generated, and waiting for reply.
88// SEND_OLD_INITIAL_LOGS, // Sending unsent logs from previous session.
89// SENDING_OLD_LOGS, // Sending unsent logs from previous session.
90// SENDING_CURRENT_LOGS, // Sending standard current logs as they accrue.
91//
92// In more detail, we have:
93//
94// INITIALIZED, // Constructor was called.
95// The MS has been constructed, but has taken no actions to compose the
96// initial log.
97//
[email protected]28ab7f92009-01-06 21:39:0498// PLUGIN_LIST_REQUESTED, // Waiting for plugin list to be loaded.
initial.commit09911bf2008-07-26 23:55:2999// Typically about 30 seconds after startup, a task is sent to a second thread
100// to get the list of plugins. That task will (when complete) make an async
101// callback (via a Task) to indicate the completion.
102//
103// PLUGIN_LIST_ARRIVED, // Waiting for timer to send initial log.
104// The callback has arrived, and it is now possible for an initial log to be
105// created. This callback typically arrives back less than one second after
106// the task is dispatched.
107//
108// INITIAL_LOG_READY, // Initial log generated, and waiting for reply.
109// This state is entered only after an initial log has been composed, and
110// prepared for transmission. It is also the case that any previously unsent
111// logs have been loaded into instance variables for possible transmission.
112//
113// SEND_OLD_INITIAL_LOGS, // Sending unsent logs from previous session.
114// This state indicates that the initial log for this session has been
115// successfully sent and it is now time to send any "initial logs" that were
116// saved from previous sessions. Most commonly, there are none, but all old
117// logs that were "initial logs" must be sent before this state is exited.
118//
119// SENDING_OLD_LOGS, // Sending unsent logs from previous session.
120// This state indicates that there are no more unsent initial logs, and now any
121// ongoing logs from previous sessions should be transmitted. All such logs
122// will be transmitted before exiting this state, and proceeding with ongoing
123// logs from the current session (see next state).
124//
125// SENDING_CURRENT_LOGS, // Sending standard current logs as they accrue.
[email protected]0b33f80b2008-12-17 21:34:36126// Current logs are being accumulated. Typically every 20 minutes a log is
initial.commit09911bf2008-07-26 23:55:29127// closed and finalized for transmission, at the same time as a new log is
128// started.
129//
130// The progression through the above states is simple, and sequential, in the
131// most common use cases. States proceed from INITIAL to SENDING_CURRENT_LOGS,
132// and remain in the latter until shutdown.
133//
134// The one unusual case is when the user asks that we stop logging. When that
135// happens, any pending (transmission in progress) log is pushed into the list
136// of old unsent logs (the appropriate list, depending on whether it is an
137// initial log, or an ongoing log). An addition, any log that is currently
138// accumulating is also finalized, and pushed into the unsent log list. With
[email protected]281d2882009-01-20 20:32:42139// those pushes performed, we regress back to the SEND_OLD_INITIAL_LOGS state in
initial.commit09911bf2008-07-26 23:55:29140// case the user enables log recording again during this session. This way
141// anything we have "pushed back" will be sent automatically if/when we progress
142// back to SENDING_CURRENT_LOG state.
143//
144// Also note that whenever the member variables containing unsent logs are
145// modified (i.e., when we send an old log), we mirror the list of logs into
146// the PrefServices. This ensures that IF we crash, we won't start up and
147// retransmit our old logs again.
148//
149// Due to race conditions, it is always possible that a log file could be sent
150// twice. For example, if a log file is sent, but not yet acknowledged by
151// the external server, and the user shuts down, then a copy of the log may be
152// saved for re-transmission. These duplicates could be filtered out server
[email protected]281d2882009-01-20 20:32:42153// side, but are not expected to be a significant problem.
initial.commit09911bf2008-07-26 23:55:29154//
155//
156//------------------------------------------------------------------------------
157
[email protected]40bcc302009-03-02 20:50:39158#include "chrome/browser/metrics/metrics_service.h"
159
[email protected]dc6f4962009-02-13 01:25:50160#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:29161#include <windows.h>
[email protected]40bcc302009-03-02 20:50:39162#include <objbase.h>
[email protected]dc6f4962009-02-13 01:25:50163#endif
initial.commit09911bf2008-07-26 23:55:29164
[email protected]690a99c2009-01-06 16:48:45165#include "base/file_path.h"
initial.commit09911bf2008-07-26 23:55:29166#include "base/histogram.h"
167#include "base/path_service.h"
[email protected]dc6f4962009-02-13 01:25:50168#include "base/platform_thread.h"
initial.commit09911bf2008-07-26 23:55:29169#include "base/string_util.h"
170#include "base/task.h"
[email protected]d8e41ed2008-09-11 15:22:32171#include "chrome/browser/bookmarks/bookmark_model.h"
initial.commit09911bf2008-07-26 23:55:29172#include "chrome/browser/browser.h"
173#include "chrome/browser/browser_list.h"
174#include "chrome/browser/browser_process.h"
175#include "chrome/browser/load_notification_details.h"
176#include "chrome/browser/memory_details.h"
[email protected]fd49e2d2009-02-20 17:21:30177#include "chrome/browser/plugin_service.h"
initial.commit09911bf2008-07-26 23:55:29178#include "chrome/browser/profile.h"
[email protected]8c8657d62009-01-16 18:31:26179#include "chrome/browser/renderer_host/render_process_host.h"
[email protected]d54e03a52009-01-16 00:31:04180#include "chrome/browser/search_engines/template_url.h"
181#include "chrome/browser/search_engines/template_url_model.h"
[email protected]a27a9382009-02-11 23:55:10182#include "chrome/common/child_process_info.h"
initial.commit09911bf2008-07-26 23:55:29183#include "chrome/common/chrome_paths.h"
[email protected]252873ef2008-08-04 21:59:45184#include "chrome/common/libxml_utils.h"
[email protected]bfd04a62009-02-01 18:16:56185#include "chrome/common/notification_service.h"
initial.commit09911bf2008-07-26 23:55:29186#include "chrome/common/pref_names.h"
187#include "chrome/common/pref_service.h"
[email protected]e09ba552009-02-05 03:26:29188#include "chrome/common/render_messages.h"
initial.commit09911bf2008-07-26 23:55:29189#include "googleurl/src/gurl.h"
190#include "net/base/load_flags.h"
191#include "third_party/bzip2/bzlib.h"
192
[email protected]dc6f4962009-02-13 01:25:50193#if defined(OS_POSIX)
194// TODO(port): Move these headers above as they are ported.
195#include "chrome/common/temp_scaffolding_stubs.h"
196#else
[email protected]dc6f4962009-02-13 01:25:50197#include "chrome/installer/util/google_update_settings.h"
198#endif
199
[email protected]e1acf6f2008-10-27 20:43:33200using base::Time;
201using base::TimeDelta;
202
initial.commit09911bf2008-07-26 23:55:29203// Check to see that we're being called on only one thread.
204static bool IsSingleThreaded();
205
206static const char kMetricsURL[] =
[email protected]0acdfc42009-01-30 01:13:22207 "https://clients4.google.com/firefox/metrics/collect";
initial.commit09911bf2008-07-26 23:55:29208
209static const char kMetricsType[] = "application/vnd.mozilla.metrics.bz2";
210
211// The delay, in seconds, after startup before sending the first log message.
[email protected]252873ef2008-08-04 21:59:45212static const int kInitialInterlogDuration = 60; // one minute
213
214// The default maximum number of events in a log uploaded to the UMA server.
[email protected]0b33f80b2008-12-17 21:34:36215static const int kInitialEventLimit = 2400;
[email protected]68475e602008-08-22 03:21:15216
217// If an upload fails, and the transmission was over this byte count, then we
218// will discard the log, and not try to retransmit it. We also don't persist
219// the log to the prefs for transmission during the next chrome session if this
220// limit is exceeded.
221static const int kUploadLogAvoidRetransmitSize = 50000;
initial.commit09911bf2008-07-26 23:55:29222
223// When we have logs from previous Chrome sessions to send, how long should we
224// delay (in seconds) between each log transmission.
225static const int kUnsentLogDelay = 15; // 15 seconds
226
227// Minimum time a log typically exists before sending, in seconds.
228// This number is supplied by the server, but until we parse it out of a server
229// response, we use this duration to specify how long we should wait before
230// sending the next log. If the channel is busy, such as when there is a
231// failure during an attempt to transmit a previous log, then a log may wait
232// (and continue to accrue now log entries) for a much greater period of time.
[email protected]0eb34fee2009-01-21 08:04:38233static const int kMinSecondsPerLog = 20 * 60; // Twenty minutes.
initial.commit09911bf2008-07-26 23:55:29234
initial.commit09911bf2008-07-26 23:55:29235// When we don't succeed at transmitting a log to a server, we progressively
236// wait longer and longer before sending the next log. This backoff process
237// help reduce load on the server, and makes the amount of backoff vary between
238// clients so that a collision (server overload?) on retransmit is less likely.
239// The following is the constant we use to expand that inter-log duration.
240static const double kBackoff = 1.1;
241// We limit the maximum backoff to be no greater than some multiple of the
242// default kMinSecondsPerLog. The following is that maximum ratio.
243static const int kMaxBackoff = 10;
244
245// Interval, in seconds, between state saves.
246static const int kSaveStateInterval = 5 * 60; // five minutes
247
248// The number of "initial" logs we're willing to save, and hope to send during
249// a future Chrome session. Initial logs contain crash stats, and are pretty
250// small.
251static const size_t kMaxInitialLogsPersisted = 20;
252
253// The number of ongoing logs we're willing to save persistently, and hope to
[email protected]281d2882009-01-20 20:32:42254// send during a this or future sessions. Note that each log may be pretty
initial.commit09911bf2008-07-26 23:55:29255// large, as presumably the related "initial" log wasn't sent (probably nothing
256// was, as the user was probably off-line). As a result, the log probably kept
257// accumulating while the "initial" log was stalled (pending_), and couldn't be
258// sent. As a result, we don't want to save too many of these mega-logs.
259// A "standard shutdown" will create a small log, including just the data that
260// was not yet been transmitted, and that is normal (to have exactly one
261// ongoing_log_ at startup).
[email protected]281d2882009-01-20 20:32:42262static const size_t kMaxOngoingLogsPersisted = 8;
initial.commit09911bf2008-07-26 23:55:29263
264
265// Handles asynchronous fetching of memory details.
266// Will run the provided task after finished.
267class MetricsMemoryDetails : public MemoryDetails {
268 public:
269 explicit MetricsMemoryDetails(Task* completion) : completion_(completion) {}
270
271 virtual void OnDetailsAvailable() {
272 MessageLoop::current()->PostTask(FROM_HERE, completion_);
273 }
274
275 private:
276 Task* completion_;
277 DISALLOW_EVIL_CONSTRUCTORS(MetricsMemoryDetails);
278};
279
280class MetricsService::GetPluginListTaskComplete : public Task {
281 virtual void Run() {
282 g_browser_process->metrics_service()->OnGetPluginListTaskComplete();
283 }
284};
285
286class MetricsService::GetPluginListTask : public Task {
287 public:
288 explicit GetPluginListTask(MessageLoop* callback_loop)
289 : callback_loop_(callback_loop) {}
290
291 virtual void Run() {
292 std::vector<WebPluginInfo> plugins;
293 PluginService::GetInstance()->GetPlugins(false, &plugins);
294
295 callback_loop_->PostTask(FROM_HERE, new GetPluginListTaskComplete());
296 }
297
298 private:
299 MessageLoop* callback_loop_;
300};
301
302// static
303void MetricsService::RegisterPrefs(PrefService* local_state) {
304 DCHECK(IsSingleThreaded());
305 local_state->RegisterStringPref(prefs::kMetricsClientID, L"");
[email protected]0bb1a622009-03-04 03:22:32306 local_state->RegisterInt64Pref(prefs::kMetricsClientIDTimestamp, 0);
307 local_state->RegisterInt64Pref(prefs::kStabilityLaunchTimeSec, 0);
308 local_state->RegisterInt64Pref(prefs::kStabilityLastTimestampSec, 0);
309 local_state->RegisterInt64Pref(prefs::kStabilityUptimeSec, 0);
[email protected]541f77922009-02-23 21:14:38310 local_state->RegisterStringPref(prefs::kStabilityStatsVersion, L"");
initial.commit09911bf2008-07-26 23:55:29311 local_state->RegisterBooleanPref(prefs::kStabilityExitedCleanly, true);
312 local_state->RegisterBooleanPref(prefs::kStabilitySessionEndCompleted, true);
313 local_state->RegisterIntegerPref(prefs::kMetricsSessionID, -1);
314 local_state->RegisterIntegerPref(prefs::kStabilityLaunchCount, 0);
315 local_state->RegisterIntegerPref(prefs::kStabilityCrashCount, 0);
316 local_state->RegisterIntegerPref(prefs::kStabilityIncompleteSessionEndCount,
317 0);
318 local_state->RegisterIntegerPref(prefs::kStabilityPageLoadCount, 0);
319 local_state->RegisterIntegerPref(prefs::kSecurityRendererOnSboxDesktop, 0);
320 local_state->RegisterIntegerPref(prefs::kSecurityRendererOnDefaultDesktop, 0);
321 local_state->RegisterIntegerPref(prefs::kStabilityRendererCrashCount, 0);
322 local_state->RegisterIntegerPref(prefs::kStabilityRendererHangCount, 0);
[email protected]e73c01972008-08-13 00:18:24323 local_state->RegisterIntegerPref(prefs::kStabilityBreakpadRegistrationFail,
324 0);
325 local_state->RegisterIntegerPref(prefs::kStabilityBreakpadRegistrationSuccess,
326 0);
327 local_state->RegisterIntegerPref(prefs::kStabilityDebuggerPresent, 0);
328 local_state->RegisterIntegerPref(prefs::kStabilityDebuggerNotPresent, 0);
329
initial.commit09911bf2008-07-26 23:55:29330 local_state->RegisterDictionaryPref(prefs::kProfileMetrics);
331 local_state->RegisterIntegerPref(prefs::kNumBookmarksOnBookmarkBar, 0);
332 local_state->RegisterIntegerPref(prefs::kNumFoldersOnBookmarkBar, 0);
333 local_state->RegisterIntegerPref(prefs::kNumBookmarksInOtherBookmarkFolder,
334 0);
335 local_state->RegisterIntegerPref(prefs::kNumFoldersInOtherBookmarkFolder, 0);
336 local_state->RegisterIntegerPref(prefs::kNumKeywords, 0);
337 local_state->RegisterListPref(prefs::kMetricsInitialLogs);
338 local_state->RegisterListPref(prefs::kMetricsOngoingLogs);
[email protected]0bb1a622009-03-04 03:22:32339
340 local_state->RegisterInt64Pref(prefs::kUninstallMetricsPageLoadCount, 0);
341 local_state->RegisterInt64Pref(prefs::kUninstallLaunchCount, 0);
342 local_state->RegisterInt64Pref(prefs::kUninstallMetricsUptimeSec, 0);
343 local_state->RegisterInt64Pref(prefs::kUninstallLastLaunchTimeSec, 0);
344 local_state->RegisterInt64Pref(prefs::kUninstallLastObservedRunTimeSec, 0);
initial.commit09911bf2008-07-26 23:55:29345}
346
[email protected]541f77922009-02-23 21:14:38347// static
348void MetricsService::DiscardOldStabilityStats(PrefService* local_state) {
349 local_state->SetBoolean(prefs::kStabilityExitedCleanly, true);
350
351 local_state->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0);
352 local_state->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0);
353 local_state->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0);
354 local_state->SetInteger(prefs::kStabilityDebuggerPresent, 0);
355 local_state->SetInteger(prefs::kStabilityDebuggerNotPresent, 0);
356
357 local_state->SetInteger(prefs::kStabilityLaunchCount, 0);
358 local_state->SetInteger(prefs::kStabilityCrashCount, 0);
359
360 local_state->SetInteger(prefs::kStabilityPageLoadCount, 0);
361 local_state->SetInteger(prefs::kStabilityRendererCrashCount, 0);
362 local_state->SetInteger(prefs::kStabilityRendererHangCount, 0);
363
364 local_state->SetInteger(prefs::kSecurityRendererOnSboxDesktop, 0);
365 local_state->SetInteger(prefs::kSecurityRendererOnDefaultDesktop, 0);
366
367 local_state->SetString(prefs::kStabilityUptimeSec, L"0");
368
369 local_state->ClearPref(prefs::kStabilityPluginStats);
370}
371
initial.commit09911bf2008-07-26 23:55:29372MetricsService::MetricsService()
[email protected]d01b8732008-10-16 02:18:07373 : recording_active_(false),
374 reporting_active_(false),
375 user_permits_upload_(false),
376 server_permits_upload_(true),
377 state_(INITIALIZED),
initial.commit09911bf2008-07-26 23:55:29378 pending_log_(NULL),
379 pending_log_text_(""),
380 current_fetch_(NULL),
381 current_log_(NULL),
[email protected]d01b8732008-10-16 02:18:07382 idle_since_last_transmission_(false),
initial.commit09911bf2008-07-26 23:55:29383 next_window_id_(0),
[email protected]40bcc302009-03-02 20:50:39384 ALLOW_THIS_IN_INITIALIZER_LIST(log_sender_factory_(this)),
385 ALLOW_THIS_IN_INITIALIZER_LIST(state_saver_factory_(this)),
initial.commit09911bf2008-07-26 23:55:29386 logged_samples_(),
[email protected]252873ef2008-08-04 21:59:45387 interlog_duration_(TimeDelta::FromSeconds(kInitialInterlogDuration)),
[email protected]d01b8732008-10-16 02:18:07388 log_event_limit_(kInitialEventLimit),
initial.commit09911bf2008-07-26 23:55:29389 timer_pending_(false) {
390 DCHECK(IsSingleThreaded());
391 InitializeMetricsState();
392}
393
394MetricsService::~MetricsService() {
395 SetRecording(false);
[email protected]d8bc79bf2009-01-28 01:17:58396 if (pending_log_) {
397 delete pending_log_;
398 pending_log_ = NULL;
399 }
400 if (current_log_) {
401 delete current_log_;
402 current_log_ = NULL;
403 }
initial.commit09911bf2008-07-26 23:55:29404}
405
[email protected]d01b8732008-10-16 02:18:07406void MetricsService::SetUserPermitsUpload(bool enabled) {
407 HandleIdleSinceLastTransmission(false);
408 user_permits_upload_ = enabled;
409}
410
411void MetricsService::Start() {
412 SetRecording(true);
413 SetReporting(true);
414}
415
416void MetricsService::StartRecordingOnly() {
417 SetRecording(true);
418 SetReporting(false);
419}
420
421void MetricsService::Stop() {
422 SetReporting(false);
423 SetRecording(false);
424}
425
initial.commit09911bf2008-07-26 23:55:29426void MetricsService::SetRecording(bool enabled) {
427 DCHECK(IsSingleThreaded());
428
[email protected]d01b8732008-10-16 02:18:07429 if (enabled == recording_active_)
initial.commit09911bf2008-07-26 23:55:29430 return;
431
432 if (enabled) {
433 StartRecording();
434 ListenerRegistration(true);
435 } else {
436 // Turn off all observers.
437 ListenerRegistration(false);
438 PushPendingLogsToUnsentLists();
439 DCHECK(!pending_log());
440 if (state_ > INITIAL_LOG_READY && unsent_logs())
441 state_ = SEND_OLD_INITIAL_LOGS;
442 }
[email protected]d01b8732008-10-16 02:18:07443 recording_active_ = enabled;
initial.commit09911bf2008-07-26 23:55:29444}
445
[email protected]d01b8732008-10-16 02:18:07446bool MetricsService::recording_active() const {
initial.commit09911bf2008-07-26 23:55:29447 DCHECK(IsSingleThreaded());
[email protected]d01b8732008-10-16 02:18:07448 return recording_active_;
initial.commit09911bf2008-07-26 23:55:29449}
450
[email protected]d01b8732008-10-16 02:18:07451void MetricsService::SetReporting(bool enable) {
452 if (reporting_active_ != enable) {
453 reporting_active_ = enable;
454 if (reporting_active_)
initial.commit09911bf2008-07-26 23:55:29455 StartLogTransmissionTimer();
456 }
[email protected]d01b8732008-10-16 02:18:07457}
458
459bool MetricsService::reporting_active() const {
460 DCHECK(IsSingleThreaded());
461 return reporting_active_;
initial.commit09911bf2008-07-26 23:55:29462}
463
464void MetricsService::Observe(NotificationType type,
465 const NotificationSource& source,
466 const NotificationDetails& details) {
467 DCHECK(current_log_);
468 DCHECK(IsSingleThreaded());
469
470 if (!CanLogNotification(type, source, details))
471 return;
472
[email protected]bfd04a62009-02-01 18:16:56473 switch (type.value) {
474 case NotificationType::USER_ACTION:
initial.commit09911bf2008-07-26 23:55:29475 current_log_->RecordUserAction(*Details<const wchar_t*>(details).ptr());
476 break;
477
[email protected]bfd04a62009-02-01 18:16:56478 case NotificationType::BROWSER_OPENED:
479 case NotificationType::BROWSER_CLOSED:
initial.commit09911bf2008-07-26 23:55:29480 LogWindowChange(type, source, details);
481 break;
482
[email protected]bfd04a62009-02-01 18:16:56483 case NotificationType::TAB_PARENTED:
484 case NotificationType::TAB_CLOSING:
initial.commit09911bf2008-07-26 23:55:29485 LogWindowChange(type, source, details);
486 break;
487
[email protected]bfd04a62009-02-01 18:16:56488 case NotificationType::LOAD_STOP:
initial.commit09911bf2008-07-26 23:55:29489 LogLoadComplete(type, source, details);
490 break;
491
[email protected]bfd04a62009-02-01 18:16:56492 case NotificationType::LOAD_START:
initial.commit09911bf2008-07-26 23:55:29493 LogLoadStarted();
494 break;
495
[email protected]bfd04a62009-02-01 18:16:56496 case NotificationType::RENDERER_PROCESS_TERMINATED:
initial.commit09911bf2008-07-26 23:55:29497 if (!*Details<bool>(details).ptr())
498 LogRendererCrash();
499 break;
500
[email protected]bfd04a62009-02-01 18:16:56501 case NotificationType::RENDERER_PROCESS_HANG:
initial.commit09911bf2008-07-26 23:55:29502 LogRendererHang();
503 break;
504
[email protected]bfd04a62009-02-01 18:16:56505 case NotificationType::RENDERER_PROCESS_IN_SBOX:
initial.commit09911bf2008-07-26 23:55:29506 LogRendererInSandbox(*Details<bool>(details).ptr());
507 break;
508
[email protected]a27a9382009-02-11 23:55:10509 case NotificationType::CHILD_PROCESS_HOST_CONNECTED:
510 case NotificationType::CHILD_PROCESS_CRASHED:
511 case NotificationType::CHILD_INSTANCE_CREATED:
512 LogChildProcessChange(type, source, details);
initial.commit09911bf2008-07-26 23:55:29513 break;
514
[email protected]bfd04a62009-02-01 18:16:56515 case NotificationType::TEMPLATE_URL_MODEL_LOADED:
initial.commit09911bf2008-07-26 23:55:29516 LogKeywords(Source<TemplateURLModel>(source).ptr());
517 break;
518
[email protected]bfd04a62009-02-01 18:16:56519 case NotificationType::OMNIBOX_OPENED_URL:
initial.commit09911bf2008-07-26 23:55:29520 current_log_->RecordOmniboxOpenedURL(
521 *Details<AutocompleteLog>(details).ptr());
522 break;
523
[email protected]bfd04a62009-02-01 18:16:56524 case NotificationType::BOOKMARK_MODEL_LOADED:
[email protected]d8e41ed2008-09-11 15:22:32525 LogBookmarks(Source<Profile>(source)->GetBookmarkModel());
initial.commit09911bf2008-07-26 23:55:29526 break;
527
528 default:
529 NOTREACHED();
530 break;
531 }
[email protected]d01b8732008-10-16 02:18:07532
533 HandleIdleSinceLastTransmission(false);
534
535 if (current_log_)
[email protected]281d2882009-01-20 20:32:42536 DLOG(INFO) << "METRICS: NUMBER OF EVENTS = " << current_log_->num_events();
[email protected]d01b8732008-10-16 02:18:07537}
538
539void MetricsService::HandleIdleSinceLastTransmission(bool in_idle) {
540 // If there wasn't a lot of action, maybe the computer was asleep, in which
541 // case, the log transmissions should have stopped. Here we start them up
542 // again.
[email protected]cac78842008-11-27 01:02:20543 if (!in_idle && idle_since_last_transmission_)
544 StartLogTransmissionTimer();
545 idle_since_last_transmission_ = in_idle;
initial.commit09911bf2008-07-26 23:55:29546}
547
548void MetricsService::RecordCleanShutdown() {
549 RecordBooleanPrefValue(prefs::kStabilityExitedCleanly, true);
550}
551
552void MetricsService::RecordStartOfSessionEnd() {
553 RecordBooleanPrefValue(prefs::kStabilitySessionEndCompleted, false);
554}
555
556void MetricsService::RecordCompletedSessionEnd() {
557 RecordBooleanPrefValue(prefs::kStabilitySessionEndCompleted, true);
558}
559
[email protected]e73c01972008-08-13 00:18:24560void MetricsService:: RecordBreakpadRegistration(bool success) {
[email protected]68475e602008-08-22 03:21:15561 if (!success)
[email protected]e73c01972008-08-13 00:18:24562 IncrementPrefValue(prefs::kStabilityBreakpadRegistrationFail);
563 else
564 IncrementPrefValue(prefs::kStabilityBreakpadRegistrationSuccess);
565}
566
567void MetricsService::RecordBreakpadHasDebugger(bool has_debugger) {
568 if (!has_debugger)
569 IncrementPrefValue(prefs::kStabilityDebuggerNotPresent);
570 else
[email protected]68475e602008-08-22 03:21:15571 IncrementPrefValue(prefs::kStabilityDebuggerPresent);
[email protected]e73c01972008-08-13 00:18:24572}
573
initial.commit09911bf2008-07-26 23:55:29574//------------------------------------------------------------------------------
575// private methods
576//------------------------------------------------------------------------------
577
578
579//------------------------------------------------------------------------------
580// Initialization methods
581
582void MetricsService::InitializeMetricsState() {
583 PrefService* pref = g_browser_process->local_state();
584 DCHECK(pref);
585
[email protected]541f77922009-02-23 21:14:38586 if (WideToUTF8(pref->GetString(prefs::kStabilityStatsVersion)) !=
587 MetricsLog::GetVersionString()) {
588 // This is a new version, so we don't want to confuse the stats about the
589 // old version with info that we upload.
590 DiscardOldStabilityStats(pref);
591 pref->SetString(prefs::kStabilityStatsVersion,
592 UTF8ToWide(MetricsLog::GetVersionString()));
593 }
594
initial.commit09911bf2008-07-26 23:55:29595 client_id_ = WideToUTF8(pref->GetString(prefs::kMetricsClientID));
596 if (client_id_.empty()) {
597 client_id_ = GenerateClientID();
598 pref->SetString(prefs::kMetricsClientID, UTF8ToWide(client_id_));
599
600 // Might as well make a note of how long this ID has existed
[email protected]0bb1a622009-03-04 03:22:32601 pref->SetInt64(prefs::kMetricsClientIDTimestamp, Time::Now().ToTimeT());
initial.commit09911bf2008-07-26 23:55:29602 }
603
604 // Update session ID
605 session_id_ = pref->GetInteger(prefs::kMetricsSessionID);
606 ++session_id_;
607 pref->SetInteger(prefs::kMetricsSessionID, session_id_);
608
initial.commit09911bf2008-07-26 23:55:29609 // Stability bookkeeping
[email protected]e73c01972008-08-13 00:18:24610 IncrementPrefValue(prefs::kStabilityLaunchCount);
initial.commit09911bf2008-07-26 23:55:29611
[email protected]e73c01972008-08-13 00:18:24612 if (!pref->GetBoolean(prefs::kStabilityExitedCleanly)) {
613 IncrementPrefValue(prefs::kStabilityCrashCount);
initial.commit09911bf2008-07-26 23:55:29614 }
[email protected]e73c01972008-08-13 00:18:24615
616 // This will be set to 'true' if we exit cleanly.
initial.commit09911bf2008-07-26 23:55:29617 pref->SetBoolean(prefs::kStabilityExitedCleanly, false);
618
[email protected]e73c01972008-08-13 00:18:24619 if (!pref->GetBoolean(prefs::kStabilitySessionEndCompleted)) {
620 IncrementPrefValue(prefs::kStabilityIncompleteSessionEndCount);
initial.commit09911bf2008-07-26 23:55:29621 }
622 // This is marked false when we get a WM_ENDSESSION.
623 pref->SetBoolean(prefs::kStabilitySessionEndCompleted, true);
624
[email protected]0bb1a622009-03-04 03:22:32625 int64 last_start_time = pref->GetInt64(prefs::kStabilityLaunchTimeSec);
626 int64 last_end_time = pref->GetInt64(prefs::kStabilityLastTimestampSec);
627 int64 uptime = pref->GetInt64(prefs::kStabilityUptimeSec);
628
629 // Same idea as uptime, except this one never gets reset and is used at
630 // uninstallation.
631 int64 uninstall_metrics_uptime =
632 pref->GetInt64(prefs::kUninstallMetricsUptimeSec);
initial.commit09911bf2008-07-26 23:55:29633
634 if (last_start_time && last_end_time) {
635 // TODO(JAR): Exclude sleep time. ... which must be gathered in UI loop.
[email protected]0bb1a622009-03-04 03:22:32636 int64 uptime_increment = last_end_time - last_start_time;
637 uptime += uptime_increment;
638 pref->SetInt64(prefs::kStabilityUptimeSec, uptime);
639
640 uninstall_metrics_uptime += uptime_increment;
641 pref->SetInt64(prefs::kUninstallMetricsUptimeSec,
642 uninstall_metrics_uptime);
initial.commit09911bf2008-07-26 23:55:29643 }
[email protected]0bb1a622009-03-04 03:22:32644 pref->SetInt64(prefs::kStabilityLaunchTimeSec, Time::Now().ToTimeT());
645
646 // Bookkeeping for the uninstall metrics.
647 IncrementLongPrefsValue(prefs::kUninstallLaunchCount);
initial.commit09911bf2008-07-26 23:55:29648
649 // Save profile metrics.
650 PrefService* prefs = g_browser_process->local_state();
651 if (prefs) {
652 // Remove the current dictionary and store it for use when sending data to
653 // server. By removing the value we prune potentially dead profiles
654 // (and keys). All valid values are added back once services startup.
655 const DictionaryValue* profile_dictionary =
656 prefs->GetDictionary(prefs::kProfileMetrics);
657 if (profile_dictionary) {
658 // Do a deep copy of profile_dictionary since ClearPref will delete it.
659 profile_dictionary_.reset(static_cast<DictionaryValue*>(
660 profile_dictionary->DeepCopy()));
661 prefs->ClearPref(prefs::kProfileMetrics);
662 }
663 }
664
665 // Kick off the process of saving the state (so the uptime numbers keep
666 // getting updated) every n minutes.
667 ScheduleNextStateSave();
668}
669
670void MetricsService::OnGetPluginListTaskComplete() {
671 DCHECK(state_ == PLUGIN_LIST_REQUESTED);
672 if (state_ == PLUGIN_LIST_REQUESTED)
673 state_ = PLUGIN_LIST_ARRIVED;
674}
675
676std::string MetricsService::GenerateClientID() {
[email protected]dc6f4962009-02-13 01:25:50677#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:29678 const int kGUIDSize = 39;
679
680 GUID guid;
681 HRESULT guid_result = CoCreateGuid(&guid);
682 DCHECK(SUCCEEDED(guid_result));
683
684 std::wstring guid_string;
685 int result = StringFromGUID2(guid,
686 WriteInto(&guid_string, kGUIDSize), kGUIDSize);
687 DCHECK(result == kGUIDSize);
688
689 return WideToUTF8(guid_string.substr(1, guid_string.length() - 2));
[email protected]dc6f4962009-02-13 01:25:50690#else
691 // TODO(port): Implement for Mac and linux.
[email protected]f5d0e152009-02-19 21:54:37692 // Rather than actually implementing a random source, might this be a good
693 // time to implement http://code.google.com/p/chromium/issues/detail?id=2278
694 // ? I think so!
[email protected]dc6f4962009-02-13 01:25:50695 NOTIMPLEMENTED();
696 return std::string();
697#endif
initial.commit09911bf2008-07-26 23:55:29698}
699
700
701//------------------------------------------------------------------------------
702// State save methods
703
704void MetricsService::ScheduleNextStateSave() {
705 state_saver_factory_.RevokeAll();
706
707 MessageLoop::current()->PostDelayedTask(FROM_HERE,
708 state_saver_factory_.NewRunnableMethod(&MetricsService::SaveLocalState),
709 kSaveStateInterval * 1000);
710}
711
712void MetricsService::SaveLocalState() {
713 PrefService* pref = g_browser_process->local_state();
714 if (!pref) {
715 NOTREACHED();
716 return;
717 }
718
719 RecordCurrentState(pref);
720 pref->ScheduleSavePersistentPrefs(g_browser_process->file_thread());
721
[email protected]281d2882009-01-20 20:32:42722 // TODO(jar): Does this run down the batteries????
initial.commit09911bf2008-07-26 23:55:29723 ScheduleNextStateSave();
724}
725
726
727//------------------------------------------------------------------------------
728// Recording control methods
729
730void MetricsService::StartRecording() {
731 if (current_log_)
732 return;
733
734 current_log_ = new MetricsLog(client_id_, session_id_);
735 if (state_ == INITIALIZED) {
736 // We only need to schedule that run once.
737 state_ = PLUGIN_LIST_REQUESTED;
738
739 // Make sure the plugin list is loaded before the inital log is sent, so
740 // that the main thread isn't blocked generating the list.
741 g_browser_process->file_thread()->message_loop()->PostDelayedTask(FROM_HERE,
742 new GetPluginListTask(MessageLoop::current()),
[email protected]252873ef2008-08-04 21:59:45743 kInitialInterlogDuration * 1000 / 2);
initial.commit09911bf2008-07-26 23:55:29744 }
745}
746
747void MetricsService::StopRecording(MetricsLog** log) {
748 if (!current_log_)
749 return;
750
[email protected]68475e602008-08-22 03:21:15751 // TODO(jar): Integrate bounds on log recording more consistently, so that we
752 // can stop recording logs that are too big much sooner.
[email protected]d01b8732008-10-16 02:18:07753 if (current_log_->num_events() > log_event_limit_) {
[email protected]553dba62009-02-24 19:08:23754 UMA_HISTOGRAM_COUNTS("UMA.Discarded Log Events",
[email protected]68475e602008-08-22 03:21:15755 current_log_->num_events());
756 current_log_->CloseLog();
757 delete current_log_;
[email protected]294638782008-09-24 00:22:41758 current_log_ = NULL;
[email protected]68475e602008-08-22 03:21:15759 StartRecording(); // Start trivial log to hold our histograms.
760 }
761
[email protected]0b33f80b2008-12-17 21:34:36762 // Put incremental data (histogram deltas, and realtime stats deltas) at the
[email protected]147bbc0b2009-01-06 19:37:40763 // end of all log transmissions (initial log handles this separately).
initial.commit09911bf2008-07-26 23:55:29764 // Don't bother if we're going to discard current_log_.
[email protected]0b33f80b2008-12-17 21:34:36765 if (log) {
[email protected]c96d53092009-02-24 01:25:06766 current_log_->RecordIncrementalStabilityElements();
initial.commit09911bf2008-07-26 23:55:29767 RecordCurrentHistograms();
[email protected]0b33f80b2008-12-17 21:34:36768 }
initial.commit09911bf2008-07-26 23:55:29769
770 current_log_->CloseLog();
[email protected]cac78842008-11-27 01:02:20771 if (log)
initial.commit09911bf2008-07-26 23:55:29772 *log = current_log_;
[email protected]cac78842008-11-27 01:02:20773 else
initial.commit09911bf2008-07-26 23:55:29774 delete current_log_;
initial.commit09911bf2008-07-26 23:55:29775 current_log_ = NULL;
776}
777
778void MetricsService::ListenerRegistration(bool start_listening) {
[email protected]bfd04a62009-02-01 18:16:56779 AddOrRemoveObserver(this, NotificationType::BROWSER_OPENED, start_listening);
780 AddOrRemoveObserver(this, NotificationType::BROWSER_CLOSED, start_listening);
781 AddOrRemoveObserver(this, NotificationType::USER_ACTION, start_listening);
782 AddOrRemoveObserver(this, NotificationType::TAB_PARENTED, start_listening);
783 AddOrRemoveObserver(this, NotificationType::TAB_CLOSING, start_listening);
784 AddOrRemoveObserver(this, NotificationType::LOAD_START, start_listening);
785 AddOrRemoveObserver(this, NotificationType::LOAD_STOP, start_listening);
786 AddOrRemoveObserver(this, NotificationType::RENDERER_PROCESS_IN_SBOX,
initial.commit09911bf2008-07-26 23:55:29787 start_listening);
[email protected]bfd04a62009-02-01 18:16:56788 AddOrRemoveObserver(this, NotificationType::RENDERER_PROCESS_TERMINATED,
initial.commit09911bf2008-07-26 23:55:29789 start_listening);
[email protected]bfd04a62009-02-01 18:16:56790 AddOrRemoveObserver(this, NotificationType::RENDERER_PROCESS_HANG,
791 start_listening);
[email protected]a27a9382009-02-11 23:55:10792 AddOrRemoveObserver(this, NotificationType::CHILD_PROCESS_HOST_CONNECTED,
[email protected]bfd04a62009-02-01 18:16:56793 start_listening);
[email protected]a27a9382009-02-11 23:55:10794 AddOrRemoveObserver(this, NotificationType::CHILD_INSTANCE_CREATED,
[email protected]bfd04a62009-02-01 18:16:56795 start_listening);
[email protected]a27a9382009-02-11 23:55:10796 AddOrRemoveObserver(this, NotificationType::CHILD_PROCESS_CRASHED,
[email protected]bfd04a62009-02-01 18:16:56797 start_listening);
798 AddOrRemoveObserver(this, NotificationType::TEMPLATE_URL_MODEL_LOADED,
799 start_listening);
800 AddOrRemoveObserver(this, NotificationType::OMNIBOX_OPENED_URL,
801 start_listening);
802 AddOrRemoveObserver(this, NotificationType::BOOKMARK_MODEL_LOADED,
803 start_listening);
initial.commit09911bf2008-07-26 23:55:29804}
805
806// static
807void MetricsService::AddOrRemoveObserver(NotificationObserver* observer,
[email protected]cac78842008-11-27 01:02:20808 NotificationType type,
809 bool is_add) {
initial.commit09911bf2008-07-26 23:55:29810 NotificationService* service = NotificationService::current();
811
[email protected]cac78842008-11-27 01:02:20812 if (is_add)
initial.commit09911bf2008-07-26 23:55:29813 service->AddObserver(observer, type, NotificationService::AllSources());
[email protected]cac78842008-11-27 01:02:20814 else
initial.commit09911bf2008-07-26 23:55:29815 service->RemoveObserver(observer, type, NotificationService::AllSources());
initial.commit09911bf2008-07-26 23:55:29816}
817
818void MetricsService::PushPendingLogsToUnsentLists() {
819 if (state_ < INITIAL_LOG_READY)
[email protected]28ab7f92009-01-06 21:39:04820 return; // We didn't and still don't have time to get plugin list etc.
initial.commit09911bf2008-07-26 23:55:29821
822 if (pending_log()) {
823 PreparePendingLogText();
824 if (state_ == INITIAL_LOG_READY) {
825 // We may race here, and send second copy of initial log later.
826 unsent_initial_logs_.push_back(pending_log_text_);
[email protected]d01b8732008-10-16 02:18:07827 state_ = SEND_OLD_INITIAL_LOGS;
initial.commit09911bf2008-07-26 23:55:29828 } else {
[email protected]281d2882009-01-20 20:32:42829 // TODO(jar): Verify correctness in other states, including sending unsent
[email protected]541f77922009-02-23 21:14:38830 // initial logs.
[email protected]68475e602008-08-22 03:21:15831 PushPendingLogTextToUnsentOngoingLogs();
initial.commit09911bf2008-07-26 23:55:29832 }
833 DiscardPendingLog();
834 }
835 DCHECK(!pending_log());
836 StopRecording(&pending_log_);
837 PreparePendingLogText();
[email protected]68475e602008-08-22 03:21:15838 PushPendingLogTextToUnsentOngoingLogs();
initial.commit09911bf2008-07-26 23:55:29839 DiscardPendingLog();
840 StoreUnsentLogs();
841}
842
[email protected]68475e602008-08-22 03:21:15843void MetricsService::PushPendingLogTextToUnsentOngoingLogs() {
[email protected]d01b8732008-10-16 02:18:07844 // If UMA response told us not to upload, there's no need to save the pending
845 // log. It wasn't supposed to be uploaded anyway.
846 if (!server_permits_upload_)
847 return;
848
[email protected]dc6f4962009-02-13 01:25:50849 if (pending_log_text_.length() >
850 static_cast<size_t>(kUploadLogAvoidRetransmitSize)) {
[email protected]553dba62009-02-24 19:08:23851 UMA_HISTOGRAM_COUNTS("UMA.Large Accumulated Log Not Persisted",
[email protected]68475e602008-08-22 03:21:15852 static_cast<int>(pending_log_text_.length()));
853 return;
854 }
855 unsent_ongoing_logs_.push_back(pending_log_text_);
856}
857
initial.commit09911bf2008-07-26 23:55:29858//------------------------------------------------------------------------------
859// Transmission of logs methods
860
861void MetricsService::StartLogTransmissionTimer() {
[email protected]d01b8732008-10-16 02:18:07862 // If we're not reporting, there's no point in starting a log transmission
863 // timer.
864 if (!reporting_active())
865 return;
866
initial.commit09911bf2008-07-26 23:55:29867 if (!current_log_)
868 return; // Recorder is shutdown.
[email protected]d01b8732008-10-16 02:18:07869
870 // If there is already a timer running, we leave it running.
871 // If timer_pending is true because the fetch is waiting for a response,
872 // we return for now and let the response handler start the timer.
873 if (timer_pending_)
initial.commit09911bf2008-07-26 23:55:29874 return;
[email protected]d01b8732008-10-16 02:18:07875
[email protected]d01b8732008-10-16 02:18:07876 // Before starting the timer, set timer_pending_ to true.
initial.commit09911bf2008-07-26 23:55:29877 timer_pending_ = true;
[email protected]d01b8732008-10-16 02:18:07878
879 // Right before the UMA transmission gets started, there's one more thing we'd
880 // like to record: the histogram of memory usage, so we spawn a task to
881 // collect the memory details and when that task is finished, we arrange for
882 // TryToStartTransmission to take over.
initial.commit09911bf2008-07-26 23:55:29883 MessageLoop::current()->PostDelayedTask(FROM_HERE,
884 log_sender_factory_.
885 NewRunnableMethod(&MetricsService::CollectMemoryDetails),
886 static_cast<int>(interlog_duration_.InMilliseconds()));
887}
888
889void MetricsService::TryToStartTransmission() {
890 DCHECK(IsSingleThreaded());
891
[email protected]d01b8732008-10-16 02:18:07892 // This function should only be called via timer, so timer_pending_
893 // should be true.
894 DCHECK(timer_pending_);
895 timer_pending_ = false;
initial.commit09911bf2008-07-26 23:55:29896
897 DCHECK(!current_fetch_.get());
initial.commit09911bf2008-07-26 23:55:29898
[email protected]d01b8732008-10-16 02:18:07899 // If we're getting no notifications, then the log won't have much in it, and
900 // it's possible the computer is about to go to sleep, so don't upload and
901 // don't restart the transmission timer.
902 if (idle_since_last_transmission_)
903 return;
904
905 // If somehow there is a fetch in progress, we return setting timer_pending_
906 // to true and hope things work out.
907 if (current_fetch_.get()) {
908 timer_pending_ = true;
909 return;
910 }
911
912 // If uploads are forbidden by UMA response, there's no point in keeping
913 // the current_log_, and the more often we delete it, the less likely it is
914 // to expand forever.
915 if (!server_permits_upload_ && current_log_) {
916 StopRecording(NULL);
917 StartRecording();
918 }
initial.commit09911bf2008-07-26 23:55:29919
920 if (!current_log_)
921 return; // Logging was disabled.
[email protected]d01b8732008-10-16 02:18:07922 if (!reporting_active())
initial.commit09911bf2008-07-26 23:55:29923 return; // Don't do work if we're not going to send anything now.
924
[email protected]d01b8732008-10-16 02:18:07925 MakePendingLog();
initial.commit09911bf2008-07-26 23:55:29926
[email protected]d01b8732008-10-16 02:18:07927 // MakePendingLog should have put something in the pending log, if it didn't,
928 // we start the timer again, return and hope things work out.
929 if (!pending_log()) {
930 StartLogTransmissionTimer();
931 return;
932 }
initial.commit09911bf2008-07-26 23:55:29933
[email protected]d01b8732008-10-16 02:18:07934 // If we're not supposed to upload any UMA data because the response or the
935 // user said so, cancel the upload at this point, but start the timer.
936 if (!TransmissionPermitted()) {
937 DiscardPendingLog();
938 StartLogTransmissionTimer();
939 return;
940 }
initial.commit09911bf2008-07-26 23:55:29941
[email protected]d01b8732008-10-16 02:18:07942 PrepareFetchWithPendingLog();
943
944 if (!current_fetch_.get()) {
945 // Compression failed, and log discarded :-/.
946 DiscardPendingLog();
947 StartLogTransmissionTimer(); // Maybe we'll do better next time
948 // TODO(jar): If compression failed, we should have created a tiny log and
949 // compressed that, so that we can signal that we're losing logs.
950 return;
951 }
952
953 DCHECK(!timer_pending_);
954
955 // The URL fetch is a like timer in that after a while we get called back
956 // so we set timer_pending_ true just as we start the url fetch.
957 timer_pending_ = true;
958 current_fetch_->Start();
959
960 HandleIdleSinceLastTransmission(true);
961}
962
963
964void MetricsService::MakePendingLog() {
965 if (pending_log())
966 return;
967
968 switch (state_) {
969 case INITIALIZED:
970 case PLUGIN_LIST_REQUESTED: // We should be further along by now.
971 DCHECK(false);
972 return;
973
974 case PLUGIN_LIST_ARRIVED:
975 // We need to wait for the initial log to be ready before sending
976 // anything, because the server will tell us whether it wants to hear
977 // from us.
978 PrepareInitialLog();
979 DCHECK(state_ == PLUGIN_LIST_ARRIVED);
980 RecallUnsentLogs();
981 state_ = INITIAL_LOG_READY;
982 break;
983
984 case SEND_OLD_INITIAL_LOGS:
[email protected]cac78842008-11-27 01:02:20985 if (!unsent_initial_logs_.empty()) {
986 pending_log_text_ = unsent_initial_logs_.back();
987 break;
988 }
[email protected]d01b8732008-10-16 02:18:07989 state_ = SENDING_OLD_LOGS;
990 // Fall through.
initial.commit09911bf2008-07-26 23:55:29991
[email protected]d01b8732008-10-16 02:18:07992 case SENDING_OLD_LOGS:
993 if (!unsent_ongoing_logs_.empty()) {
994 pending_log_text_ = unsent_ongoing_logs_.back();
995 break;
996 }
997 state_ = SENDING_CURRENT_LOGS;
998 // Fall through.
999
1000 case SENDING_CURRENT_LOGS:
1001 StopRecording(&pending_log_);
1002 StartRecording();
1003 break;
1004
1005 default:
1006 DCHECK(false);
1007 return;
1008 }
1009
1010 DCHECK(pending_log());
1011}
1012
1013bool MetricsService::TransmissionPermitted() const {
1014 // If the user forbids uploading that's they're business, and we don't upload
1015 // anything. If the server forbids uploading, that's our business, so we take
1016 // that to mean it forbids current logs, but we still send up the inital logs
1017 // and any old logs.
[email protected]d01b8732008-10-16 02:18:071018 if (!user_permits_upload_)
1019 return false;
[email protected]cac78842008-11-27 01:02:201020 if (server_permits_upload_)
[email protected]d01b8732008-10-16 02:18:071021 return true;
initial.commit09911bf2008-07-26 23:55:291022
[email protected]cac78842008-11-27 01:02:201023 switch (state_) {
1024 case INITIAL_LOG_READY:
1025 case SEND_OLD_INITIAL_LOGS:
1026 case SENDING_OLD_LOGS:
1027 return true;
1028
1029 case SENDING_CURRENT_LOGS:
1030 default:
1031 return false;
[email protected]8c8824b2008-09-20 01:55:501032 }
initial.commit09911bf2008-07-26 23:55:291033}
1034
1035void MetricsService::CollectMemoryDetails() {
1036 Task* task = log_sender_factory_.
1037 NewRunnableMethod(&MetricsService::TryToStartTransmission);
1038 MetricsMemoryDetails* details = new MetricsMemoryDetails(task);
1039 details->StartFetch();
1040
1041 // Collect WebCore cache information to put into a histogram.
1042 for (RenderProcessHost::iterator it = RenderProcessHost::begin();
1043 it != RenderProcessHost::end(); ++it) {
1044 it->second->Send(new ViewMsg_GetCacheResourceStats());
1045 }
1046}
1047
1048void MetricsService::PrepareInitialLog() {
1049 DCHECK(state_ == PLUGIN_LIST_ARRIVED);
1050 std::vector<WebPluginInfo> plugins;
1051 PluginService::GetInstance()->GetPlugins(false, &plugins);
1052
1053 MetricsLog* log = new MetricsLog(client_id_, session_id_);
1054 log->RecordEnvironment(plugins, profile_dictionary_.get());
1055
1056 // Histograms only get written to current_log_, so setup for the write.
1057 MetricsLog* save_log = current_log_;
1058 current_log_ = log;
1059 RecordCurrentHistograms(); // Into current_log_... which is really log.
1060 current_log_ = save_log;
1061
1062 log->CloseLog();
1063 DCHECK(!pending_log());
1064 pending_log_ = log;
1065}
1066
1067void MetricsService::RecallUnsentLogs() {
1068 DCHECK(unsent_initial_logs_.empty());
1069 DCHECK(unsent_ongoing_logs_.empty());
1070
1071 PrefService* local_state = g_browser_process->local_state();
1072 DCHECK(local_state);
1073
1074 ListValue* unsent_initial_logs = local_state->GetMutableList(
1075 prefs::kMetricsInitialLogs);
1076 for (ListValue::iterator it = unsent_initial_logs->begin();
1077 it != unsent_initial_logs->end(); ++it) {
[email protected]5e324b72008-12-18 00:07:591078 std::string log;
1079 (*it)->GetAsString(&log);
1080 unsent_initial_logs_.push_back(log);
initial.commit09911bf2008-07-26 23:55:291081 }
1082
1083 ListValue* unsent_ongoing_logs = local_state->GetMutableList(
1084 prefs::kMetricsOngoingLogs);
1085 for (ListValue::iterator it = unsent_ongoing_logs->begin();
1086 it != unsent_ongoing_logs->end(); ++it) {
[email protected]5e324b72008-12-18 00:07:591087 std::string log;
1088 (*it)->GetAsString(&log);
1089 unsent_ongoing_logs_.push_back(log);
initial.commit09911bf2008-07-26 23:55:291090 }
1091}
1092
1093void MetricsService::StoreUnsentLogs() {
1094 if (state_ < INITIAL_LOG_READY)
1095 return; // We never Recalled the prior unsent logs.
1096
1097 PrefService* local_state = g_browser_process->local_state();
1098 DCHECK(local_state);
1099
1100 ListValue* unsent_initial_logs = local_state->GetMutableList(
1101 prefs::kMetricsInitialLogs);
1102 unsent_initial_logs->Clear();
1103 size_t start = 0;
1104 if (unsent_initial_logs_.size() > kMaxInitialLogsPersisted)
1105 start = unsent_initial_logs_.size() - kMaxInitialLogsPersisted;
1106 for (size_t i = start; i < unsent_initial_logs_.size(); ++i)
1107 unsent_initial_logs->Append(
[email protected]5e324b72008-12-18 00:07:591108 Value::CreateStringValue(unsent_initial_logs_[i]));
initial.commit09911bf2008-07-26 23:55:291109
1110 ListValue* unsent_ongoing_logs = local_state->GetMutableList(
1111 prefs::kMetricsOngoingLogs);
1112 unsent_ongoing_logs->Clear();
1113 start = 0;
1114 if (unsent_ongoing_logs_.size() > kMaxOngoingLogsPersisted)
1115 start = unsent_ongoing_logs_.size() - kMaxOngoingLogsPersisted;
1116 for (size_t i = start; i < unsent_ongoing_logs_.size(); ++i)
1117 unsent_ongoing_logs->Append(
[email protected]5e324b72008-12-18 00:07:591118 Value::CreateStringValue(unsent_ongoing_logs_[i]));
initial.commit09911bf2008-07-26 23:55:291119}
1120
1121void MetricsService::PreparePendingLogText() {
1122 DCHECK(pending_log());
1123 if (!pending_log_text_.empty())
1124 return;
1125 int original_size = pending_log_->GetEncodedLogSize();
1126 pending_log_->GetEncodedLog(WriteInto(&pending_log_text_, original_size),
1127 original_size);
1128}
1129
[email protected]d01b8732008-10-16 02:18:071130void MetricsService::PrepareFetchWithPendingLog() {
initial.commit09911bf2008-07-26 23:55:291131 DCHECK(pending_log());
1132 DCHECK(!current_fetch_.get());
1133 PreparePendingLogText();
1134 DCHECK(!pending_log_text_.empty());
1135
1136 // Allow security conscious users to see all metrics logs that we send.
1137 LOG(INFO) << "METRICS LOG: " << pending_log_text_;
1138
1139 std::string compressed_log;
[email protected]cac78842008-11-27 01:02:201140 if (!Bzip2Compress(pending_log_text_, &compressed_log)) {
initial.commit09911bf2008-07-26 23:55:291141 NOTREACHED() << "Failed to compress log for transmission.";
1142 DiscardPendingLog();
1143 StartLogTransmissionTimer(); // Maybe we'll do better on next log :-/.
1144 return;
1145 }
[email protected]cac78842008-11-27 01:02:201146
initial.commit09911bf2008-07-26 23:55:291147 current_fetch_.reset(new URLFetcher(GURL(kMetricsURL), URLFetcher::POST,
1148 this));
1149 current_fetch_->set_request_context(Profile::GetDefaultRequestContext());
1150 current_fetch_->set_upload_data(kMetricsType, compressed_log);
initial.commit09911bf2008-07-26 23:55:291151}
1152
1153void MetricsService::DiscardPendingLog() {
1154 if (pending_log_) { // Shutdown might have deleted it!
1155 delete pending_log_;
1156 pending_log_ = NULL;
1157 }
1158 pending_log_text_.clear();
1159}
1160
1161// This implementation is based on the Firefox MetricsService implementation.
1162bool MetricsService::Bzip2Compress(const std::string& input,
1163 std::string* output) {
1164 bz_stream stream = {0};
1165 // As long as our input is smaller than the bzip2 block size, we should get
1166 // the best compression. For example, if your input was 250k, using a block
1167 // size of 300k or 500k should result in the same compression ratio. Since
1168 // our data should be under 100k, using the minimum block size of 100k should
1169 // allocate less temporary memory, but result in the same compression ratio.
1170 int result = BZ2_bzCompressInit(&stream,
1171 1, // 100k (min) block size
1172 0, // quiet
1173 0); // default "work factor"
1174 if (result != BZ_OK) { // out of memory?
1175 return false;
1176 }
1177
1178 output->clear();
1179
1180 stream.next_in = const_cast<char*>(input.data());
1181 stream.avail_in = static_cast<int>(input.size());
1182 // NOTE: we don't need a BZ_RUN phase since our input buffer contains
1183 // the entire input
1184 do {
1185 output->resize(output->size() + 1024);
1186 stream.next_out = &((*output)[stream.total_out_lo32]);
1187 stream.avail_out = static_cast<int>(output->size()) - stream.total_out_lo32;
1188 result = BZ2_bzCompress(&stream, BZ_FINISH);
1189 } while (result == BZ_FINISH_OK);
1190 if (result != BZ_STREAM_END) // unknown failure?
1191 return false;
1192 result = BZ2_bzCompressEnd(&stream);
1193 DCHECK(result == BZ_OK);
1194
1195 output->resize(stream.total_out_lo32);
1196
1197 return true;
1198}
1199
1200static const char* StatusToString(const URLRequestStatus& status) {
1201 switch (status.status()) {
1202 case URLRequestStatus::SUCCESS:
1203 return "SUCCESS";
1204
1205 case URLRequestStatus::IO_PENDING:
1206 return "IO_PENDING";
1207
1208 case URLRequestStatus::HANDLED_EXTERNALLY:
1209 return "HANDLED_EXTERNALLY";
1210
1211 case URLRequestStatus::CANCELED:
1212 return "CANCELED";
1213
1214 case URLRequestStatus::FAILED:
1215 return "FAILED";
1216
1217 default:
1218 NOTREACHED();
1219 return "Unknown";
1220 }
1221}
1222
1223void MetricsService::OnURLFetchComplete(const URLFetcher* source,
1224 const GURL& url,
1225 const URLRequestStatus& status,
1226 int response_code,
1227 const ResponseCookies& cookies,
1228 const std::string& data) {
1229 DCHECK(timer_pending_);
1230 timer_pending_ = false;
1231 DCHECK(current_fetch_.get());
1232 current_fetch_.reset(NULL); // We're not allowed to re-use it.
1233
1234 // Confirm send so that we can move on.
[email protected]281d2882009-01-20 20:32:421235 LOG(INFO) << "METRICS RESPONSE CODE: " << response_code << " status=" <<
[email protected]cac78842008-11-27 01:02:201236 StatusToString(status);
[email protected]252873ef2008-08-04 21:59:451237
[email protected]0eb34fee2009-01-21 08:04:381238 // Provide boolean for error recovery (allow us to ignore response_code).
[email protected]dc6f4962009-02-13 01:25:501239 bool discard_log = false;
[email protected]0eb34fee2009-01-21 08:04:381240
[email protected]68475e602008-08-22 03:21:151241 if (response_code != 200 &&
[email protected]dc6f4962009-02-13 01:25:501242 pending_log_text_.length() >
1243 static_cast<size_t>(kUploadLogAvoidRetransmitSize)) {
[email protected]553dba62009-02-24 19:08:231244 UMA_HISTOGRAM_COUNTS("UMA.Large Rejected Log was Discarded",
[email protected]68475e602008-08-22 03:21:151245 static_cast<int>(pending_log_text_.length()));
[email protected]0eb34fee2009-01-21 08:04:381246 discard_log = true;
1247 } else if (response_code == 400) {
1248 // Bad syntax. Retransmission won't work.
[email protected]553dba62009-02-24 19:08:231249 UMA_HISTOGRAM_COUNTS("UMA.Unacceptable_Log_Discarded", state_);
[email protected]0eb34fee2009-01-21 08:04:381250 discard_log = true;
[email protected]68475e602008-08-22 03:21:151251 }
1252
[email protected]0eb34fee2009-01-21 08:04:381253 if (response_code != 200 && !discard_log) {
[email protected]281d2882009-01-20 20:32:421254 LOG(INFO) << "METRICS: transmission attempt returned a failure code: "
1255 << response_code << ". Verify network connectivity";
[email protected]252873ef2008-08-04 21:59:451256 HandleBadResponseCode();
[email protected]0eb34fee2009-01-21 08:04:381257 } else { // Successful receipt (or we are discarding log).
[email protected]281d2882009-01-20 20:32:421258 LOG(INFO) << "METRICS RESPONSE DATA: " << data;
initial.commit09911bf2008-07-26 23:55:291259 switch (state_) {
1260 case INITIAL_LOG_READY:
1261 state_ = SEND_OLD_INITIAL_LOGS;
1262 break;
1263
1264 case SEND_OLD_INITIAL_LOGS:
1265 DCHECK(!unsent_initial_logs_.empty());
1266 unsent_initial_logs_.pop_back();
1267 StoreUnsentLogs();
1268 break;
1269
1270 case SENDING_OLD_LOGS:
1271 DCHECK(!unsent_ongoing_logs_.empty());
1272 unsent_ongoing_logs_.pop_back();
1273 StoreUnsentLogs();
1274 break;
1275
1276 case SENDING_CURRENT_LOGS:
1277 break;
1278
1279 default:
1280 DCHECK(false);
1281 break;
1282 }
[email protected]d01b8732008-10-16 02:18:071283
initial.commit09911bf2008-07-26 23:55:291284 DiscardPendingLog();
[email protected]29be92552008-08-07 22:49:271285 // Since we sent a log, make sure our in-memory state is recorded to disk.
1286 PrefService* local_state = g_browser_process->local_state();
1287 DCHECK(local_state);
1288 if (local_state)
1289 local_state->ScheduleSavePersistentPrefs(
1290 g_browser_process->file_thread());
[email protected]252873ef2008-08-04 21:59:451291
[email protected]147bbc0b2009-01-06 19:37:401292 // Provide a default (free of exponetial backoff, other varances) in case
1293 // the server does not specify a value.
1294 interlog_duration_ = TimeDelta::FromSeconds(kMinSecondsPerLog);
1295
[email protected]252873ef2008-08-04 21:59:451296 GetSettingsFromResponseData(data);
[email protected]252873ef2008-08-04 21:59:451297 // Override server specified interlog delay if there are unsent logs to
[email protected]29be92552008-08-07 22:49:271298 // transmit.
initial.commit09911bf2008-07-26 23:55:291299 if (unsent_logs()) {
1300 DCHECK(state_ < SENDING_CURRENT_LOGS);
1301 interlog_duration_ = TimeDelta::FromSeconds(kUnsentLogDelay);
initial.commit09911bf2008-07-26 23:55:291302 }
1303 }
[email protected]252873ef2008-08-04 21:59:451304
initial.commit09911bf2008-07-26 23:55:291305 StartLogTransmissionTimer();
1306}
1307
[email protected]252873ef2008-08-04 21:59:451308void MetricsService::HandleBadResponseCode() {
[email protected]281d2882009-01-20 20:32:421309 LOG(INFO) << "Verify your metrics logs are formatted correctly. "
[email protected]cac78842008-11-27 01:02:201310 "Verify server is active at " << kMetricsURL;
[email protected]252873ef2008-08-04 21:59:451311 if (!pending_log()) {
[email protected]281d2882009-01-20 20:32:421312 LOG(INFO) << "METRICS: Recorder shutdown during log transmission.";
[email protected]252873ef2008-08-04 21:59:451313 } else {
1314 // Send progressively less frequently.
1315 DCHECK(kBackoff > 1.0);
1316 interlog_duration_ = TimeDelta::FromMicroseconds(
1317 static_cast<int64>(kBackoff * interlog_duration_.InMicroseconds()));
1318
1319 if (kMaxBackoff * TimeDelta::FromSeconds(kMinSecondsPerLog) <
[email protected]cac78842008-11-27 01:02:201320 interlog_duration_) {
[email protected]252873ef2008-08-04 21:59:451321 interlog_duration_ = kMaxBackoff *
1322 TimeDelta::FromSeconds(kMinSecondsPerLog);
[email protected]cac78842008-11-27 01:02:201323 }
[email protected]252873ef2008-08-04 21:59:451324
[email protected]281d2882009-01-20 20:32:421325 LOG(INFO) << "METRICS: transmission retry being scheduled in " <<
[email protected]252873ef2008-08-04 21:59:451326 interlog_duration_.InSeconds() << " seconds for " <<
1327 pending_log_text_;
initial.commit09911bf2008-07-26 23:55:291328 }
initial.commit09911bf2008-07-26 23:55:291329}
1330
[email protected]252873ef2008-08-04 21:59:451331void MetricsService::GetSettingsFromResponseData(const std::string& data) {
1332 // We assume that the file is structured as a block opened by <response>
[email protected]d01b8732008-10-16 02:18:071333 // and that inside response, there is a block opened by tag <chrome_config>
1334 // other tags are ignored for now except the content of <chrome_config>.
[email protected]281d2882009-01-20 20:32:421335 LOG(INFO) << "METRICS: getting settings from response data: " << data;
[email protected]d01b8732008-10-16 02:18:071336
[email protected]252873ef2008-08-04 21:59:451337 int data_size = static_cast<int>(data.size());
1338 if (data_size < 0) {
[email protected]281d2882009-01-20 20:32:421339 LOG(INFO) << "METRICS: server response data bad size: " << data_size <<
[email protected]cac78842008-11-27 01:02:201340 "; aborting extraction of settings";
[email protected]252873ef2008-08-04 21:59:451341 return;
1342 }
[email protected]cac78842008-11-27 01:02:201343 xmlDocPtr doc = xmlReadMemory(data.c_str(), data_size, "", NULL, 0);
[email protected]252873ef2008-08-04 21:59:451344 DCHECK(doc);
[email protected]d01b8732008-10-16 02:18:071345 // If the document is malformed, we just use the settings that were there.
1346 if (!doc) {
[email protected]281d2882009-01-20 20:32:421347 LOG(INFO) << "METRICS: reading xml from server response data failed";
[email protected]252873ef2008-08-04 21:59:451348 return;
[email protected]d01b8732008-10-16 02:18:071349 }
[email protected]252873ef2008-08-04 21:59:451350
[email protected]d01b8732008-10-16 02:18:071351 xmlNodePtr top_node = xmlDocGetRootElement(doc), chrome_config_node = NULL;
1352 // Here, we find the chrome_config node by name.
[email protected]252873ef2008-08-04 21:59:451353 for (xmlNodePtr p = top_node->children; p; p = p->next) {
[email protected]d01b8732008-10-16 02:18:071354 if (xmlStrEqual(p->name, BAD_CAST "chrome_config")) {
1355 chrome_config_node = p;
[email protected]252873ef2008-08-04 21:59:451356 break;
1357 }
1358 }
1359 // If the server data is formatted wrong and there is no
1360 // config node where we expect, we just drop out.
[email protected]d01b8732008-10-16 02:18:071361 if (chrome_config_node != NULL)
1362 GetSettingsFromChromeConfigNode(chrome_config_node);
[email protected]252873ef2008-08-04 21:59:451363 xmlFreeDoc(doc);
1364}
1365
[email protected]d01b8732008-10-16 02:18:071366void MetricsService::GetSettingsFromChromeConfigNode(
1367 xmlNodePtr chrome_config_node) {
1368 // Iterate through all children of the config node.
1369 for (xmlNodePtr current_node = chrome_config_node->children;
1370 current_node;
1371 current_node = current_node->next) {
1372 // If we find the upload tag, we appeal to another function
1373 // GetSettingsFromUploadNode to read all the data in it.
[email protected]252873ef2008-08-04 21:59:451374 if (xmlStrEqual(current_node->name, BAD_CAST "upload")) {
[email protected]d01b8732008-10-16 02:18:071375 GetSettingsFromUploadNode(current_node);
[email protected]252873ef2008-08-04 21:59:451376 continue;
1377 }
1378 }
1379}
initial.commit09911bf2008-07-26 23:55:291380
[email protected]d01b8732008-10-16 02:18:071381void MetricsService::InheritedProperties::OverwriteWhereNeeded(
1382 xmlNodePtr node) {
1383 xmlChar* salt_value = xmlGetProp(node, BAD_CAST "salt");
1384 if (salt_value) // If the property isn't there, xmlGetProp returns NULL.
1385 salt = atoi(reinterpret_cast<char*>(salt_value));
1386 // If the property isn't there, we keep the value the property had before
1387
1388 xmlChar* denominator_value = xmlGetProp(node, BAD_CAST "denominator");
1389 if (denominator_value)
1390 denominator = atoi(reinterpret_cast<char*>(denominator_value));
1391}
1392
1393void MetricsService::GetSettingsFromUploadNode(xmlNodePtr upload_node) {
1394 InheritedProperties props;
1395 GetSettingsFromUploadNodeRecursive(upload_node, props, "", true);
1396}
1397
[email protected]cac78842008-11-27 01:02:201398void MetricsService::GetSettingsFromUploadNodeRecursive(
1399 xmlNodePtr node,
1400 InheritedProperties props,
1401 std::string path_prefix,
1402 bool uploadOn) {
[email protected]d01b8732008-10-16 02:18:071403 props.OverwriteWhereNeeded(node);
1404
1405 // The bool uploadOn is set to true if the data represented by current
1406 // node should be uploaded. This gets inherited in the tree; the children
1407 // of a node that has already been rejected for upload get rejected for
1408 // upload.
1409 uploadOn = uploadOn && NodeProbabilityTest(node, props);
1410
1411 // The path is a / separated list of the node names ancestral to the current
1412 // one. So, if you want to check if the current node has a certain name,
1413 // compare to name. If you want to check if it is a certan tag at a certain
1414 // place in the tree, compare to the whole path.
1415 std::string name = std::string(reinterpret_cast<const char*>(node->name));
1416 std::string path = path_prefix + "/" + name;
1417
1418 if (path == "/upload") {
1419 xmlChar* upload_interval_val = xmlGetProp(node, BAD_CAST "interval");
1420 if (upload_interval_val) {
1421 interlog_duration_ = TimeDelta::FromSeconds(
1422 atoi(reinterpret_cast<char*>(upload_interval_val)));
1423 }
1424
1425 server_permits_upload_ = uploadOn;
1426 }
1427 if (path == "/upload/logs") {
1428 xmlChar* log_event_limit_val = xmlGetProp(node, BAD_CAST "event_limit");
1429 if (log_event_limit_val)
1430 log_event_limit_ = atoi(reinterpret_cast<char*>(log_event_limit_val));
1431 }
1432 if (name == "histogram") {
1433 xmlChar* type_value = xmlGetProp(node, BAD_CAST "type");
1434 if (type_value) {
1435 std::string type = (reinterpret_cast<char*>(type_value));
1436 if (uploadOn)
1437 histograms_to_upload_.insert(type);
1438 else
1439 histograms_to_omit_.insert(type);
1440 }
1441 }
1442 if (name == "log") {
1443 xmlChar* type_value = xmlGetProp(node, BAD_CAST "type");
1444 if (type_value) {
1445 std::string type = (reinterpret_cast<char*>(type_value));
1446 if (uploadOn)
1447 logs_to_upload_.insert(type);
1448 else
1449 logs_to_omit_.insert(type);
1450 }
1451 }
1452
1453 // Recursive call. If the node is a leaf i.e. if it ends in a "/>", then it
1454 // doesn't have children, so node->children is NULL, and this loop doesn't
1455 // call (that's how the recursion ends).
1456 for (xmlNodePtr child_node = node->children;
[email protected]cac78842008-11-27 01:02:201457 child_node;
1458 child_node = child_node->next) {
[email protected]d01b8732008-10-16 02:18:071459 GetSettingsFromUploadNodeRecursive(child_node, props, path, uploadOn);
1460 }
1461}
1462
1463bool MetricsService::NodeProbabilityTest(xmlNodePtr node,
[email protected]cac78842008-11-27 01:02:201464 InheritedProperties props) const {
[email protected]d01b8732008-10-16 02:18:071465 // Default value of probability on any node is 1, but recall that
1466 // its parents can already have been rejected for upload.
1467 double probability = 1;
1468
1469 // If a probability is specified in the node, we use it instead.
1470 xmlChar* probability_value = xmlGetProp(node, BAD_CAST "probability");
1471 if (probability_value)
[email protected]0b33f80b2008-12-17 21:34:361472 probability = atoi(reinterpret_cast<char*>(probability_value));
[email protected]d01b8732008-10-16 02:18:071473
1474 return ProbabilityTest(probability, props.salt, props.denominator);
1475}
1476
1477bool MetricsService::ProbabilityTest(double probability,
1478 int salt,
1479 int denominator) const {
1480 // Okay, first we figure out how many of the digits of the
1481 // client_id_ we need in order to make a nice pseudorandomish
1482 // number in the range [0,denominator). Too many digits is
1483 // fine.
[email protected]d01b8732008-10-16 02:18:071484
1485 // n is the length of the client_id_ string
1486 size_t n = client_id_.size();
1487
1488 // idnumber is a positive integer generated from the client_id_.
1489 // It plus salt is going to give us our pseudorandom number.
1490 int idnumber = 0;
1491 const char* client_id_c_str = client_id_.c_str();
1492
1493 // Here we hash the relevant digits of the client_id_
1494 // string somehow to get a big integer idnumber (could be negative
1495 // from wraparound)
1496 int big = 1;
[email protected]cac78842008-11-27 01:02:201497 for (size_t j = n - 1; j >= 0; --j) {
1498 idnumber += static_cast<int>(client_id_c_str[j]) * big;
[email protected]d01b8732008-10-16 02:18:071499 big *= 10;
1500 }
1501
1502 // Mod id number by denominator making sure to get a non-negative
1503 // answer.
[email protected]cac78842008-11-27 01:02:201504 idnumber = ((idnumber % denominator) + denominator) % denominator;
[email protected]d01b8732008-10-16 02:18:071505
[email protected]cac78842008-11-27 01:02:201506 // ((idnumber + salt) % denominator) / denominator is in the range [0,1]
[email protected]d01b8732008-10-16 02:18:071507 // if it's less than probability we call that an affirmative coin
1508 // toss.
[email protected]cac78842008-11-27 01:02:201509 return static_cast<double>((idnumber + salt) % denominator) <
1510 probability * denominator;
[email protected]d01b8732008-10-16 02:18:071511}
1512
initial.commit09911bf2008-07-26 23:55:291513void MetricsService::LogWindowChange(NotificationType type,
1514 const NotificationSource& source,
1515 const NotificationDetails& details) {
[email protected]534e54b2008-08-13 15:40:091516 int controller_id = -1;
1517 uintptr_t window_or_tab = source.map_key();
initial.commit09911bf2008-07-26 23:55:291518 MetricsLog::WindowEventType window_type;
1519
1520 // Note: since we stop all logging when a single OTR session is active, it is
1521 // possible that we start getting notifications about a window that we don't
1522 // know about.
[email protected]534e54b2008-08-13 15:40:091523 if (window_map_.find(window_or_tab) == window_map_.end()) {
1524 controller_id = next_window_id_++;
1525 window_map_[window_or_tab] = controller_id;
initial.commit09911bf2008-07-26 23:55:291526 } else {
[email protected]534e54b2008-08-13 15:40:091527 controller_id = window_map_[window_or_tab];
initial.commit09911bf2008-07-26 23:55:291528 }
[email protected]534e54b2008-08-13 15:40:091529 DCHECK(controller_id != -1);
initial.commit09911bf2008-07-26 23:55:291530
[email protected]bfd04a62009-02-01 18:16:561531 switch (type.value) {
1532 case NotificationType::TAB_PARENTED:
1533 case NotificationType::BROWSER_OPENED:
initial.commit09911bf2008-07-26 23:55:291534 window_type = MetricsLog::WINDOW_CREATE;
1535 break;
1536
[email protected]bfd04a62009-02-01 18:16:561537 case NotificationType::TAB_CLOSING:
1538 case NotificationType::BROWSER_CLOSED:
[email protected]534e54b2008-08-13 15:40:091539 window_map_.erase(window_map_.find(window_or_tab));
initial.commit09911bf2008-07-26 23:55:291540 window_type = MetricsLog::WINDOW_DESTROY;
1541 break;
1542
1543 default:
1544 NOTREACHED();
[email protected]68d74f02009-02-13 01:36:501545 return;
initial.commit09911bf2008-07-26 23:55:291546 }
1547
[email protected]534e54b2008-08-13 15:40:091548 // TODO(brettw) we should have some kind of ID for the parent.
1549 current_log_->RecordWindowEvent(window_type, controller_id, 0);
initial.commit09911bf2008-07-26 23:55:291550}
1551
1552void MetricsService::LogLoadComplete(NotificationType type,
1553 const NotificationSource& source,
1554 const NotificationDetails& details) {
1555 if (details == NotificationService::NoDetails())
1556 return;
1557
[email protected]68475e602008-08-22 03:21:151558 // TODO(jar): There is a bug causing this to be called too many times, and
1559 // the log overflows. For now, we won't record these events.
[email protected]553dba62009-02-24 19:08:231560 UMA_HISTOGRAM_COUNTS("UMA.LogLoadComplete called", 1);
[email protected]68475e602008-08-22 03:21:151561 return;
1562
initial.commit09911bf2008-07-26 23:55:291563 const Details<LoadNotificationDetails> load_details(details);
[email protected]534e54b2008-08-13 15:40:091564 int controller_id = window_map_[details.map_key()];
1565 current_log_->RecordLoadEvent(controller_id,
initial.commit09911bf2008-07-26 23:55:291566 load_details->url(),
1567 load_details->origin(),
1568 load_details->session_index(),
1569 load_details->load_time());
1570}
1571
[email protected]e73c01972008-08-13 00:18:241572void MetricsService::IncrementPrefValue(const wchar_t* path) {
1573 PrefService* pref = g_browser_process->local_state();
1574 DCHECK(pref);
1575 int value = pref->GetInteger(path);
1576 pref->SetInteger(path, value + 1);
1577}
1578
[email protected]0bb1a622009-03-04 03:22:321579void MetricsService::IncrementLongPrefsValue(const wchar_t* path) {
1580 PrefService* pref = g_browser_process->local_state();
1581 DCHECK(pref);
1582 int64 value = pref->GetInt64(path);
1583 pref->SetInt64(path, value+1);
1584}
1585
initial.commit09911bf2008-07-26 23:55:291586void MetricsService::LogLoadStarted() {
[email protected]e73c01972008-08-13 00:18:241587 IncrementPrefValue(prefs::kStabilityPageLoadCount);
[email protected]0bb1a622009-03-04 03:22:321588 IncrementLongPrefsValue(prefs::kUninstallMetricsPageLoadCount);
[email protected]0b33f80b2008-12-17 21:34:361589 // We need to save the prefs, as page load count is a critical stat, and it
1590 // might be lost due to a crash :-(.
initial.commit09911bf2008-07-26 23:55:291591}
1592
1593void MetricsService::LogRendererInSandbox(bool on_sandbox_desktop) {
1594 PrefService* prefs = g_browser_process->local_state();
1595 DCHECK(prefs);
[email protected]e73c01972008-08-13 00:18:241596 if (on_sandbox_desktop)
1597 IncrementPrefValue(prefs::kSecurityRendererOnSboxDesktop);
1598 else
1599 IncrementPrefValue(prefs::kSecurityRendererOnDefaultDesktop);
initial.commit09911bf2008-07-26 23:55:291600}
1601
1602void MetricsService::LogRendererCrash() {
[email protected]e73c01972008-08-13 00:18:241603 IncrementPrefValue(prefs::kStabilityRendererCrashCount);
initial.commit09911bf2008-07-26 23:55:291604}
1605
1606void MetricsService::LogRendererHang() {
[email protected]e73c01972008-08-13 00:18:241607 IncrementPrefValue(prefs::kStabilityRendererHangCount);
initial.commit09911bf2008-07-26 23:55:291608}
1609
[email protected]a27a9382009-02-11 23:55:101610void MetricsService::LogChildProcessChange(
1611 NotificationType type,
1612 const NotificationSource& source,
1613 const NotificationDetails& details) {
1614 const std::wstring& child_name =
1615 Details<ChildProcessInfo>(details)->name();
initial.commit09911bf2008-07-26 23:55:291616
[email protected]a27a9382009-02-11 23:55:101617 if (child_process_stats_buffer_.find(child_name) ==
1618 child_process_stats_buffer_.end()) {
1619 child_process_stats_buffer_[child_name] = ChildProcessStats();
initial.commit09911bf2008-07-26 23:55:291620 }
1621
[email protected]a27a9382009-02-11 23:55:101622 ChildProcessStats& stats = child_process_stats_buffer_[child_name];
[email protected]bfd04a62009-02-01 18:16:561623 switch (type.value) {
[email protected]a27a9382009-02-11 23:55:101624 case NotificationType::CHILD_PROCESS_HOST_CONNECTED:
initial.commit09911bf2008-07-26 23:55:291625 stats.process_launches++;
1626 break;
1627
[email protected]a27a9382009-02-11 23:55:101628 case NotificationType::CHILD_INSTANCE_CREATED:
initial.commit09911bf2008-07-26 23:55:291629 stats.instances++;
1630 break;
1631
[email protected]a27a9382009-02-11 23:55:101632 case NotificationType::CHILD_PROCESS_CRASHED:
initial.commit09911bf2008-07-26 23:55:291633 stats.process_crashes++;
1634 break;
1635
1636 default:
[email protected]bfd04a62009-02-01 18:16:561637 NOTREACHED() << "Unexpected notification type " << type.value;
initial.commit09911bf2008-07-26 23:55:291638 return;
1639 }
1640}
1641
1642// Recursively counts the number of bookmarks and folders in node.
[email protected]d8e41ed2008-09-11 15:22:321643static void CountBookmarks(BookmarkNode* node, int* bookmarks, int* folders) {
initial.commit09911bf2008-07-26 23:55:291644 if (node->GetType() == history::StarredEntry::URL)
1645 (*bookmarks)++;
1646 else
1647 (*folders)++;
1648 for (int i = 0; i < node->GetChildCount(); ++i)
1649 CountBookmarks(node->GetChild(i), bookmarks, folders);
1650}
1651
[email protected]d8e41ed2008-09-11 15:22:321652void MetricsService::LogBookmarks(BookmarkNode* node,
initial.commit09911bf2008-07-26 23:55:291653 const wchar_t* num_bookmarks_key,
1654 const wchar_t* num_folders_key) {
1655 DCHECK(node);
1656 int num_bookmarks = 0;
1657 int num_folders = 0;
1658 CountBookmarks(node, &num_bookmarks, &num_folders);
1659 num_folders--; // Don't include the root folder in the count.
1660
1661 PrefService* pref = g_browser_process->local_state();
1662 DCHECK(pref);
1663 pref->SetInteger(num_bookmarks_key, num_bookmarks);
1664 pref->SetInteger(num_folders_key, num_folders);
1665}
1666
[email protected]d8e41ed2008-09-11 15:22:321667void MetricsService::LogBookmarks(BookmarkModel* model) {
initial.commit09911bf2008-07-26 23:55:291668 DCHECK(model);
1669 LogBookmarks(model->GetBookmarkBarNode(),
1670 prefs::kNumBookmarksOnBookmarkBar,
1671 prefs::kNumFoldersOnBookmarkBar);
1672 LogBookmarks(model->other_node(),
1673 prefs::kNumBookmarksInOtherBookmarkFolder,
1674 prefs::kNumFoldersInOtherBookmarkFolder);
1675 ScheduleNextStateSave();
1676}
1677
1678void MetricsService::LogKeywords(const TemplateURLModel* url_model) {
1679 DCHECK(url_model);
1680
1681 PrefService* pref = g_browser_process->local_state();
1682 DCHECK(pref);
1683 pref->SetInteger(prefs::kNumKeywords,
1684 static_cast<int>(url_model->GetTemplateURLs().size()));
1685 ScheduleNextStateSave();
1686}
1687
1688void MetricsService::RecordPluginChanges(PrefService* pref) {
1689 ListValue* plugins = pref->GetMutableList(prefs::kStabilityPluginStats);
1690 DCHECK(plugins);
1691
1692 for (ListValue::iterator value_iter = plugins->begin();
1693 value_iter != plugins->end(); ++value_iter) {
1694 if (!(*value_iter)->IsType(Value::TYPE_DICTIONARY)) {
1695 NOTREACHED();
1696 continue;
1697 }
1698
1699 DictionaryValue* plugin_dict = static_cast<DictionaryValue*>(*value_iter);
[email protected]8e50b602009-03-03 22:59:431700 std::wstring plugin_name;
1701 plugin_dict->GetString(prefs::kStabilityPluginName, &plugin_name);
[email protected]6470ee8f2009-03-03 20:46:401702 if (plugin_name.empty()) {
initial.commit09911bf2008-07-26 23:55:291703 NOTREACHED();
1704 continue;
1705 }
1706
[email protected]8e50b602009-03-03 22:59:431707 if (child_process_stats_buffer_.find(plugin_name) ==
[email protected]a27a9382009-02-11 23:55:101708 child_process_stats_buffer_.end())
initial.commit09911bf2008-07-26 23:55:291709 continue;
1710
[email protected]8e50b602009-03-03 22:59:431711 ChildProcessStats stats = child_process_stats_buffer_[plugin_name];
initial.commit09911bf2008-07-26 23:55:291712 if (stats.process_launches) {
1713 int launches = 0;
[email protected]8e50b602009-03-03 22:59:431714 plugin_dict->GetInteger(prefs::kStabilityPluginLaunches, &launches);
initial.commit09911bf2008-07-26 23:55:291715 launches += stats.process_launches;
[email protected]8e50b602009-03-03 22:59:431716 plugin_dict->SetInteger(prefs::kStabilityPluginLaunches, launches);
initial.commit09911bf2008-07-26 23:55:291717 }
1718 if (stats.process_crashes) {
1719 int crashes = 0;
[email protected]8e50b602009-03-03 22:59:431720 plugin_dict->GetInteger(prefs::kStabilityPluginCrashes, &crashes);
initial.commit09911bf2008-07-26 23:55:291721 crashes += stats.process_crashes;
[email protected]8e50b602009-03-03 22:59:431722 plugin_dict->SetInteger(prefs::kStabilityPluginCrashes, crashes);
initial.commit09911bf2008-07-26 23:55:291723 }
1724 if (stats.instances) {
1725 int instances = 0;
[email protected]8e50b602009-03-03 22:59:431726 plugin_dict->GetInteger(prefs::kStabilityPluginInstances, &instances);
initial.commit09911bf2008-07-26 23:55:291727 instances += stats.instances;
[email protected]8e50b602009-03-03 22:59:431728 plugin_dict->SetInteger(prefs::kStabilityPluginInstances, instances);
initial.commit09911bf2008-07-26 23:55:291729 }
1730
[email protected]8e50b602009-03-03 22:59:431731 child_process_stats_buffer_.erase(plugin_name);
initial.commit09911bf2008-07-26 23:55:291732 }
1733
1734 // Now go through and add dictionaries for plugins that didn't already have
1735 // reports in Local State.
[email protected]a27a9382009-02-11 23:55:101736 for (std::map<std::wstring, ChildProcessStats>::iterator cache_iter =
1737 child_process_stats_buffer_.begin();
1738 cache_iter != child_process_stats_buffer_.end(); ++cache_iter) {
1739 std::wstring plugin_name = cache_iter->first;
1740 ChildProcessStats stats = cache_iter->second;
initial.commit09911bf2008-07-26 23:55:291741 DictionaryValue* plugin_dict = new DictionaryValue;
1742
[email protected]8e50b602009-03-03 22:59:431743 plugin_dict->SetString(prefs::kStabilityPluginName, plugin_name);
1744 plugin_dict->SetInteger(prefs::kStabilityPluginLaunches,
initial.commit09911bf2008-07-26 23:55:291745 stats.process_launches);
[email protected]8e50b602009-03-03 22:59:431746 plugin_dict->SetInteger(prefs::kStabilityPluginCrashes,
initial.commit09911bf2008-07-26 23:55:291747 stats.process_crashes);
[email protected]8e50b602009-03-03 22:59:431748 plugin_dict->SetInteger(prefs::kStabilityPluginInstances,
initial.commit09911bf2008-07-26 23:55:291749 stats.instances);
1750 plugins->Append(plugin_dict);
1751 }
[email protected]a27a9382009-02-11 23:55:101752 child_process_stats_buffer_.clear();
initial.commit09911bf2008-07-26 23:55:291753}
1754
1755bool MetricsService::CanLogNotification(NotificationType type,
1756 const NotificationSource& source,
1757 const NotificationDetails& details) {
1758 // We simply don't log anything to UMA if there is a single off the record
1759 // session visible. The problem is that we always notify using the orginal
1760 // profile in order to simplify notification processing.
1761 return !BrowserList::IsOffTheRecordSessionActive();
1762}
1763
1764void MetricsService::RecordBooleanPrefValue(const wchar_t* path, bool value) {
1765 DCHECK(IsSingleThreaded());
1766
1767 PrefService* pref = g_browser_process->local_state();
1768 DCHECK(pref);
1769
1770 pref->SetBoolean(path, value);
1771 RecordCurrentState(pref);
1772}
1773
1774void MetricsService::RecordCurrentState(PrefService* pref) {
[email protected]0bb1a622009-03-04 03:22:321775 pref->SetInt64(prefs::kStabilityLastTimestampSec, Time::Now().ToTimeT());
initial.commit09911bf2008-07-26 23:55:291776
1777 RecordPluginChanges(pref);
1778}
1779
[email protected]55e57d42009-02-25 06:10:171780void MetricsService::CollectRendererHistograms() {
1781 for (RenderProcessHost::iterator it = RenderProcessHost::begin();
1782 it != RenderProcessHost::end(); ++it) {
1783 it->second->Send(new ViewMsg_GetRendererHistograms());
1784 }
1785}
1786
initial.commit09911bf2008-07-26 23:55:291787void MetricsService::RecordCurrentHistograms() {
1788 DCHECK(current_log_);
1789
[email protected]55e57d42009-02-25 06:10:171790 CollectRendererHistograms();
1791
1792 // TODO(raman): Delay the metrics collection activities until we get all the
1793 // updates from the renderers, or we time out (1 second? 3 seconds?).
1794
initial.commit09911bf2008-07-26 23:55:291795 StatisticsRecorder::Histograms histograms;
1796 StatisticsRecorder::GetHistograms(&histograms);
1797 for (StatisticsRecorder::Histograms::iterator it = histograms.begin();
1798 histograms.end() != it;
[email protected]cac78842008-11-27 01:02:201799 ++it) {
initial.commit09911bf2008-07-26 23:55:291800 if ((*it)->flags() & kUmaTargetedHistogramFlag)
[email protected]0b33f80b2008-12-17 21:34:361801 // TODO(petersont): Only record historgrams if they are not precluded by
1802 // the UMA response data.
[email protected]d01b8732008-10-16 02:18:071803 // Bug http://code.google.com/p/chromium/issues/detail?id=2739.
initial.commit09911bf2008-07-26 23:55:291804 RecordHistogram(**it);
1805 }
1806}
1807
1808void MetricsService::RecordHistogram(const Histogram& histogram) {
1809 // Get up-to-date snapshot of sample stats.
1810 Histogram::SampleSet snapshot;
1811 histogram.SnapshotSample(&snapshot);
1812
1813 const std::string& histogram_name = histogram.histogram_name();
1814
1815 // Find the already sent stats, or create an empty set.
1816 LoggedSampleMap::iterator it = logged_samples_.find(histogram_name);
1817 Histogram::SampleSet* already_logged;
1818 if (logged_samples_.end() == it) {
1819 // Add new entry
1820 already_logged = &logged_samples_[histogram.histogram_name()];
1821 already_logged->Resize(histogram); // Complete initialization.
1822 } else {
1823 already_logged = &(it->second);
1824 // Deduct any stats we've already logged from our snapshot.
1825 snapshot.Subtract(*already_logged);
1826 }
1827
1828 // snapshot now contains only a delta to what we've already_logged.
1829
1830 if (snapshot.TotalCount() > 0) {
1831 current_log_->RecordHistogramDelta(histogram, snapshot);
1832 // Add new data into our running total.
1833 already_logged->Add(snapshot);
1834 }
1835}
1836
1837void MetricsService::AddProfileMetric(Profile* profile,
1838 const std::wstring& key,
1839 int value) {
1840 // Restriction of types is needed for writing values. See
1841 // MetricsLog::WriteProfileMetrics.
1842 DCHECK(profile && !key.empty());
1843 PrefService* prefs = g_browser_process->local_state();
1844 DCHECK(prefs);
1845
1846 // Key is stored in prefs, which interpret '.'s as paths. As such, key
1847 // shouldn't have any '.'s in it.
1848 DCHECK(key.find(L'.') == std::wstring::npos);
1849 // The id is most likely an email address. We shouldn't send it to the server.
1850 const std::wstring id_hash =
1851 UTF8ToWide(MetricsLog::CreateBase64Hash(WideToUTF8(profile->GetID())));
1852 DCHECK(id_hash.find('.') == std::string::npos);
1853
1854 DictionaryValue* prof_prefs = prefs->GetMutableDictionary(
1855 prefs::kProfileMetrics);
1856 DCHECK(prof_prefs);
1857 const std::wstring pref_key = std::wstring(prefs::kProfilePrefix) + id_hash +
1858 L"." + key;
[email protected]8e50b602009-03-03 22:59:431859 prof_prefs->SetInteger(pref_key.c_str(), value);
initial.commit09911bf2008-07-26 23:55:291860}
1861
1862static bool IsSingleThreaded() {
[email protected]dc6f4962009-02-13 01:25:501863 static PlatformThreadId thread_id = 0;
initial.commit09911bf2008-07-26 23:55:291864 if (!thread_id)
[email protected]dc6f4962009-02-13 01:25:501865 thread_id = PlatformThread::CurrentId();
1866 return PlatformThread::CurrentId() == thread_id;
initial.commit09911bf2008-07-26 23:55:291867}