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

Unified Diff: chrome/browser/resources/google_now/utility.js

Issue 145353010: Gate console.log output in Google Now (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/google_now/utility.js
diff --git a/chrome/browser/resources/google_now/utility.js b/chrome/browser/resources/google_now/utility.js
index 6674edf7754803d8a231179b383d8360daaed637..f1f7884e311476f4d2d1531d78eef47e326ff2e5 100644
--- a/chrome/browser/resources/google_now/utility.js
+++ b/chrome/browser/resources/google_now/utility.js
@@ -29,13 +29,21 @@
*/
var NOTIFICATION_CARDS_URL = 'https://www.googleapis.com/chromenow/v1';
-var DEBUG_MODE = localStorage['debug_mode'];
+/**
+ * Returns true if debug mode is enabled.
+ * localStorage returns items as strings, which means if we store a boolean,
+ * it returns a string. Use this function to compare against true.
+ * @return {boolean} Debug mode is enabled.
skare_ 2014/01/28 21:25:52 tiny nit: Debug mode is enabled -> Whether debug m
robliao 2014/01/28 21:56:02 Done.
+ */
+function isInDebugMode() {
+ return !!localStorage.debug_mode && (localStorage.debug_mode === 'true');
vadimt 2014/01/28 21:07:12 Why do we need the first check (!!localStorage.deb
robliao 2014/01/28 21:56:02 I guess we don't need to check it based off of thi
+}
/**
* Initializes for debug or release modes of operation.
*/
function initializeDebug() {
- if (DEBUG_MODE) {
+ if (isInDebugMode()) {
NOTIFICATION_CARDS_URL =
localStorage['server_url'] || NOTIFICATION_CARDS_URL;
}
@@ -44,6 +52,18 @@ function initializeDebug() {
initializeDebug();
/**
+ * Conditionally allow console.log output based off of the debug mode.
+ */
+console.log = function() {
+ var originalConsoleLog = console.log;
skare_ 2014/01/28 21:25:52 any chance this and the other replacement will be
robliao 2014/01/28 21:56:02 There aren't any includes in JS world, just Chrome
+ return function() {
+ if (isInDebugMode()) {
+ originalConsoleLog.apply(console, arguments);
+ }
+ };
+}();
+
+/**
* Location Card Storage.
*/
if (localStorage['locationCardsShown'] === undefined)
@@ -171,7 +191,7 @@ function reportError(error) {
chrome.metricsPrivate.getIsCrashReportingEnabled(function(isEnabled) {
if (isEnabled)
sendErrorReport(error);
- if (DEBUG_MODE)
+ if (isInDebugMode())
alert(message);
});
}

Powered by Google App Engine
This is Rietveld 408576698