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

Side by Side Diff: chrome/browser/ui/webui/chrome_url_data_manager_backend.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
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 "chrome/browser/ui/webui/chrome_url_data_manager_backend.h" 5 #include "chrome/browser/ui/webui/chrome_url_data_manager_backend.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 } // namespace 155 } // namespace
156 156
157 // URLRequestChromeJob is a net::URLRequestJob that manages running 157 // URLRequestChromeJob is a net::URLRequestJob that manages running
158 // chrome-internal resource requests asynchronously. 158 // chrome-internal resource requests asynchronously.
159 // It hands off URL requests to ChromeURLDataManager, which asynchronously 159 // It hands off URL requests to ChromeURLDataManager, which asynchronously
160 // calls back once the data is available. 160 // calls back once the data is available.
161 class URLRequestChromeJob : public net::URLRequestJob, 161 class URLRequestChromeJob : public net::URLRequestJob,
162 public base::SupportsWeakPtr<URLRequestChromeJob> { 162 public base::SupportsWeakPtr<URLRequestChromeJob> {
163 public: 163 public:
164 URLRequestChromeJob(net::URLRequest* request, 164 URLRequestChromeJob(net::URLRequest* request,
165 net::NetworkDelegate* network_delegate,
165 ChromeURLDataManagerBackend* backend); 166 ChromeURLDataManagerBackend* backend);
166 167
167 // net::URLRequestJob implementation. 168 // net::URLRequestJob implementation.
168 virtual void Start() OVERRIDE; 169 virtual void Start() OVERRIDE;
169 virtual void Kill() OVERRIDE; 170 virtual void Kill() OVERRIDE;
170 virtual bool ReadRawData(net::IOBuffer* buf, 171 virtual bool ReadRawData(net::IOBuffer* buf,
171 int buf_size, 172 int buf_size,
172 int* bytes_read) OVERRIDE; 173 int* bytes_read) OVERRIDE;
173 virtual bool GetMimeType(std::string* mime_type) const OVERRIDE; 174 virtual bool GetMimeType(std::string* mime_type) const OVERRIDE;
174 virtual void GetResponseInfo(net::HttpResponseInfo* info) OVERRIDE; 175 virtual void GetResponseInfo(net::HttpResponseInfo* info) OVERRIDE;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 217
217 // The backend is owned by ChromeURLRequestContext and always outlives us. 218 // The backend is owned by ChromeURLRequestContext and always outlives us.
218 ChromeURLDataManagerBackend* backend_; 219 ChromeURLDataManagerBackend* backend_;
219 220
220 base::WeakPtrFactory<URLRequestChromeJob> weak_factory_; 221 base::WeakPtrFactory<URLRequestChromeJob> weak_factory_;
221 222
222 DISALLOW_COPY_AND_ASSIGN(URLRequestChromeJob); 223 DISALLOW_COPY_AND_ASSIGN(URLRequestChromeJob);
223 }; 224 };
224 225
225 URLRequestChromeJob::URLRequestChromeJob(net::URLRequest* request, 226 URLRequestChromeJob::URLRequestChromeJob(net::URLRequest* request,
227 net::NetworkDelegate* network_delegate,
226 ChromeURLDataManagerBackend* backend) 228 ChromeURLDataManagerBackend* backend)
227 : net::URLRequestJob(request, request->context()->network_delegate()), 229 : net::URLRequestJob(request, network_delegate),
228 data_offset_(0), 230 data_offset_(0),
229 pending_buf_size_(0), 231 pending_buf_size_(0),
230 allow_caching_(true), 232 allow_caching_(true),
231 backend_(backend), 233 backend_(backend),
232 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { 234 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
233 DCHECK(backend); 235 DCHECK(backend);
234 } 236 }
235 237
236 URLRequestChromeJob::~URLRequestChromeJob() { 238 URLRequestChromeJob::~URLRequestChromeJob() {
237 CHECK(!backend_->HasPendingJob(this)); 239 CHECK(!backend_->HasPendingJob(this));
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 356
355 namespace { 357 namespace {
356 358
357 class ChromeProtocolHandler 359 class ChromeProtocolHandler
358 : public net::URLRequestJobFactory::ProtocolHandler { 360 : public net::URLRequestJobFactory::ProtocolHandler {
359 public: 361 public:
360 explicit ChromeProtocolHandler(ChromeURLDataManagerBackend* backend); 362 explicit ChromeProtocolHandler(ChromeURLDataManagerBackend* backend);
361 ~ChromeProtocolHandler(); 363 ~ChromeProtocolHandler();
362 364
363 virtual net::URLRequestJob* MaybeCreateJob( 365 virtual net::URLRequestJob* MaybeCreateJob(
364 net::URLRequest* request) const OVERRIDE; 366 net::URLRequest* request,
367 net::NetworkDelegate* network_delegate) const OVERRIDE;
365 368
366 private: 369 private:
367 // These members are owned by ProfileIOData, which owns this ProtocolHandler. 370 // These members are owned by ProfileIOData, which owns this ProtocolHandler.
368 ChromeURLDataManagerBackend* const backend_; 371 ChromeURLDataManagerBackend* const backend_;
369 372
370 DISALLOW_COPY_AND_ASSIGN(ChromeProtocolHandler); 373 DISALLOW_COPY_AND_ASSIGN(ChromeProtocolHandler);
371 }; 374 };
372 375
373 ChromeProtocolHandler::ChromeProtocolHandler( 376 ChromeProtocolHandler::ChromeProtocolHandler(
374 ChromeURLDataManagerBackend* backend) 377 ChromeURLDataManagerBackend* backend)
375 : backend_(backend) {} 378 : backend_(backend) {}
376 379
377 ChromeProtocolHandler::~ChromeProtocolHandler() {} 380 ChromeProtocolHandler::~ChromeProtocolHandler() {}
378 381
379 net::URLRequestJob* ChromeProtocolHandler::MaybeCreateJob( 382 net::URLRequestJob* ChromeProtocolHandler::MaybeCreateJob(
380 net::URLRequest* request) const { 383 net::URLRequest* request, net::NetworkDelegate* network_delegate) const {
381 DCHECK(request); 384 DCHECK(request);
382 385
383 // Fall back to using a custom handler 386 // Fall back to using a custom handler
384 return new URLRequestChromeJob(request, backend_); 387 return new URLRequestChromeJob(request, network_delegate, backend_);
385 } 388 }
386 389
387 } // namespace 390 } // namespace
388 391
389 ChromeURLDataManagerBackend::ChromeURLDataManagerBackend() 392 ChromeURLDataManagerBackend::ChromeURLDataManagerBackend()
390 : next_request_id_(0) { 393 : next_request_id_(0) {
391 AddDataSource(new SharedResourcesDataSource()); 394 AddDataSource(new SharedResourcesDataSource());
392 } 395 }
393 396
394 ChromeURLDataManagerBackend::~ChromeURLDataManagerBackend() { 397 ChromeURLDataManagerBackend::~ChromeURLDataManagerBackend() {
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 } 569 }
567 570
568 class DevToolsJobFactory 571 class DevToolsJobFactory
569 : public net::URLRequestJobFactory::ProtocolHandler { 572 : public net::URLRequestJobFactory::ProtocolHandler {
570 public: 573 public:
571 DevToolsJobFactory(ChromeURLDataManagerBackend* backend, 574 DevToolsJobFactory(ChromeURLDataManagerBackend* backend,
572 net::NetworkDelegate* network_delegate); 575 net::NetworkDelegate* network_delegate);
573 virtual ~DevToolsJobFactory(); 576 virtual ~DevToolsJobFactory();
574 577
575 virtual net::URLRequestJob* MaybeCreateJob( 578 virtual net::URLRequestJob* MaybeCreateJob(
576 net::URLRequest* request) const OVERRIDE; 579 net::URLRequest* request,
580 net::NetworkDelegate* network_delegate) const OVERRIDE;
577 581
578 private: 582 private:
579 // |backend_| and |network_delegate_| are owned by ProfileIOData, which owns 583 // |backend_| and |network_delegate_| are owned by ProfileIOData, which owns
580 // this ProtocolHandler. 584 // this ProtocolHandler.
581 ChromeURLDataManagerBackend* const backend_; 585 ChromeURLDataManagerBackend* const backend_;
582 net::NetworkDelegate* network_delegate_; 586 net::NetworkDelegate* network_delegate_;
583 587
584 DISALLOW_COPY_AND_ASSIGN(DevToolsJobFactory); 588 DISALLOW_COPY_AND_ASSIGN(DevToolsJobFactory);
585 }; 589 };
586 590
587 DevToolsJobFactory::DevToolsJobFactory(ChromeURLDataManagerBackend* backend, 591 DevToolsJobFactory::DevToolsJobFactory(ChromeURLDataManagerBackend* backend,
588 net::NetworkDelegate* network_delegate) 592 net::NetworkDelegate* network_delegate)
589 : backend_(backend), 593 : backend_(backend),
590 network_delegate_(network_delegate) { 594 network_delegate_(network_delegate) {
591 DCHECK(backend_); 595 DCHECK(backend_);
592 } 596 }
593 597
594 DevToolsJobFactory::~DevToolsJobFactory() {} 598 DevToolsJobFactory::~DevToolsJobFactory() {}
595 599
596 net::URLRequestJob* 600 net::URLRequestJob*
597 DevToolsJobFactory::MaybeCreateJob(net::URLRequest* request) const { 601 DevToolsJobFactory::MaybeCreateJob(
602 net::URLRequest* request, net::NetworkDelegate* network_delegate) const {
598 if (ShouldLoadFromDisk()) { 603 if (ShouldLoadFromDisk()) {
599 FilePath path; 604 FilePath path;
600 if (IsSupportedURL(request->url(), &path)) 605 if (IsSupportedURL(request->url(), &path))
601 return new net::URLRequestFileJob(request, path, network_delegate_); 606 return new net::URLRequestFileJob(request, network_delegate, path);
602 } 607 }
603 608
604 return new URLRequestChromeJob(request, backend_); 609 return new URLRequestChromeJob(request, network_delegate, backend_);
605 } 610 }
606 611
607 } // namespace 612 } // namespace
608 613
609 net::URLRequestJobFactory::ProtocolHandler* 614 net::URLRequestJobFactory::ProtocolHandler*
610 CreateDevToolsProtocolHandler(ChromeURLDataManagerBackend* backend, 615 CreateDevToolsProtocolHandler(ChromeURLDataManagerBackend* backend,
611 net::NetworkDelegate* network_delegate) { 616 net::NetworkDelegate* network_delegate) {
612 return new DevToolsJobFactory(backend, network_delegate); 617 return new DevToolsJobFactory(backend, network_delegate);
613 } 618 }
OLDNEW
« no previous file with comments | « chrome/browser/profiles/profile_impl_io_data.cc ('k') | chrome_frame/test/net/test_automation_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698