| OLD | NEW |
| 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/appcache/view_appcache_internals_job.h" | 5 #include "content/browser/appcache/view_appcache_internals_job.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/base64.h" | 10 #include "base/base64.h" |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 appcache_service_(service), | 318 appcache_service_(service), |
| 319 appcache_storage_(service->storage()) { | 319 appcache_storage_(service->storage()) { |
| 320 appcache_service_->AddObserver(this); | 320 appcache_service_->AddObserver(this); |
| 321 } | 321 } |
| 322 | 322 |
| 323 virtual ~BaseInternalsJob() { | 323 virtual ~BaseInternalsJob() { |
| 324 appcache_service_->RemoveObserver(this); | 324 appcache_service_->RemoveObserver(this); |
| 325 } | 325 } |
| 326 | 326 |
| 327 virtual void OnServiceReinitialized( | 327 virtual void OnServiceReinitialized( |
| 328 AppCacheStorageReference* old_storage_ref) OVERRIDE { | 328 AppCacheStorageReference* old_storage_ref) override { |
| 329 if (old_storage_ref->storage() == appcache_storage_) | 329 if (old_storage_ref->storage() == appcache_storage_) |
| 330 disabled_storage_reference_ = old_storage_ref; | 330 disabled_storage_reference_ = old_storage_ref; |
| 331 } | 331 } |
| 332 | 332 |
| 333 AppCacheServiceImpl* appcache_service_; | 333 AppCacheServiceImpl* appcache_service_; |
| 334 AppCacheStorage* appcache_storage_; | 334 AppCacheStorage* appcache_storage_; |
| 335 scoped_refptr<AppCacheStorageReference> disabled_storage_reference_; | 335 scoped_refptr<AppCacheStorageReference> disabled_storage_reference_; |
| 336 }; | 336 }; |
| 337 | 337 |
| 338 // Job that lists all appcaches in the system. | 338 // Job that lists all appcaches in the system. |
| 339 class MainPageJob : public BaseInternalsJob { | 339 class MainPageJob : public BaseInternalsJob { |
| 340 public: | 340 public: |
| 341 MainPageJob(net::URLRequest* request, | 341 MainPageJob(net::URLRequest* request, |
| 342 net::NetworkDelegate* network_delegate, | 342 net::NetworkDelegate* network_delegate, |
| 343 AppCacheServiceImpl* service) | 343 AppCacheServiceImpl* service) |
| 344 : BaseInternalsJob(request, network_delegate, service), | 344 : BaseInternalsJob(request, network_delegate, service), |
| 345 weak_factory_(this) { | 345 weak_factory_(this) { |
| 346 } | 346 } |
| 347 | 347 |
| 348 virtual void Start() OVERRIDE { | 348 virtual void Start() override { |
| 349 DCHECK(request_); | 349 DCHECK(request_); |
| 350 info_collection_ = new AppCacheInfoCollection; | 350 info_collection_ = new AppCacheInfoCollection; |
| 351 appcache_service_->GetAllAppCacheInfo( | 351 appcache_service_->GetAllAppCacheInfo( |
| 352 info_collection_.get(), | 352 info_collection_.get(), |
| 353 base::Bind(&MainPageJob::OnGotInfoComplete, | 353 base::Bind(&MainPageJob::OnGotInfoComplete, |
| 354 weak_factory_.GetWeakPtr())); | 354 weak_factory_.GetWeakPtr())); |
| 355 } | 355 } |
| 356 | 356 |
| 357 // Produces a page containing the listing | 357 // Produces a page containing the listing |
| 358 virtual int GetData(std::string* mime_type, | 358 virtual int GetData(std::string* mime_type, |
| 359 std::string* charset, | 359 std::string* charset, |
| 360 std::string* out, | 360 std::string* out, |
| 361 const net::CompletionCallback& callback) const OVERRIDE { | 361 const net::CompletionCallback& callback) const override { |
| 362 mime_type->assign("text/html"); | 362 mime_type->assign("text/html"); |
| 363 charset->assign("UTF-8"); | 363 charset->assign("UTF-8"); |
| 364 | 364 |
| 365 out->clear(); | 365 out->clear(); |
| 366 EmitPageStart(out); | 366 EmitPageStart(out); |
| 367 if (!info_collection_.get()) { | 367 if (!info_collection_.get()) { |
| 368 out->append(kErrorMessage); | 368 out->append(kErrorMessage); |
| 369 } else if (info_collection_->infos_by_origin.empty()) { | 369 } else if (info_collection_->infos_by_origin.empty()) { |
| 370 out->append(kEmptyAppCachesMessage); | 370 out->append(kEmptyAppCachesMessage); |
| 371 } else { | 371 } else { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 class RedirectToMainPageJob : public BaseInternalsJob { | 404 class RedirectToMainPageJob : public BaseInternalsJob { |
| 405 public: | 405 public: |
| 406 RedirectToMainPageJob(net::URLRequest* request, | 406 RedirectToMainPageJob(net::URLRequest* request, |
| 407 net::NetworkDelegate* network_delegate, | 407 net::NetworkDelegate* network_delegate, |
| 408 AppCacheServiceImpl* service) | 408 AppCacheServiceImpl* service) |
| 409 : BaseInternalsJob(request, network_delegate, service) {} | 409 : BaseInternalsJob(request, network_delegate, service) {} |
| 410 | 410 |
| 411 virtual int GetData(std::string* mime_type, | 411 virtual int GetData(std::string* mime_type, |
| 412 std::string* charset, | 412 std::string* charset, |
| 413 std::string* data, | 413 std::string* data, |
| 414 const net::CompletionCallback& callback) const OVERRIDE { | 414 const net::CompletionCallback& callback) const override { |
| 415 return net::OK; // IsRedirectResponse induces a redirect. | 415 return net::OK; // IsRedirectResponse induces a redirect. |
| 416 } | 416 } |
| 417 | 417 |
| 418 virtual bool IsRedirectResponse(GURL* location, | 418 virtual bool IsRedirectResponse(GURL* location, |
| 419 int* http_status_code) OVERRIDE { | 419 int* http_status_code) override { |
| 420 *location = ClearQuery(request_->url()); | 420 *location = ClearQuery(request_->url()); |
| 421 *http_status_code = 307; | 421 *http_status_code = 307; |
| 422 return true; | 422 return true; |
| 423 } | 423 } |
| 424 | 424 |
| 425 protected: | 425 protected: |
| 426 virtual ~RedirectToMainPageJob() {} | 426 virtual ~RedirectToMainPageJob() {} |
| 427 }; | 427 }; |
| 428 | 428 |
| 429 // Job that removes an appcache and then redirects back to the main page. | 429 // Job that removes an appcache and then redirects back to the main page. |
| 430 class RemoveAppCacheJob : public RedirectToMainPageJob { | 430 class RemoveAppCacheJob : public RedirectToMainPageJob { |
| 431 public: | 431 public: |
| 432 RemoveAppCacheJob( | 432 RemoveAppCacheJob( |
| 433 net::URLRequest* request, | 433 net::URLRequest* request, |
| 434 net::NetworkDelegate* network_delegate, | 434 net::NetworkDelegate* network_delegate, |
| 435 AppCacheServiceImpl* service, | 435 AppCacheServiceImpl* service, |
| 436 const GURL& manifest_url) | 436 const GURL& manifest_url) |
| 437 : RedirectToMainPageJob(request, network_delegate, service), | 437 : RedirectToMainPageJob(request, network_delegate, service), |
| 438 manifest_url_(manifest_url), | 438 manifest_url_(manifest_url), |
| 439 weak_factory_(this) { | 439 weak_factory_(this) { |
| 440 } | 440 } |
| 441 | 441 |
| 442 virtual void Start() OVERRIDE { | 442 virtual void Start() override { |
| 443 DCHECK(request_); | 443 DCHECK(request_); |
| 444 | 444 |
| 445 appcache_service_->DeleteAppCacheGroup( | 445 appcache_service_->DeleteAppCacheGroup( |
| 446 manifest_url_,base::Bind(&RemoveAppCacheJob::OnDeleteAppCacheComplete, | 446 manifest_url_,base::Bind(&RemoveAppCacheJob::OnDeleteAppCacheComplete, |
| 447 weak_factory_.GetWeakPtr())); | 447 weak_factory_.GetWeakPtr())); |
| 448 } | 448 } |
| 449 | 449 |
| 450 private: | 450 private: |
| 451 virtual ~RemoveAppCacheJob() {} | 451 virtual ~RemoveAppCacheJob() {} |
| 452 | 452 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 464 public AppCacheStorage::Delegate { | 464 public AppCacheStorage::Delegate { |
| 465 public: | 465 public: |
| 466 ViewAppCacheJob( | 466 ViewAppCacheJob( |
| 467 net::URLRequest* request, | 467 net::URLRequest* request, |
| 468 net::NetworkDelegate* network_delegate, | 468 net::NetworkDelegate* network_delegate, |
| 469 AppCacheServiceImpl* service, | 469 AppCacheServiceImpl* service, |
| 470 const GURL& manifest_url) | 470 const GURL& manifest_url) |
| 471 : BaseInternalsJob(request, network_delegate, service), | 471 : BaseInternalsJob(request, network_delegate, service), |
| 472 manifest_url_(manifest_url) {} | 472 manifest_url_(manifest_url) {} |
| 473 | 473 |
| 474 virtual void Start() OVERRIDE { | 474 virtual void Start() override { |
| 475 DCHECK(request_); | 475 DCHECK(request_); |
| 476 appcache_storage_->LoadOrCreateGroup(manifest_url_, this); | 476 appcache_storage_->LoadOrCreateGroup(manifest_url_, this); |
| 477 } | 477 } |
| 478 | 478 |
| 479 // Produces a page containing the entries listing. | 479 // Produces a page containing the entries listing. |
| 480 virtual int GetData(std::string* mime_type, | 480 virtual int GetData(std::string* mime_type, |
| 481 std::string* charset, | 481 std::string* charset, |
| 482 std::string* out, | 482 std::string* out, |
| 483 const net::CompletionCallback& callback) const OVERRIDE { | 483 const net::CompletionCallback& callback) const override { |
| 484 mime_type->assign("text/html"); | 484 mime_type->assign("text/html"); |
| 485 charset->assign("UTF-8"); | 485 charset->assign("UTF-8"); |
| 486 out->clear(); | 486 out->clear(); |
| 487 EmitPageStart(out); | 487 EmitPageStart(out); |
| 488 if (appcache_info_.manifest_url.is_empty()) { | 488 if (appcache_info_.manifest_url.is_empty()) { |
| 489 out->append(kManifestNotFoundMessage); | 489 out->append(kManifestNotFoundMessage); |
| 490 } else { | 490 } else { |
| 491 GURL base_url = ClearQuery(request_->url()); | 491 GURL base_url = ClearQuery(request_->url()); |
| 492 EmitAppCacheInfo(base_url, appcache_service_, &appcache_info_, out); | 492 EmitAppCacheInfo(base_url, appcache_service_, &appcache_info_, out); |
| 493 EmitAppCacheResourceInfoVector(base_url, | 493 EmitAppCacheResourceInfoVector(base_url, |
| 494 manifest_url_, | 494 manifest_url_, |
| 495 resource_infos_, | 495 resource_infos_, |
| 496 appcache_info_.group_id, | 496 appcache_info_.group_id, |
| 497 out); | 497 out); |
| 498 } | 498 } |
| 499 EmitPageEnd(out); | 499 EmitPageEnd(out); |
| 500 return net::OK; | 500 return net::OK; |
| 501 } | 501 } |
| 502 | 502 |
| 503 private: | 503 private: |
| 504 virtual ~ViewAppCacheJob() { | 504 virtual ~ViewAppCacheJob() { |
| 505 appcache_storage_->CancelDelegateCallbacks(this); | 505 appcache_storage_->CancelDelegateCallbacks(this); |
| 506 } | 506 } |
| 507 | 507 |
| 508 // AppCacheStorage::Delegate override | 508 // AppCacheStorage::Delegate override |
| 509 virtual void OnGroupLoaded( | 509 virtual void OnGroupLoaded( |
| 510 AppCacheGroup* group, const GURL& manifest_url) OVERRIDE { | 510 AppCacheGroup* group, const GURL& manifest_url) override { |
| 511 DCHECK_EQ(manifest_url_, manifest_url); | 511 DCHECK_EQ(manifest_url_, manifest_url); |
| 512 if (group && group->newest_complete_cache()) { | 512 if (group && group->newest_complete_cache()) { |
| 513 appcache_info_.manifest_url = manifest_url; | 513 appcache_info_.manifest_url = manifest_url; |
| 514 appcache_info_.group_id = group->group_id(); | 514 appcache_info_.group_id = group->group_id(); |
| 515 appcache_info_.size = group->newest_complete_cache()->cache_size(); | 515 appcache_info_.size = group->newest_complete_cache()->cache_size(); |
| 516 appcache_info_.creation_time = group->creation_time(); | 516 appcache_info_.creation_time = group->creation_time(); |
| 517 appcache_info_.last_update_time = | 517 appcache_info_.last_update_time = |
| 518 group->newest_complete_cache()->update_time(); | 518 group->newest_complete_cache()->update_time(); |
| 519 appcache_info_.last_access_time = base::Time::Now(); | 519 appcache_info_.last_access_time = base::Time::Now(); |
| 520 group->newest_complete_cache()->ToResourceInfoVector(&resource_infos_); | 520 group->newest_complete_cache()->ToResourceInfoVector(&resource_infos_); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 539 net::NetworkDelegate* network_delegate, | 539 net::NetworkDelegate* network_delegate, |
| 540 AppCacheServiceImpl* service, | 540 AppCacheServiceImpl* service, |
| 541 const GURL& manifest_url, | 541 const GURL& manifest_url, |
| 542 const GURL& entry_url, | 542 const GURL& entry_url, |
| 543 int64 response_id, int64 group_id) | 543 int64 response_id, int64 group_id) |
| 544 : BaseInternalsJob(request, network_delegate, service), | 544 : BaseInternalsJob(request, network_delegate, service), |
| 545 manifest_url_(manifest_url), entry_url_(entry_url), | 545 manifest_url_(manifest_url), entry_url_(entry_url), |
| 546 response_id_(response_id), group_id_(group_id), amount_read_(0) { | 546 response_id_(response_id), group_id_(group_id), amount_read_(0) { |
| 547 } | 547 } |
| 548 | 548 |
| 549 virtual void Start() OVERRIDE { | 549 virtual void Start() override { |
| 550 DCHECK(request_); | 550 DCHECK(request_); |
| 551 appcache_storage_->LoadResponseInfo( | 551 appcache_storage_->LoadResponseInfo( |
| 552 manifest_url_, group_id_, response_id_, this); | 552 manifest_url_, group_id_, response_id_, this); |
| 553 } | 553 } |
| 554 | 554 |
| 555 // Produces a page containing the response headers and data. | 555 // Produces a page containing the response headers and data. |
| 556 virtual int GetData(std::string* mime_type, | 556 virtual int GetData(std::string* mime_type, |
| 557 std::string* charset, | 557 std::string* charset, |
| 558 std::string* out, | 558 std::string* out, |
| 559 const net::CompletionCallback& callback) const OVERRIDE { | 559 const net::CompletionCallback& callback) const override { |
| 560 mime_type->assign("text/html"); | 560 mime_type->assign("text/html"); |
| 561 charset->assign("UTF-8"); | 561 charset->assign("UTF-8"); |
| 562 out->clear(); | 562 out->clear(); |
| 563 EmitPageStart(out); | 563 EmitPageStart(out); |
| 564 EmitAnchor(entry_url_.spec(), entry_url_.spec(), out); | 564 EmitAnchor(entry_url_.spec(), entry_url_.spec(), out); |
| 565 out->append("<br/>\n"); | 565 out->append("<br/>\n"); |
| 566 if (response_info_.get()) { | 566 if (response_info_.get()) { |
| 567 if (response_info_->http_response_info()) | 567 if (response_info_->http_response_info()) |
| 568 EmitResponseHeaders(response_info_->http_response_info()->headers.get(), | 568 EmitResponseHeaders(response_info_->http_response_info()->headers.get(), |
| 569 out); | 569 out); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 584 EmitPageEnd(out); | 584 EmitPageEnd(out); |
| 585 return net::OK; | 585 return net::OK; |
| 586 } | 586 } |
| 587 | 587 |
| 588 private: | 588 private: |
| 589 virtual ~ViewEntryJob() { | 589 virtual ~ViewEntryJob() { |
| 590 appcache_storage_->CancelDelegateCallbacks(this); | 590 appcache_storage_->CancelDelegateCallbacks(this); |
| 591 } | 591 } |
| 592 | 592 |
| 593 virtual void OnResponseInfoLoaded( | 593 virtual void OnResponseInfoLoaded( |
| 594 AppCacheResponseInfo* response_info, int64 response_id) OVERRIDE { | 594 AppCacheResponseInfo* response_info, int64 response_id) override { |
| 595 if (!response_info) { | 595 if (!response_info) { |
| 596 StartAsync(); | 596 StartAsync(); |
| 597 return; | 597 return; |
| 598 } | 598 } |
| 599 response_info_ = response_info; | 599 response_info_ = response_info; |
| 600 | 600 |
| 601 // Read the response data, truncating if its too large. | 601 // Read the response data, truncating if its too large. |
| 602 const int64 kLimit = 100 * 1000; | 602 const int64 kLimit = 100 * 1000; |
| 603 int64 amount_to_read = | 603 int64 amount_to_read = |
| 604 std::min(kLimit, response_info->response_data_size()); | 604 std::min(kLimit, response_info->response_data_size()); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 660 return new ViewEntryJob(request, network_delegate, service, | 660 return new ViewEntryJob(request, network_delegate, service, |
| 661 DecodeBase64URL(tokens[0]), // manifest url | 661 DecodeBase64URL(tokens[0]), // manifest url |
| 662 DecodeBase64URL(tokens[1]), // entry url | 662 DecodeBase64URL(tokens[1]), // entry url |
| 663 response_id, group_id); | 663 response_id, group_id); |
| 664 } | 664 } |
| 665 | 665 |
| 666 return new RedirectToMainPageJob(request, network_delegate, service); | 666 return new RedirectToMainPageJob(request, network_delegate, service); |
| 667 } | 667 } |
| 668 | 668 |
| 669 } // namespace content | 669 } // namespace content |
| OLD | NEW |