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

Side by Side Diff: webkit/appcache/view_appcache_internals_job.cc

Issue 10855209: Refactoring: ProtocolHandler::MaybeCreateJob takes NetworkDelegate as argument (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Latest merge Created 8 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « webkit/appcache/view_appcache_internals_job.h ('k') | webkit/blob/blob_url_request_job.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <algorithm> 5 #include <algorithm>
6 #include <string> 6 #include <string>
7 7
8 #include "webkit/appcache/view_appcache_internals_job.h" 8 #include "webkit/appcache/view_appcache_internals_job.h"
9 9
10 #include "base/base64.h" 10 #include "base/base64.h"
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 304
305 GURL ClearQuery(const GURL& url) { 305 GURL ClearQuery(const GURL& url) {
306 GURL::Replacements replacements; 306 GURL::Replacements replacements;
307 replacements.ClearQuery(); 307 replacements.ClearQuery();
308 return url.ReplaceComponents(replacements); 308 return url.ReplaceComponents(replacements);
309 } 309 }
310 310
311 // Simple base class for the job subclasses defined here. 311 // Simple base class for the job subclasses defined here.
312 class BaseInternalsJob : public net::URLRequestSimpleJob { 312 class BaseInternalsJob : public net::URLRequestSimpleJob {
313 protected: 313 protected:
314 BaseInternalsJob(net::URLRequest* request, AppCacheService* service) 314 BaseInternalsJob(net::URLRequest* request,
315 : URLRequestSimpleJob(request), appcache_service_(service) {} 315 net::NetworkDelegate* network_delegate,
316 AppCacheService* service)
317 : URLRequestSimpleJob(request, network_delegate),
318 appcache_service_(service) {}
316 virtual ~BaseInternalsJob() {} 319 virtual ~BaseInternalsJob() {}
317 320
318 AppCacheService* appcache_service_; 321 AppCacheService* appcache_service_;
319 }; 322 };
320 323
321 // Job that lists all appcaches in the system. 324 // Job that lists all appcaches in the system.
322 class MainPageJob : public BaseInternalsJob { 325 class MainPageJob : public BaseInternalsJob {
323 public: 326 public:
324 MainPageJob(net::URLRequest* request, AppCacheService* service) 327 MainPageJob(net::URLRequest* request,
325 : BaseInternalsJob(request, service), 328 net::NetworkDelegate* network_delegate,
329 AppCacheService* service)
330 : BaseInternalsJob(request, network_delegate, service),
326 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { 331 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
327 } 332 }
328 333
329 virtual void Start() { 334 virtual void Start() {
330 DCHECK(request_); 335 DCHECK(request_);
331 info_collection_ = new AppCacheInfoCollection; 336 info_collection_ = new AppCacheInfoCollection;
332 appcache_service_->GetAllAppCacheInfo( 337 appcache_service_->GetAllAppCacheInfo(
333 info_collection_, base::Bind(&MainPageJob::OnGotInfoComplete, 338 info_collection_, base::Bind(&MainPageJob::OnGotInfoComplete,
334 weak_factory_.GetWeakPtr())); 339 weak_factory_.GetWeakPtr()));
335 } 340 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 } 381 }
377 382
378 base::WeakPtrFactory<MainPageJob> weak_factory_; 383 base::WeakPtrFactory<MainPageJob> weak_factory_;
379 scoped_refptr<AppCacheInfoCollection> info_collection_; 384 scoped_refptr<AppCacheInfoCollection> info_collection_;
380 DISALLOW_COPY_AND_ASSIGN(MainPageJob); 385 DISALLOW_COPY_AND_ASSIGN(MainPageJob);
381 }; 386 };
382 387
383 // Job that redirects back to the main appcache internals page. 388 // Job that redirects back to the main appcache internals page.
384 class RedirectToMainPageJob : public BaseInternalsJob { 389 class RedirectToMainPageJob : public BaseInternalsJob {
385 public: 390 public:
386 RedirectToMainPageJob(net::URLRequest* request, AppCacheService* service) 391 RedirectToMainPageJob(net::URLRequest* request,
387 : BaseInternalsJob(request, service) {} 392 net::NetworkDelegate* network_delegate,
393 AppCacheService* service)
394 : BaseInternalsJob(request, network_delegate, service) {}
388 395
389 virtual int GetData(std::string* mime_type, 396 virtual int GetData(std::string* mime_type,
390 std::string* charset, 397 std::string* charset,
391 std::string* data, 398 std::string* data,
392 const net::CompletionCallback& callback) const OVERRIDE { 399 const net::CompletionCallback& callback) const OVERRIDE {
393 return net::OK; // IsRedirectResponse induces a redirect. 400 return net::OK; // IsRedirectResponse induces a redirect.
394 } 401 }
395 402
396 virtual bool IsRedirectResponse(GURL* location, int* http_status_code) { 403 virtual bool IsRedirectResponse(GURL* location, int* http_status_code) {
397 *location = ClearQuery(request_->url()); 404 *location = ClearQuery(request_->url());
398 *http_status_code = 307; 405 *http_status_code = 307;
399 return true; 406 return true;
400 } 407 }
401 408
402 protected: 409 protected:
403 virtual ~RedirectToMainPageJob() {} 410 virtual ~RedirectToMainPageJob() {}
404 }; 411 };
405 412
406 // Job that removes an appcache and then redirects back to the main page. 413 // Job that removes an appcache and then redirects back to the main page.
407 class RemoveAppCacheJob : public RedirectToMainPageJob { 414 class RemoveAppCacheJob : public RedirectToMainPageJob {
408 public: 415 public:
409 RemoveAppCacheJob( 416 RemoveAppCacheJob(
410 net::URLRequest* request, AppCacheService* service, 417 net::URLRequest* request,
418 net::NetworkDelegate* network_delegate,
419 AppCacheService* service,
411 const GURL& manifest_url) 420 const GURL& manifest_url)
412 : RedirectToMainPageJob(request, service), 421 : RedirectToMainPageJob(request, network_delegate, service),
413 manifest_url_(manifest_url), 422 manifest_url_(manifest_url),
414 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { 423 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
415 } 424 }
416 425
417 virtual void Start() { 426 virtual void Start() {
418 DCHECK(request_); 427 DCHECK(request_);
419 428
420 appcache_service_->DeleteAppCacheGroup( 429 appcache_service_->DeleteAppCacheGroup(
421 manifest_url_,base::Bind(&RemoveAppCacheJob::OnDeleteAppCacheComplete, 430 manifest_url_,base::Bind(&RemoveAppCacheJob::OnDeleteAppCacheComplete,
422 weak_factory_.GetWeakPtr())); 431 weak_factory_.GetWeakPtr()));
423 } 432 }
424 433
425 private: 434 private:
426 virtual ~RemoveAppCacheJob() {} 435 virtual ~RemoveAppCacheJob() {}
427 436
428 void OnDeleteAppCacheComplete(int rv) { 437 void OnDeleteAppCacheComplete(int rv) {
429 StartAsync(); // Causes the base class to redirect. 438 StartAsync(); // Causes the base class to redirect.
430 } 439 }
431 440
432 GURL manifest_url_; 441 GURL manifest_url_;
433 base::WeakPtrFactory<RemoveAppCacheJob> weak_factory_; 442 base::WeakPtrFactory<RemoveAppCacheJob> weak_factory_;
434 }; 443 };
435 444
436 445
437 // Job shows the details of a particular manifest url. 446 // Job shows the details of a particular manifest url.
438 class ViewAppCacheJob : public BaseInternalsJob, 447 class ViewAppCacheJob : public BaseInternalsJob,
439 public AppCacheStorage::Delegate { 448 public AppCacheStorage::Delegate {
440 public: 449 public:
441 ViewAppCacheJob( 450 ViewAppCacheJob(
442 net::URLRequest* request, AppCacheService* service, 451 net::URLRequest* request,
452 net::NetworkDelegate* network_delegate,
453 AppCacheService* service,
443 const GURL& manifest_url) 454 const GURL& manifest_url)
444 : BaseInternalsJob(request, service), 455 : BaseInternalsJob(request, network_delegate, service),
445 manifest_url_(manifest_url) {} 456 manifest_url_(manifest_url) {}
446 457
447 virtual void Start() { 458 virtual void Start() {
448 DCHECK(request_); 459 DCHECK(request_);
449 appcache_service_->storage()->LoadOrCreateGroup(manifest_url_, this); 460 appcache_service_->storage()->LoadOrCreateGroup(manifest_url_, this);
450 } 461 }
451 462
452 // Produces a page containing the entries listing. 463 // Produces a page containing the entries listing.
453 virtual int GetData(std::string* mime_type, 464 virtual int GetData(std::string* mime_type,
454 std::string* charset, 465 std::string* charset,
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 AppCacheInfo appcache_info_; 512 AppCacheInfo appcache_info_;
502 AppCacheResourceInfoVector resource_infos_; 513 AppCacheResourceInfoVector resource_infos_;
503 DISALLOW_COPY_AND_ASSIGN(ViewAppCacheJob); 514 DISALLOW_COPY_AND_ASSIGN(ViewAppCacheJob);
504 }; 515 };
505 516
506 // Job that shows the details of a particular cached resource. 517 // Job that shows the details of a particular cached resource.
507 class ViewEntryJob : public BaseInternalsJob, 518 class ViewEntryJob : public BaseInternalsJob,
508 public AppCacheStorage::Delegate { 519 public AppCacheStorage::Delegate {
509 public: 520 public:
510 ViewEntryJob( 521 ViewEntryJob(
511 net::URLRequest* request, AppCacheService* service, 522 net::URLRequest* request,
512 const GURL& manifest_url, const GURL& entry_url, 523 net::NetworkDelegate* network_delegate,
524 AppCacheService* service,
525 const GURL& manifest_url,
526 const GURL& entry_url,
513 int64 response_id, int64 group_id) 527 int64 response_id, int64 group_id)
514 : BaseInternalsJob(request, service), 528 : BaseInternalsJob(request, network_delegate, service),
515 manifest_url_(manifest_url), entry_url_(entry_url), 529 manifest_url_(manifest_url), entry_url_(entry_url),
516 response_id_(response_id), group_id_(group_id), amount_read_(0) { 530 response_id_(response_id), group_id_(group_id), amount_read_(0) {
517 } 531 }
518 532
519 virtual void Start() { 533 virtual void Start() {
520 DCHECK(request_); 534 DCHECK(request_);
521 appcache_service_->storage()->LoadResponseInfo( 535 appcache_service_->storage()->LoadResponseInfo(
522 manifest_url_, group_id_, response_id_, this); 536 manifest_url_, group_id_, response_id_, this);
523 } 537 }
524 538
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 int64 group_id_; 606 int64 group_id_;
593 scoped_refptr<AppCacheResponseInfo> response_info_; 607 scoped_refptr<AppCacheResponseInfo> response_info_;
594 scoped_refptr<net::IOBuffer> response_data_; 608 scoped_refptr<net::IOBuffer> response_data_;
595 int amount_read_; 609 int amount_read_;
596 scoped_ptr<AppCacheResponseReader> reader_; 610 scoped_ptr<AppCacheResponseReader> reader_;
597 }; 611 };
598 612
599 } // namespace 613 } // namespace
600 614
601 net::URLRequestJob* ViewAppCacheInternalsJobFactory::CreateJobForRequest( 615 net::URLRequestJob* ViewAppCacheInternalsJobFactory::CreateJobForRequest(
602 net::URLRequest* request, AppCacheService* service) { 616 net::URLRequest* request,
617 net::NetworkDelegate* network_delegate,
618 AppCacheService* service) {
603 if (!request->url().has_query()) 619 if (!request->url().has_query())
604 return new MainPageJob(request, service); 620 return new MainPageJob(request, network_delegate, service);
605 621
606 std::string command; 622 std::string command;
607 std::string param; 623 std::string param;
608 ParseQuery(request->url().query(), &command, &param); 624 ParseQuery(request->url().query(), &command, &param);
609 625
610 if (command == kRemoveCacheCommand) 626 if (command == kRemoveCacheCommand)
611 return new RemoveAppCacheJob(request, service, 627 return new RemoveAppCacheJob(request, network_delegate, service,
612 DecodeBase64URL(param)); 628 DecodeBase64URL(param));
613 629
614 if (command == kViewCacheCommand) 630 if (command == kViewCacheCommand)
615 return new ViewAppCacheJob(request, service, 631 return new ViewAppCacheJob(request, network_delegate, service,
616 DecodeBase64URL(param)); 632 DecodeBase64URL(param));
617 633
618 std::vector<std::string> tokens; 634 std::vector<std::string> tokens;
619 int64 response_id; 635 int64 response_id;
620 int64 group_id; 636 int64 group_id;
621 if (command == kViewEntryCommand && Tokenize(param, "|", &tokens) == 4u && 637 if (command == kViewEntryCommand && Tokenize(param, "|", &tokens) == 4u &&
622 base::StringToInt64(tokens[2], &response_id) && 638 base::StringToInt64(tokens[2], &response_id) &&
623 base::StringToInt64(tokens[3], &group_id)) { 639 base::StringToInt64(tokens[3], &group_id)) {
624 return new ViewEntryJob(request, service, 640 return new ViewEntryJob(request, network_delegate, service,
625 DecodeBase64URL(tokens[0]), // manifest url 641 DecodeBase64URL(tokens[0]), // manifest url
626 DecodeBase64URL(tokens[1]), // entry url 642 DecodeBase64URL(tokens[1]), // entry url
627 response_id, group_id); 643 response_id, group_id);
628 } 644 }
629 645
630 return new RedirectToMainPageJob(request, service); 646 return new RedirectToMainPageJob(request, network_delegate, service);
631 } 647 }
632 648
633 } // namespace appcache 649 } // namespace appcache
OLDNEW
« no previous file with comments | « webkit/appcache/view_appcache_internals_job.h ('k') | webkit/blob/blob_url_request_job.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698