Commit 62b1a31d authored by horo's avatar horo Committed by Commit bot

Report error messages to DevTools window.

This cl depends on https://codereview.chromium.org/1036743003/.

BUG=466871

Review URL: https://codereview.chromium.org/1030103003

Cr-Commit-Position: refs/heads/master@{#322354}
parent f32b641d
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/containers/scoped_ptr_hash_map.h" #include "base/containers/scoped_ptr_hash_map.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "content/browser/devtools/service_worker_devtools_agent_host.h" #include "content/browser/devtools/service_worker_devtools_agent_host.h"
#include "content/browser/devtools/service_worker_devtools_manager.h" #include "content/browser/devtools/service_worker_devtools_manager.h"
#include "content/browser/frame_host/frame_tree.h" #include "content/browser/frame_host/frame_tree.h"
...@@ -249,6 +250,8 @@ Response ServiceWorkerHandler::Enable() { ...@@ -249,6 +250,8 @@ Response ServiceWorkerHandler::Enable() {
context_, base::Bind(&ServiceWorkerHandler::OnWorkerRegistrationUpdated, context_, base::Bind(&ServiceWorkerHandler::OnWorkerRegistrationUpdated,
weak_factory_.GetWeakPtr()), weak_factory_.GetWeakPtr()),
base::Bind(&ServiceWorkerHandler::OnWorkerVersionUpdated, base::Bind(&ServiceWorkerHandler::OnWorkerVersionUpdated,
weak_factory_.GetWeakPtr()),
base::Bind(&ServiceWorkerHandler::OnErrorReported,
weak_factory_.GetWeakPtr())); weak_factory_.GetWeakPtr()));
context_watcher_->Start(); context_watcher_->Start();
...@@ -370,6 +373,21 @@ void ServiceWorkerHandler::OnWorkerVersionUpdated( ...@@ -370,6 +373,21 @@ void ServiceWorkerHandler::OnWorkerVersionUpdated(
WorkerVersionUpdatedParams::Create()->set_versions(version_values)); WorkerVersionUpdatedParams::Create()->set_versions(version_values));
} }
void ServiceWorkerHandler::OnErrorReported(
int64 registration_id,
int64 version_id,
const ServiceWorkerContextObserver::ErrorInfo& info) {
client_->WorkerErrorReported(
WorkerErrorReportedParams::Create()->set_error_message(
ServiceWorkerErrorMessage::Create()
->set_error_message(base::UTF16ToUTF8(info.error_message))
->set_registration_id(base::Int64ToString(registration_id))
->set_version_id(base::Int64ToString(version_id))
->set_source_url(info.source_url.spec())
->set_line_number(info.line_number)
->set_column_number(info.column_number)));
}
void ServiceWorkerHandler::DispatchProtocolMessage( void ServiceWorkerHandler::DispatchProtocolMessage(
DevToolsAgentHost* host, DevToolsAgentHost* host,
const std::string& message) { const std::string& message) {
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "content/browser/devtools/protocol/devtools_protocol_handler.h" #include "content/browser/devtools/protocol/devtools_protocol_handler.h"
#include "content/browser/devtools/service_worker_devtools_agent_host.h" #include "content/browser/devtools/service_worker_devtools_agent_host.h"
#include "content/browser/devtools/service_worker_devtools_manager.h" #include "content/browser/devtools/service_worker_devtools_manager.h"
#include "content/browser/service_worker/service_worker_context_observer.h"
#include "content/browser/service_worker/service_worker_info.h" #include "content/browser/service_worker/service_worker_info.h"
#include "content/public/browser/devtools_agent_host.h" #include "content/public/browser/devtools_agent_host.h"
#include "content/public/browser/devtools_agent_host_client.h" #include "content/public/browser/devtools_agent_host_client.h"
...@@ -72,6 +73,9 @@ class ServiceWorkerHandler : public DevToolsAgentHostClient, ...@@ -72,6 +73,9 @@ class ServiceWorkerHandler : public DevToolsAgentHostClient,
const std::vector<ServiceWorkerRegistrationInfo>& registrations); const std::vector<ServiceWorkerRegistrationInfo>& registrations);
void OnWorkerVersionUpdated( void OnWorkerVersionUpdated(
const std::vector<ServiceWorkerVersionInfo>& registrations); const std::vector<ServiceWorkerVersionInfo>& registrations);
void OnErrorReported(int64 registration_id,
int64 version_id,
const ServiceWorkerContextObserver::ErrorInfo& info);
void OpenNewDevToolsWindow(int process_id, int devtools_agent_route_id); void OpenNewDevToolsWindow(int process_id, int devtools_agent_route_id);
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "content/browser/service_worker/service_worker_context_observer.h" #include "content/browser/service_worker/service_worker_context_observer.h"
#include "content/browser/service_worker/service_worker_context_wrapper.h" #include "content/browser/service_worker/service_worker_context_wrapper.h"
#include "content/browser/service_worker/service_worker_version.h" #include "content/browser/service_worker/service_worker_version.h"
#include "content/common/service_worker/service_worker_types.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -26,10 +27,12 @@ bool IsStoppedAndRedundant(const ServiceWorkerVersionInfo& version_info) { ...@@ -26,10 +27,12 @@ bool IsStoppedAndRedundant(const ServiceWorkerVersionInfo& version_info) {
ServiceWorkerContextWatcher::ServiceWorkerContextWatcher( ServiceWorkerContextWatcher::ServiceWorkerContextWatcher(
scoped_refptr<ServiceWorkerContextWrapper> context, scoped_refptr<ServiceWorkerContextWrapper> context,
const WorkerRegistrationUpdatedCallback& registration_callback, const WorkerRegistrationUpdatedCallback& registration_callback,
const WorkerVersionUpdatedCallback& version_callback) const WorkerVersionUpdatedCallback& version_callback,
const WorkerErrorReportedCallback& error_callback)
: context_(context), : context_(context),
registration_callback_(registration_callback), registration_callback_(registration_callback),
version_callback_(version_callback) { version_callback_(version_callback),
error_callback_(error_callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
} }
...@@ -195,6 +198,18 @@ void ServiceWorkerContextWatcher::OnVersionStateChanged( ...@@ -195,6 +198,18 @@ void ServiceWorkerContextWatcher::OnVersionStateChanged(
version_info_map_.erase(version_id); version_info_map_.erase(version_id);
} }
void ServiceWorkerContextWatcher::OnErrorReported(int64 version_id,
int process_id,
int thread_id,
const ErrorInfo& info) {
int64 registration_id = kInvalidServiceWorkerRegistrationId;
if (ServiceWorkerVersionInfo* version = version_info_map_.get(version_id))
registration_id = version->registration_id;
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::Bind(error_callback_, registration_id, version_id, info));
}
void ServiceWorkerContextWatcher::OnRegistrationStored(int64 registration_id, void ServiceWorkerContextWatcher::OnRegistrationStored(int64 registration_id,
const GURL& pattern) { const GURL& pattern) {
SendRegistrationInfo(registration_id, pattern, SendRegistrationInfo(registration_id, pattern,
......
...@@ -27,10 +27,15 @@ class ServiceWorkerContextWatcher ...@@ -27,10 +27,15 @@ class ServiceWorkerContextWatcher
WorkerRegistrationUpdatedCallback; WorkerRegistrationUpdatedCallback;
typedef base::Callback<void(const std::vector<ServiceWorkerVersionInfo>&)> typedef base::Callback<void(const std::vector<ServiceWorkerVersionInfo>&)>
WorkerVersionUpdatedCallback; WorkerVersionUpdatedCallback;
typedef base::Callback<void(int64 /* registration_id */,
int64 /* version_id */,
const ErrorInfo&)> WorkerErrorReportedCallback;
ServiceWorkerContextWatcher( ServiceWorkerContextWatcher(
scoped_refptr<ServiceWorkerContextWrapper> context, scoped_refptr<ServiceWorkerContextWrapper> context,
const WorkerRegistrationUpdatedCallback& registration_callback, const WorkerRegistrationUpdatedCallback& registration_callback,
const WorkerVersionUpdatedCallback& version_callback); const WorkerVersionUpdatedCallback& version_callback,
const WorkerErrorReportedCallback& error_callback);
void Start(); void Start();
void Stop(); void Stop();
...@@ -66,6 +71,10 @@ class ServiceWorkerContextWatcher ...@@ -66,6 +71,10 @@ class ServiceWorkerContextWatcher
void OnVersionStateChanged( void OnVersionStateChanged(
int64 version_id, int64 version_id,
content::ServiceWorkerVersion::Status status) override; content::ServiceWorkerVersion::Status status) override;
void OnErrorReported(int64 version_id,
int process_id,
int thread_id,
const ErrorInfo& info) override;
void OnRegistrationStored(int64 registration_id, void OnRegistrationStored(int64 registration_id,
const GURL& pattern) override; const GURL& pattern) override;
void OnRegistrationDeleted(int64 registration_id, void OnRegistrationDeleted(int64 registration_id,
...@@ -75,6 +84,7 @@ class ServiceWorkerContextWatcher ...@@ -75,6 +84,7 @@ class ServiceWorkerContextWatcher
scoped_refptr<ServiceWorkerContextWrapper> context_; scoped_refptr<ServiceWorkerContextWrapper> context_;
WorkerRegistrationUpdatedCallback registration_callback_; WorkerRegistrationUpdatedCallback registration_callback_;
WorkerVersionUpdatedCallback version_callback_; WorkerVersionUpdatedCallback version_callback_;
WorkerErrorReportedCallback error_callback_;
}; };
} // namespace content } // namespace content
......
...@@ -458,6 +458,8 @@ void ServiceWorkerRegisterJob::CompleteInternal( ...@@ -458,6 +458,8 @@ void ServiceWorkerRegisterJob::CompleteInternal(
if (should_uninstall_on_failure_) if (should_uninstall_on_failure_)
registration()->ClearWhenReady(); registration()->ClearWhenReady();
if (new_version()) { if (new_version()) {
if (status != SERVICE_WORKER_ERROR_EXISTS)
new_version()->ReportError(status, status_message);
registration()->UnsetVersion(new_version()); registration()->UnsetVersion(new_version());
new_version()->Doom(); new_version()->Doom();
} }
......
...@@ -784,6 +784,16 @@ void ServiceWorkerVersion::RemoveListener(Listener* listener) { ...@@ -784,6 +784,16 @@ void ServiceWorkerVersion::RemoveListener(Listener* listener) {
listeners_.RemoveObserver(listener); listeners_.RemoveObserver(listener);
} }
void ServiceWorkerVersion::ReportError(ServiceWorkerStatusCode status,
const std::string& status_message) {
if (status_message.empty()) {
OnReportException(base::UTF8ToUTF16(ServiceWorkerStatusToString(status)),
-1, -1, GURL());
} else {
OnReportException(base::UTF8ToUTF16(status_message), -1, -1, GURL());
}
}
void ServiceWorkerVersion::Doom() { void ServiceWorkerVersion::Doom() {
if (is_doomed_) if (is_doomed_)
return; return;
......
...@@ -280,6 +280,10 @@ class CONTENT_EXPORT ServiceWorkerVersion ...@@ -280,6 +280,10 @@ class CONTENT_EXPORT ServiceWorkerVersion
ServiceWorkerScriptCacheMap* script_cache_map() { return &script_cache_map_; } ServiceWorkerScriptCacheMap* script_cache_map() { return &script_cache_map_; }
EmbeddedWorkerInstance* embedded_worker() { return embedded_worker_.get(); } EmbeddedWorkerInstance* embedded_worker() { return embedded_worker_.get(); }
// Reports the error message to |listeners_|.
void ReportError(ServiceWorkerStatusCode status,
const std::string& status_message);
// Dooms this version to have REDUNDANT status and its resources deleted. If // Dooms this version to have REDUNDANT status and its resources deleted. If
// the version is controlling a page, these changes will happen when the // the version is controlling a page, these changes will happen when the
// version no longer controls any pages. // version no longer controls any pages.
......
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