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

Side by Side Diff: content/browser/service_worker/service_worker_internals_ui.cc

Issue 1221643014: Service Worker: Migrate to version_uuid and surface ServiceWorker.id. (Chromium 2/3) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/service_worker/service_worker_internals_ui.h" 5 #include "content/browser/service_worker/service_worker_internals_ui.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 internals->web_ui()->CallJavascriptFunction( 57 internals->web_ui()->CallJavascriptFunction(
58 "serviceworker.onOperationComplete", 58 "serviceworker.onOperationComplete",
59 FundamentalValue(static_cast<int>(status)), 59 FundamentalValue(static_cast<int>(status)),
60 FundamentalValue(callback_id)); 60 FundamentalValue(callback_id));
61 } 61 }
62 } 62 }
63 63
64 void CallServiceWorkerVersionMethodWithVersionID( 64 void CallServiceWorkerVersionMethodWithVersionID(
65 ServiceWorkerInternalsUI::ServiceWorkerVersionMethod method, 65 ServiceWorkerInternalsUI::ServiceWorkerVersionMethod method,
66 scoped_refptr<ServiceWorkerContextWrapper> context, 66 scoped_refptr<ServiceWorkerContextWrapper> context,
67 int64 version_id, 67 std::string version_uuid,
68 const ServiceWorkerInternalsUI::StatusCallback& callback) { 68 const ServiceWorkerInternalsUI::StatusCallback& callback) {
69 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { 69 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
70 BrowserThread::PostTask( 70 BrowserThread::PostTask(
71 BrowserThread::IO, 71 BrowserThread::IO, FROM_HERE,
72 FROM_HERE, 72 base::Bind(CallServiceWorkerVersionMethodWithVersionID, method, context,
73 base::Bind(CallServiceWorkerVersionMethodWithVersionID, 73 version_uuid, callback));
74 method,
75 context,
76 version_id,
77 callback));
78 return; 74 return;
79 } 75 }
80 76
81 scoped_refptr<ServiceWorkerVersion> version = 77 scoped_refptr<ServiceWorkerVersion> version =
82 context->GetLiveVersion(version_id); 78 context->GetLiveVersion(version_uuid);
83 if (!version.get()) { 79 if (!version.get()) {
84 callback.Run(SERVICE_WORKER_ERROR_NOT_FOUND); 80 callback.Run(SERVICE_WORKER_ERROR_NOT_FOUND);
85 return; 81 return;
86 } 82 }
87 (*version.get().*method)(callback); 83 (*version.get().*method)(callback);
88 } 84 }
89 85
90 void DispatchPushEventWithVersionID( 86 void DispatchPushEventWithVersionID(
91 scoped_refptr<ServiceWorkerContextWrapper> context, 87 scoped_refptr<ServiceWorkerContextWrapper> context,
92 int64 version_id, 88 std::string version_uuid,
93 const ServiceWorkerInternalsUI::StatusCallback& callback) { 89 const ServiceWorkerInternalsUI::StatusCallback& callback) {
94 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { 90 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
95 BrowserThread::PostTask( 91 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
96 BrowserThread::IO, 92 base::Bind(DispatchPushEventWithVersionID, context,
97 FROM_HERE, 93 version_uuid, callback));
98 base::Bind(DispatchPushEventWithVersionID,
99 context,
100 version_id,
101 callback));
102 return; 94 return;
103 } 95 }
104 96
105 scoped_refptr<ServiceWorkerVersion> version = 97 scoped_refptr<ServiceWorkerVersion> version =
106 context->GetLiveVersion(version_id); 98 context->GetLiveVersion(version_uuid);
107 if (!version.get()) { 99 if (!version.get()) {
108 callback.Run(SERVICE_WORKER_ERROR_NOT_FOUND); 100 callback.Run(SERVICE_WORKER_ERROR_NOT_FOUND);
109 return; 101 return;
110 } 102 }
111 std::string data = "Test push message from ServiceWorkerInternals."; 103 std::string data = "Test push message from ServiceWorkerInternals.";
112 version->DispatchPushEvent(callback, data); 104 version->DispatchPushEvent(callback, data);
113 } 105 }
114 106
115 void UpdateVersionInfo(const ServiceWorkerVersionInfo& version, 107 void UpdateVersionInfo(const ServiceWorkerVersionInfo& version,
116 DictionaryValue* info) { 108 DictionaryValue* info) {
(...skipping 26 matching lines...) Expand all
143 info->SetString("status", "ACTIVATING"); 135 info->SetString("status", "ACTIVATING");
144 break; 136 break;
145 case ServiceWorkerVersion::ACTIVATED: 137 case ServiceWorkerVersion::ACTIVATED:
146 info->SetString("status", "ACTIVATED"); 138 info->SetString("status", "ACTIVATED");
147 break; 139 break;
148 case ServiceWorkerVersion::REDUNDANT: 140 case ServiceWorkerVersion::REDUNDANT:
149 info->SetString("status", "REDUNDANT"); 141 info->SetString("status", "REDUNDANT");
150 break; 142 break;
151 } 143 }
152 info->SetString("script_url", version.script_url.spec()); 144 info->SetString("script_url", version.script_url.spec());
153 info->SetString("version_id", base::Int64ToString(version.version_id)); 145 info->SetString("version_uuid", version.version_uuid);
154 info->SetInteger("process_id", version.process_id); 146 info->SetInteger("process_id", version.process_id);
155 info->SetInteger("thread_id", version.thread_id); 147 info->SetInteger("thread_id", version.thread_id);
156 info->SetInteger("devtools_agent_route_id", version.devtools_agent_route_id); 148 info->SetInteger("devtools_agent_route_id", version.devtools_agent_route_id);
157 } 149 }
158 150
159 ListValue* GetRegistrationListValue( 151 ListValue* GetRegistrationListValue(
160 const std::vector<ServiceWorkerRegistrationInfo>& registrations) { 152 const std::vector<ServiceWorkerRegistrationInfo>& registrations) {
161 ListValue* result = new ListValue(); 153 ListValue* result = new ListValue();
162 for (std::vector<ServiceWorkerRegistrationInfo>::const_iterator it = 154 for (std::vector<ServiceWorkerRegistrationInfo>::const_iterator it =
163 registrations.begin(); 155 registrations.begin();
164 it != registrations.end(); 156 it != registrations.end();
165 ++it) { 157 ++it) {
166 const ServiceWorkerRegistrationInfo& registration = *it; 158 const ServiceWorkerRegistrationInfo& registration = *it;
167 DictionaryValue* registration_info = new DictionaryValue(); 159 DictionaryValue* registration_info = new DictionaryValue();
168 registration_info->SetString("scope", registration.pattern.spec()); 160 registration_info->SetString("scope", registration.pattern.spec());
169 registration_info->SetString( 161 registration_info->SetString(
170 "registration_id", base::Int64ToString(registration.registration_id)); 162 "registration_id", base::Int64ToString(registration.registration_id));
171 163
172 if (registration.active_version.version_id != 164 if (!registration.active_version.version_uuid.empty()) {
173 kInvalidServiceWorkerVersionId) {
174 DictionaryValue* active_info = new DictionaryValue(); 165 DictionaryValue* active_info = new DictionaryValue();
175 UpdateVersionInfo(registration.active_version, active_info); 166 UpdateVersionInfo(registration.active_version, active_info);
176 registration_info->Set("active", active_info); 167 registration_info->Set("active", active_info);
177 } 168 }
178 169
179 if (registration.waiting_version.version_id != 170 if (!registration.waiting_version.version_uuid.empty()) {
180 kInvalidServiceWorkerVersionId) {
181 DictionaryValue* waiting_info = new DictionaryValue(); 171 DictionaryValue* waiting_info = new DictionaryValue();
182 UpdateVersionInfo(registration.waiting_version, waiting_info); 172 UpdateVersionInfo(registration.waiting_version, waiting_info);
183 registration_info->Set("waiting", waiting_info); 173 registration_info->Set("waiting", waiting_info);
184 } 174 }
185 175
186 result->Append(registration_info); 176 result->Append(registration_info);
187 } 177 }
188 return result; 178 return result;
189 } 179 }
190 180
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 234
245 } // namespace 235 } // namespace
246 236
247 class ServiceWorkerInternalsUI::PartitionObserver 237 class ServiceWorkerInternalsUI::PartitionObserver
248 : public ServiceWorkerContextObserver { 238 : public ServiceWorkerContextObserver {
249 public: 239 public:
250 PartitionObserver(int partition_id, WebUI* web_ui) 240 PartitionObserver(int partition_id, WebUI* web_ui)
251 : partition_id_(partition_id), web_ui_(web_ui) {} 241 : partition_id_(partition_id), web_ui_(web_ui) {}
252 ~PartitionObserver() override {} 242 ~PartitionObserver() override {}
253 // ServiceWorkerContextObserver overrides: 243 // ServiceWorkerContextObserver overrides:
254 void OnRunningStateChanged(int64 version_id, 244 void OnRunningStateChanged(std::string version_uuid,
255 ServiceWorkerVersion::RunningStatus) override { 245 ServiceWorkerVersion::RunningStatus) override {
256 DCHECK_CURRENTLY_ON(BrowserThread::UI); 246 DCHECK_CURRENTLY_ON(BrowserThread::UI);
257 web_ui_->CallJavascriptFunction( 247 web_ui_->CallJavascriptFunction("serviceworker.onRunningStateChanged",
258 "serviceworker.onRunningStateChanged", FundamentalValue(partition_id_), 248 FundamentalValue(partition_id_),
259 StringValue(base::Int64ToString(version_id))); 249 StringValue(version_uuid));
260 } 250 }
261 void OnVersionStateChanged(int64 version_id, 251 void OnVersionStateChanged(std::string version_uuid,
262 ServiceWorkerVersion::Status) override { 252 ServiceWorkerVersion::Status) override {
263 DCHECK_CURRENTLY_ON(BrowserThread::UI); 253 DCHECK_CURRENTLY_ON(BrowserThread::UI);
264 web_ui_->CallJavascriptFunction( 254 web_ui_->CallJavascriptFunction("serviceworker.onVersionStateChanged",
265 "serviceworker.onVersionStateChanged", 255 FundamentalValue(partition_id_),
266 FundamentalValue(partition_id_), 256 StringValue(version_uuid));
267 StringValue(base::Int64ToString(version_id)));
268 } 257 }
269 void OnErrorReported(int64 version_id, 258 void OnErrorReported(std::string version_uuid,
270 int process_id, 259 int process_id,
271 int thread_id, 260 int thread_id,
272 const ErrorInfo& info) override { 261 const ErrorInfo& info) override {
273 DCHECK_CURRENTLY_ON(BrowserThread::UI); 262 DCHECK_CURRENTLY_ON(BrowserThread::UI);
274 ScopedVector<const Value> args; 263 ScopedVector<const Value> args;
275 args.push_back(new FundamentalValue(partition_id_)); 264 args.push_back(new FundamentalValue(partition_id_));
276 args.push_back(new StringValue(base::Int64ToString(version_id))); 265 args.push_back(new StringValue(version_uuid));
277 args.push_back(new FundamentalValue(process_id)); 266 args.push_back(new FundamentalValue(process_id));
278 args.push_back(new FundamentalValue(thread_id)); 267 args.push_back(new FundamentalValue(thread_id));
279 scoped_ptr<DictionaryValue> value(new DictionaryValue()); 268 scoped_ptr<DictionaryValue> value(new DictionaryValue());
280 value->SetString("message", info.error_message); 269 value->SetString("message", info.error_message);
281 value->SetInteger("lineNumber", info.line_number); 270 value->SetInteger("lineNumber", info.line_number);
282 value->SetInteger("columnNumber", info.column_number); 271 value->SetInteger("columnNumber", info.column_number);
283 value->SetString("sourceURL", info.source_url.spec()); 272 value->SetString("sourceURL", info.source_url.spec());
284 args.push_back(value.release()); 273 args.push_back(value.release());
285 web_ui_->CallJavascriptFunction("serviceworker.onErrorReported", 274 web_ui_->CallJavascriptFunction("serviceworker.onErrorReported",
286 args.get()); 275 args.get());
287 } 276 }
288 void OnReportConsoleMessage(int64 version_id, 277 void OnReportConsoleMessage(std::string version_uuid,
289 int process_id, 278 int process_id,
290 int thread_id, 279 int thread_id,
291 const ConsoleMessage& message) override { 280 const ConsoleMessage& message) override {
292 DCHECK_CURRENTLY_ON(BrowserThread::UI); 281 DCHECK_CURRENTLY_ON(BrowserThread::UI);
293 ScopedVector<const Value> args; 282 ScopedVector<const Value> args;
294 args.push_back(new FundamentalValue(partition_id_)); 283 args.push_back(new FundamentalValue(partition_id_));
295 args.push_back(new StringValue(base::Int64ToString(version_id))); 284 args.push_back(new StringValue(version_uuid));
296 args.push_back(new FundamentalValue(process_id)); 285 args.push_back(new FundamentalValue(process_id));
297 args.push_back(new FundamentalValue(thread_id)); 286 args.push_back(new FundamentalValue(thread_id));
298 scoped_ptr<DictionaryValue> value(new DictionaryValue()); 287 scoped_ptr<DictionaryValue> value(new DictionaryValue());
299 value->SetInteger("sourceIdentifier", message.source_identifier); 288 value->SetInteger("sourceIdentifier", message.source_identifier);
300 value->SetInteger("message_level", message.message_level); 289 value->SetInteger("message_level", message.message_level);
301 value->SetString("message", message.message); 290 value->SetString("message", message.message);
302 value->SetInteger("lineNumber", message.line_number); 291 value->SetInteger("lineNumber", message.line_number);
303 value->SetString("sourceURL", message.source_url.spec()); 292 value->SetString("sourceURL", message.source_url.spec());
304 args.push_back(value.release()); 293 args.push_back(value.release());
305 web_ui_->CallJavascriptFunction("serviceworker.onConsoleMessageReported", 294 web_ui_->CallJavascriptFunction("serviceworker.onConsoleMessageReported",
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 } 477 }
489 478
490 void ServiceWorkerInternalsUI::CallServiceWorkerVersionMethod( 479 void ServiceWorkerInternalsUI::CallServiceWorkerVersionMethod(
491 ServiceWorkerVersionMethod method, 480 ServiceWorkerVersionMethod method,
492 const ListValue* args) { 481 const ListValue* args) {
493 DCHECK_CURRENTLY_ON(BrowserThread::UI); 482 DCHECK_CURRENTLY_ON(BrowserThread::UI);
494 int callback_id; 483 int callback_id;
495 const DictionaryValue* cmd_args = NULL; 484 const DictionaryValue* cmd_args = NULL;
496 int partition_id; 485 int partition_id;
497 scoped_refptr<ServiceWorkerContextWrapper> context; 486 scoped_refptr<ServiceWorkerContextWrapper> context;
498 std::string version_id_string; 487 std::string version_uuid;
499 int64 version_id = 0;
500 if (!args->GetInteger(0, &callback_id) || 488 if (!args->GetInteger(0, &callback_id) ||
501 !args->GetDictionary(1, &cmd_args) || 489 !args->GetDictionary(1, &cmd_args) ||
502 !cmd_args->GetInteger("partition_id", &partition_id) || 490 !cmd_args->GetInteger("partition_id", &partition_id) ||
503 !GetServiceWorkerContext(partition_id, &context) || 491 !GetServiceWorkerContext(partition_id, &context) ||
504 !cmd_args->GetString("version_id", &version_id_string) || 492 !cmd_args->GetString("version_uuid", &version_uuid)) {
505 !base::StringToInt64(version_id_string, &version_id)) {
506 return; 493 return;
507 } 494 }
508 495
509 base::Callback<void(ServiceWorkerStatusCode)> callback = 496 base::Callback<void(ServiceWorkerStatusCode)> callback =
510 base::Bind(OperationCompleteCallback, AsWeakPtr(), callback_id); 497 base::Bind(OperationCompleteCallback, AsWeakPtr(), callback_id);
511 CallServiceWorkerVersionMethodWithVersionID( 498 CallServiceWorkerVersionMethodWithVersionID(method, context, version_uuid,
512 method, context, version_id, callback); 499 callback);
513 } 500 }
514 501
515 void ServiceWorkerInternalsUI::DispatchPushEvent( 502 void ServiceWorkerInternalsUI::DispatchPushEvent(
516 const ListValue* args) { 503 const ListValue* args) {
517 DCHECK_CURRENTLY_ON(BrowserThread::UI); 504 DCHECK_CURRENTLY_ON(BrowserThread::UI);
518 int callback_id; 505 int callback_id;
519 int partition_id; 506 int partition_id;
520 int64 version_id = 0; 507 std::string version_uuid = 0;
521 std::string version_id_string;
522 const DictionaryValue* cmd_args = NULL; 508 const DictionaryValue* cmd_args = NULL;
523 scoped_refptr<ServiceWorkerContextWrapper> context; 509 scoped_refptr<ServiceWorkerContextWrapper> context;
524 if (!args->GetInteger(0, &callback_id) || 510 if (!args->GetInteger(0, &callback_id) ||
525 !args->GetDictionary(1, &cmd_args) || 511 !args->GetDictionary(1, &cmd_args) ||
526 !cmd_args->GetInteger("partition_id", &partition_id) || 512 !cmd_args->GetInteger("partition_id", &partition_id) ||
527 !GetServiceWorkerContext(partition_id, &context) || 513 !GetServiceWorkerContext(partition_id, &context) ||
528 !cmd_args->GetString("version_id", &version_id_string) || 514 !cmd_args->GetString("version_uuid", &version_uuid)) {
529 !base::StringToInt64(version_id_string, &version_id)) {
530 return; 515 return;
531 } 516 }
532 517
533 base::Callback<void(ServiceWorkerStatusCode)> callback = 518 base::Callback<void(ServiceWorkerStatusCode)> callback =
534 base::Bind(OperationCompleteCallback, AsWeakPtr(), callback_id); 519 base::Bind(OperationCompleteCallback, AsWeakPtr(), callback_id);
535 DispatchPushEventWithVersionID(context, version_id, callback); 520 DispatchPushEventWithVersionID(context, version_uuid, callback);
536 } 521 }
537 522
538 void ServiceWorkerInternalsUI::InspectWorker(const ListValue* args) { 523 void ServiceWorkerInternalsUI::InspectWorker(const ListValue* args) {
539 DCHECK_CURRENTLY_ON(BrowserThread::UI); 524 DCHECK_CURRENTLY_ON(BrowserThread::UI);
540 int callback_id; 525 int callback_id;
541 const DictionaryValue* cmd_args = NULL; 526 const DictionaryValue* cmd_args = NULL;
542 int process_id = 0; 527 int process_id = 0;
543 int devtools_agent_route_id = 0; 528 int devtools_agent_route_id = 0;
544 if (!args->GetInteger(0, &callback_id) || 529 if (!args->GetInteger(0, &callback_id) ||
545 !args->GetDictionary(1, &cmd_args) || 530 !args->GetDictionary(1, &cmd_args) ||
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 callback.Run(SERVICE_WORKER_ERROR_ABORT); 601 callback.Run(SERVICE_WORKER_ERROR_ABORT);
617 return; 602 return;
618 } 603 }
619 604
620 // ServiceWorkerContextWrapper::UnregisterServiceWorker doesn't work here 605 // ServiceWorkerContextWrapper::UnregisterServiceWorker doesn't work here
621 // because that reduces a status code to boolean. 606 // because that reduces a status code to boolean.
622 context->context()->UnregisterServiceWorker(scope, callback); 607 context->context()->UnregisterServiceWorker(scope, callback);
623 } 608 }
624 609
625 } // namespace content 610 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/service_worker/service_worker_info.cc ('k') | content/browser/service_worker/service_worker_job_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698