diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-22 18:58:16 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-22 18:58:16 +0000 |
commit | bea0616a1c86509eb3e8a05b43735d48e4cb2f6f (patch) | |
tree | 24122f23f48dd1309bc31ae066498b7a5de28c6b | |
parent | 8aff4ad0475f0b3b7f16a4d02c73f1062e322d73 (diff) | |
download | chromium_src-bea0616a1c86509eb3e8a05b43735d48e4cb2f6f.zip chromium_src-bea0616a1c86509eb3e8a05b43735d48e4cb2f6f.tar.gz chromium_src-bea0616a1c86509eb3e8a05b43735d48e4cb2f6f.tar.bz2 |
Add a notification observer for the first tab load for Chrome OS.
It simply records the uptime into the tmp directory for metrics collection
BUG=none
TEST=none
Original review: http://codereview.chromium.org/548044
Patch by sosa@chromium.org
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@36876 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/browser_init.cc | 9 | ||||
-rw-r--r-- | chrome/browser/chromeos/browser_notification_observers.cc | 45 | ||||
-rw-r--r-- | chrome/browser/chromeos/browser_notification_observers.h | 43 | ||||
-rwxr-xr-x | chrome/chrome_browser.gypi | 1 |
4 files changed, 98 insertions, 0 deletions
diff --git a/chrome/browser/browser_init.cc b/chrome/browser/browser_init.cc index 9406d6d..0a74de0 100644 --- a/chrome/browser/browser_init.cc +++ b/chrome/browser/browser_init.cc @@ -57,6 +57,7 @@ #endif #if defined(OS_CHROMEOS) +#include "chrome/browser/chromeos/browser_notification_observers.h" #include "chrome/browser/chromeos/gview_request_interceptor.h" #include "chrome/browser/chromeos/mount_library.h" #include "chrome/browser/chromeos/usb_mount_observer.h" @@ -312,6 +313,14 @@ bool LaunchBrowser(const CommandLine& command_line, Profile* profile, in_startup = process_startup; DCHECK(profile); + // This forces the creation of the initial tavb notification observer + // singleton. It must be created before browser launch to catch first tab + // load. +#if defined(OS_CHROMEOS) + if (process_startup) + chromeos::InitialTabNotificationObserver::Get(); +#endif + // Continue with the off-the-record profile from here on if --incognito if (command_line.HasSwitch(switches::kIncognito)) profile = profile->GetOffTheRecordProfile(); diff --git a/chrome/browser/chromeos/browser_notification_observers.cc b/chrome/browser/chromeos/browser_notification_observers.cc new file mode 100644 index 0000000..e47c452 --- /dev/null +++ b/chrome/browser/chromeos/browser_notification_observers.cc @@ -0,0 +1,45 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/chromeos/browser_notification_observers.h" + +#include "chrome/browser/chrome_thread.h" +#include "chrome/common/notification_service.h" + +namespace { + +// Static function that records uptime in /proc/uptime to tmp for metrics use. +void RecordUptime() { + system("cat /proc/uptime > /tmp/uptime-chrome-first-render &"); +} + +} // namespace + +namespace chromeos { + +InitialTabNotificationObserver::InitialTabNotificationObserver() { + registrar_.Add(this, NotificationType::LOAD_START, + NotificationService::AllSources()); +} + +InitialTabNotificationObserver::~InitialTabNotificationObserver() { +} + +void InitialTabNotificationObserver::Observe( + NotificationType type, + const NotificationSource& source, + const NotificationDetails& details) { + // Only log for first tab to render. Make sure this is only done once. + if (type == NotificationType::LOAD_START && + num_tabs_.GetNext() == 0) { + // If we can't post it, it doesn't matter. + ChromeThread::PostTask( + ChromeThread::FILE, FROM_HERE, + NewRunnableFunction(RecordUptime)); + registrar_.Remove(this, NotificationType::LOAD_START, + NotificationService::AllSources()); + } +} + +} // namespace chromeos diff --git a/chrome/browser/chromeos/browser_notification_observers.h b/chrome/browser/chromeos/browser_notification_observers.h new file mode 100644 index 0000000..91c95b9 --- /dev/null +++ b/chrome/browser/chromeos/browser_notification_observers.h @@ -0,0 +1,43 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_CHROMEOS_BROWSER_NOTIFICATION_OBSERVERS_H_ +#define CHROME_BROWSER_CHROMEOS_BROWSER_NOTIFICATION_OBSERVERS_H_ + +#include "base/atomic_sequence_num.h" +#include "base/singleton.h" +#include "chrome/common/notification_observer.h" +#include "chrome/common/notification_registrar.h" +#include "chrome/common/notification_source.h" +#include "chrome/common/notification_type.h" + +// Global notification observers for chrome os. +namespace chromeos { + +// Notification observer to log the initial time of when the first tab +// page is rendered for Chrome OS. +class InitialTabNotificationObserver : public NotificationObserver { + public: + InitialTabNotificationObserver(); + virtual ~InitialTabNotificationObserver(); + + static InitialTabNotificationObserver* Get() { + return Singleton<InitialTabNotificationObserver>::get(); + } + + // NotificationObserver implementation. + virtual void Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details); + + private: + NotificationRegistrar registrar_; + base::AtomicSequenceNumber num_tabs_; + + DISALLOW_COPY_AND_ASSIGN(InitialTabNotificationObserver); +}; + +} // namespace chromeos + +#endif // CHROME_BROWSER_CHROMEOS_BROWSER_NOTIFICATION_OBSERVERS_H_ diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 76c622b..4f5c837 100755 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -251,6 +251,7 @@ 'browser/chrome_plugin_host.h', 'browser/chrome_thread.cc', 'browser/chrome_thread.h', + 'browser/chromeos/browser_notification_observers.cc', 'browser/chromeos/browser_extenders.cc', 'browser/chromeos/chromeos_browser_view.cc', 'browser/chromeos/chromeos_browser_view.h', |