summaryrefslogtreecommitdiffstats
path: root/components/app_modal
diff options
context:
space:
mode:
Diffstat (limited to 'components/app_modal')
-rw-r--r--components/app_modal/javascript_app_modal_dialog.cc31
-rw-r--r--components/app_modal/javascript_app_modal_dialog.h6
-rw-r--r--components/app_modal/javascript_dialog_manager.cc22
-rw-r--r--components/app_modal/javascript_dialog_manager.h6
4 files changed, 55 insertions, 10 deletions
diff --git a/components/app_modal/javascript_app_modal_dialog.cc b/components/app_modal/javascript_app_modal_dialog.cc
index d2cc903..efce144 100644
--- a/components/app_modal/javascript_app_modal_dialog.cc
+++ b/components/app_modal/javascript_app_modal_dialog.cc
@@ -4,6 +4,8 @@
#include "components/app_modal/javascript_app_modal_dialog.h"
+#include "base/metrics/histogram_macros.h"
+#include "base/time/time.h"
#include "build/build_config.h"
#include "components/app_modal/javascript_dialog_manager.h"
#include "components/app_modal/javascript_native_dialog_factory.h"
@@ -72,7 +74,8 @@ JavaScriptAppModalDialog::JavaScriptAppModalDialog(
is_before_unload_dialog_(is_before_unload_dialog),
is_reload_(is_reload),
callback_(callback),
- use_override_prompt_text_(false) {
+ use_override_prompt_text_(false),
+ creation_time_(base::TimeTicks::Now()) {
EnforceMaxTextSize(message_text, &message_text_);
EnforceMaxPromptSize(default_prompt_text, &default_prompt_text_);
}
@@ -95,10 +98,7 @@ void JavaScriptAppModalDialog::Invalidate() {
return;
AppModalDialog::Invalidate();
- if (!callback_.is_null()) {
- callback_.Run(false, base::string16());
- callback_.Reset();
- }
+ CallDialogClosedCallback(false, base::string16());
if (native_dialog())
CloseModalDialog();
}
@@ -142,12 +142,9 @@ void JavaScriptAppModalDialog::NotifyDelegate(bool success,
if (!IsValid())
return;
- if (!callback_.is_null()) {
- callback_.Run(success, user_input);
- callback_.Reset();
- }
+ CallDialogClosedCallback(success, user_input);
- // The callback_ above may delete web_contents_, thus removing the extra
+ // The close callback above may delete web_contents_, thus removing the extra
// data from the map owned by ::JavaScriptDialogManager. Make sure
// to only use the data if still present. http://crbug.com/236476
ExtraDataMap::iterator extra_data =
@@ -162,6 +159,20 @@ void JavaScriptAppModalDialog::NotifyDelegate(bool success,
AppModalDialog::Invalidate();
}
+void JavaScriptAppModalDialog::CallDialogClosedCallback(bool success,
+ const base::string16& user_input) {
+ // TODO(joenotcharles): Both the callers of this function also check IsValid
+ // and call AppModalDialog::Invalidate, but in different orders. If the
+ // difference is not significant, more common code could be moved here.
+ UMA_HISTOGRAM_MEDIUM_TIMES(
+ "JSDialogs.FineTiming.TimeBetweenDialogCreatedAndSameDialogClosed",
+ base::TimeTicks::Now() - creation_time_);
+ if (!callback_.is_null()) {
+ callback_.Run(success, user_input);
+ callback_.Reset();
+ }
+}
+
// static
std::string JavaScriptAppModalDialog::GetSerializedOriginForWebContents(
content::WebContents* contents) {
diff --git a/components/app_modal/javascript_app_modal_dialog.h b/components/app_modal/javascript_app_modal_dialog.h
index 5c81ef7..111ba7d 100644
--- a/components/app_modal/javascript_app_modal_dialog.h
+++ b/components/app_modal/javascript_app_modal_dialog.h
@@ -10,6 +10,7 @@
#include "base/compiler_specific.h"
#include "base/macros.h"
+#include "base/time/time.h"
#include "components/app_modal/app_modal_dialog.h"
#include "content/public/browser/javascript_dialog_manager.h"
@@ -83,6 +84,9 @@ class JavaScriptAppModalDialog : public AppModalDialog {
void NotifyDelegate(bool success, const base::string16& prompt_text,
bool suppress_js_messages);
+ void CallDialogClosedCallback(bool success,
+ const base::string16& prompt_text);
+
// A map of extra Chrome-only data associated with the delegate_. The keys
// come from |GetSerializedOriginForWebContents|.
ExtraDataMap* extra_data_map_;
@@ -102,6 +106,8 @@ class JavaScriptAppModalDialog : public AppModalDialog {
base::string16 override_prompt_text_;
bool use_override_prompt_text_;
+ base::TimeTicks creation_time_;
+
DISALLOW_COPY_AND_ASSIGN(JavaScriptAppModalDialog);
};
diff --git a/components/app_modal/javascript_dialog_manager.cc b/components/app_modal/javascript_dialog_manager.cc
index a0a08e6..f654f8bf3 100644
--- a/components/app_modal/javascript_dialog_manager.cc
+++ b/components/app_modal/javascript_dialog_manager.cc
@@ -9,6 +9,7 @@
#include "base/bind.h"
#include "base/i18n/rtl.h"
#include "base/macros.h"
+#include "base/metrics/histogram_macros.h"
#include "base/strings/utf_string_conversions.h"
#include "components/app_modal/app_modal_dialog.h"
#include "components/app_modal/app_modal_dialog_queue.h"
@@ -107,6 +108,25 @@ void JavaScriptDialogManager::RunJavaScriptDialog(
return;
}
+ base::TimeTicks now = base::TimeTicks::Now();
+ if (!last_creation_time_.is_null()) {
+ // A new dialog has been created: log the time since the last one was
+ // created.
+ UMA_HISTOGRAM_MEDIUM_TIMES(
+ "JSDialogs.FineTiming.TimeBetweenDialogCreatedAndNextDialogCreated",
+ now - last_creation_time_);
+ }
+ last_creation_time_ = now;
+
+ // Also log the time since a dialog was closed, but only if this is the first
+ // dialog that was opened since the closing.
+ if (!last_close_time_.is_null()) {
+ UMA_HISTOGRAM_MEDIUM_TIMES(
+ "JSDialogs.FineTiming.TimeBetweenDialogClosedAndNextDialogCreated",
+ now - last_close_time_);
+ last_close_time_ = base::TimeTicks();
+ }
+
bool is_alert = message_type == content::JAVASCRIPT_MESSAGE_TYPE_ALERT;
base::string16 dialog_title =
GetTitle(web_contents, origin_url, accept_lang, is_alert);
@@ -261,6 +281,8 @@ void JavaScriptDialogManager::OnDialogClosed(
// their WebContents is destroyed so |web_contents| is still valid here.)
extensions_client_->OnDialogClosed(web_contents);
+ last_close_time_ = base::TimeTicks::Now();
+
callback.Run(success, user_input);
}
diff --git a/components/app_modal/javascript_dialog_manager.h b/components/app_modal/javascript_dialog_manager.h
index b204aaf8..9d70bd3 100644
--- a/components/app_modal/javascript_dialog_manager.h
+++ b/components/app_modal/javascript_dialog_manager.h
@@ -8,6 +8,7 @@
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/singleton.h"
+#include "base/time/time.h"
#include "components/app_modal/javascript_app_modal_dialog.h"
#include "content/public/browser/javascript_dialog_manager.h"
@@ -80,6 +81,11 @@ class JavaScriptDialogManager : public content::JavaScriptDialogManager {
scoped_ptr<JavaScriptNativeDialogFactory> native_dialog_factory_;
scoped_ptr<JavaScriptDialogExtensionsClient> extensions_client_;
+ // Record a single create and close timestamp to track the time between
+ // dialogs. (Since Javascript dialogs are modal, this is even accurate!)
+ base::TimeTicks last_close_time_;
+ base::TimeTicks last_creation_time_;
+
DISALLOW_COPY_AND_ASSIGN(JavaScriptDialogManager);
};