Added 'error logs' tab to chrome://translte-internals.

Added 'error logs' tab.  For now, simply TranslateErrors::Type is logged.  More error details will be logged when we can get those from Translate API.

BUG=175967
TEST=manual

Review URL: https://chromiumcodereview.appspot.com/15881006

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@202804 0039d316-1c4b-4281-b951-d872f2087c98
parent b53e8da0
<!--
Copyright 2013 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.
-->
<div>
<h2>Error Logs</h2>
<table>
<thead>
<tr>
<th class="error-logs-time">Time</th>
<th class="error-logs-url">URL</th>
<th class="error-logs-error">Error</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
......@@ -88,3 +88,15 @@ td.detection-logs-url {
.detection-logs-language {
width: 10%;
}
.error-logs-time {
width: 20%;
}
.error-logs-url {
width: 40%;
}
.error-logs-error {
width: 40%;
}
......@@ -27,6 +27,7 @@ found in the LICENSE file.
<tabs>
<tab>Prefs</tab>
<tab>Detection Logs</tab>
<tab>Error Logs</tab>
</tabs>
<tabpanels>
......@@ -42,6 +43,12 @@ found in the LICENSE file.
</div>
</tabpanel>
<tabpanel id="error-logs">
<div>
<include src="error_logs.html"/>
</div>
</tabpanel>
</tabpanels>
</tabbox>
......
......@@ -57,6 +57,32 @@
return langCode;
}
/**
* Formats the error type to a human-readable text.
*
* @param {string} error Translation error type from the browser.
* @return {string} The formatted string.
*/
function formatTranslateErrorsType(error) {
// This list is from chrome/common/translate_errors.h. If this header
// file is updated, the below list also should be updated.
var errorStrs = {
0: 'None',
1: 'Network',
2: 'Initialization Error',
3: 'Unknown Language',
4: 'Unsupported Language',
5: 'Identical Languages',
6: 'Translation Error',
};
if (error < 0 || errorStrs.length <= error) {
console.error('Invalid error code:', error);
return 'Invalid Error Code';
}
return errorStrs[error];
}
/**
* Handles the message of 'prefsUpdated' from the browser.
*
......@@ -207,6 +233,30 @@
tbody.appendChild(tr);
}
/**
* Handles the message of 'translateErrorDetailsAdded' from the
* browser.
*
* @param {Object} details The object which represents the logs.
*/
function onTranslateErrorDetailsAdded(details) {
var tr = document.createElement('tr');
var errorStr = details['error'] + ': ' +
formatTranslateErrorsType(details['error']);
[
createTD(formatDate(new Date(details['time'])),
'error-logs-time'),
createTD(details['url'], 'error-logs-url'),
createTD(errorStr, 'error-logs-error'),
].forEach(function(td) {
tr.appendChild(td);
});
var tbody = $('error-logs').getElementsByTagName('tbody')[0];
tbody.appendChild(tr);
}
/**
* The callback entry point from the browser. This function will be
* called by the browser.
......@@ -222,6 +272,9 @@
case 'prefsUpdated':
cr.translateInternals.onPrefsUpdated(detail);
break;
case 'translateErrorDetailsAdded':
cr.translateInternals.onTranslateErrorDetailsAdded(detail);
break;
default:
console.error('Unknown message:', message);
break;
......@@ -233,6 +286,7 @@
messageHandler: messageHandler,
onLanguageDetectionInfoAdded: onLanguageDetectionInfoAdded,
onPrefsUpdated: onPrefsUpdated,
onTranslateErrorDetailsAdded: onTranslateErrorDetailsAdded,
};
});
......
// Copyright 2013 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_TRANSLATE_TRANSLATE_ERROR_DETAILS_H_
#define CHROME_BROWSER_TRANSLATE_TRANSLATE_ERROR_DETAILS_H_
#include "base/time.h"
#include "chrome/common/translate_errors.h"
#include "googleurl/src/gurl.h"
struct TranslateErrorDetails {
// The time when this was created
base::Time time;
// The URL
GURL url;
// Translation error type
TranslateErrors::Type error;
};
#endif
......@@ -22,6 +22,7 @@
#include "chrome/browser/tab_contents/language_state.h"
#include "chrome/browser/tab_contents/tab_util.h"
#include "chrome/browser/translate/page_translated_details.h"
#include "chrome/browser/translate/translate_error_details.h"
#include "chrome/browser/translate/translate_infobar_delegate.h"
#include "chrome/browser/translate/translate_language_list.h"
#include "chrome/browser/translate/translate_manager_metrics.h"
......@@ -333,6 +334,12 @@ void TranslateManager::OnURLFetchComplete(const net::URLFetcher* source) {
ShortcutConfig(),
request.source_lang,
request.target_lang);
TranslateErrorDetails error_details;
error_details.time = base::Time::Now();
error_details.url = entry->GetURL();
error_details.error = TranslateErrors::NETWORK;
NotifyTranslateError(error_details);
} else {
// Translate the page.
DoTranslatePage(web_contents, translate_script_,
......@@ -356,6 +363,10 @@ void TranslateManager::NotifyLanguageDetection(
FOR_EACH_OBSERVER(Observer, observer_list_, OnLanguageDetection(details));
}
void TranslateManager::NotifyTranslateError(
const TranslateErrorDetails& details) {
FOR_EACH_OBSERVER(Observer, observer_list_, OnTranslateError(details));
}
TranslateManager::TranslateManager()
: weak_method_factory_(this),
......@@ -636,10 +647,18 @@ void TranslateManager::PageTranslated(WebContents* web_contents,
TranslateInfoBarDelegate::Create(
InfoBarService::FromWebContents(web_contents), true,
(details->error_type == TranslateErrors::NONE) ?
TranslateInfoBarDelegate::AFTER_TRANSLATE :
TranslateInfoBarDelegate::TRANSLATION_ERROR,
TranslateInfoBarDelegate::AFTER_TRANSLATE :
TranslateInfoBarDelegate::TRANSLATION_ERROR,
details->error_type, prefs, ShortcutConfig(), details->source_language,
details->target_language);
if (details->error_type != TranslateErrors::NONE) {
TranslateErrorDetails error_details;
error_details.time = base::Time::Now();
error_details.url = web_contents->GetActiveURL();
error_details.error = details->error_type;
NotifyTranslateError(error_details);
}
}
bool TranslateManager::IsAcceptLanguage(WebContents* web_contents,
......
......@@ -27,6 +27,7 @@ struct LanguageDetectionDetails;
struct PageTranslatedDetails;
class PrefService;
struct ShortcutConfiguration;
struct TranslateErrorDetails;
class TranslateInfoBarDelegate;
class TranslateLanguageList;
......@@ -119,6 +120,8 @@ class TranslateManager : public content::NotificationObserver,
public:
virtual void OnLanguageDetection(
const LanguageDetectionDetails& details) = 0;
virtual void OnTranslateError(
const TranslateErrorDetails& details) = 0;
};
// Adds/removes observer.
......@@ -178,6 +181,9 @@ class TranslateManager : public content::NotificationObserver,
// Notifies to the observers when a language is detected.
void NotifyLanguageDetection(const LanguageDetectionDetails& details);
// Notifies to the observers when translate failed.
void NotifyTranslateError(const TranslateErrorDetails& details);
// Returns the language to translate to. The language returned is the
// first language found in the following list that is supported by the
// translation service:
......
......@@ -12,6 +12,7 @@
#include "base/prefs/pref_service.h"
#include "base/values.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/translate/translate_error_details.h"
#include "chrome/browser/translate/translate_prefs.h"
#include "chrome/common/language_detection_details.h"
#include "chrome/common/pref_names.h"
......@@ -50,6 +51,18 @@ void TranslateInternalsHandler::OnLanguageDetection(
SendMessageToJs("languageDetectionInfoAdded", dict);
}
void TranslateInternalsHandler::OnTranslateError(
const TranslateErrorDetails& details) {
base::DictionaryValue dict;
dict.Set("time",
new base::FundamentalValue(details.time.ToJsTime()));
dict.Set("url",
new base::StringValue(details.url.spec()));
dict.Set("error",
new base::FundamentalValue(details.error));
SendMessageToJs("translateErrorDetailsAdded", dict);
}
void TranslateInternalsHandler::OnRemovePrefItem(const base::ListValue* args) {
content::WebContents* web_contents = web_ui()->GetWebContents();
Profile* profile =
......
......@@ -12,6 +12,7 @@
#include "webkit/plugins/webplugininfo.h"
struct LanguageDetectionDetails;
struct TranslateErrorDetails;
namespace base {
class DictionaryValue;
......@@ -32,6 +33,8 @@ class TranslateInternalsHandler : public content::WebUIMessageHandler,
// TranslateManager::Observer methods:
virtual void OnLanguageDetection(
const LanguageDetectionDetails& details) OVERRIDE;
virtual void OnTranslateError(
const TranslateErrorDetails& details) OVERRIDE;
private:
// Handles the Javascript message 'removePrefItem'. This message is sent
......
......@@ -2231,6 +2231,7 @@
'browser/toolkit_extra_parts.h',
'browser/translate/options_menu_model.cc',
'browser/translate/options_menu_model.h',
'browser/translate/translate_error_details.h',
'browser/translate/translate_infobar_delegate.cc',
'browser/translate/translate_infobar_delegate.h',
'browser/translate/translate_language_list.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment