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

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: NetworkDelegate fixed almost everywhere 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 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 return true; 568 return true;
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 explicit DevToolsJobFactory(ChromeURLDataManagerBackend* backend); 574 explicit DevToolsJobFactory(ChromeURLDataManagerBackend* backend);
572 virtual ~DevToolsJobFactory(); 575 virtual ~DevToolsJobFactory();
573 576
574 virtual net::URLRequestJob* MaybeCreateJob( 577 virtual net::URLRequestJob* MaybeCreateJob(
575 net::URLRequest* request) const OVERRIDE; 578 net::URLRequest* request,
579 net::NetworkDelegate* network_delegate) const OVERRIDE;
576 580
577 private: 581 private:
578 // |backend_| is owned by ProfileIOData, which owns this ProtocolHandler. 582 // |backend_| is owned by ProfileIOData, which owns this ProtocolHandler.
579 ChromeURLDataManagerBackend* const backend_; 583 ChromeURLDataManagerBackend* const backend_;
580 584
581 DISALLOW_COPY_AND_ASSIGN(DevToolsJobFactory); 585 DISALLOW_COPY_AND_ASSIGN(DevToolsJobFactory);
582 }; 586 };
583 587
584 DevToolsJobFactory::DevToolsJobFactory(ChromeURLDataManagerBackend* backend) 588 DevToolsJobFactory::DevToolsJobFactory(ChromeURLDataManagerBackend* backend)
585 : backend_(backend) { 589 : backend_(backend) {
586 DCHECK(backend_); 590 DCHECK(backend_);
587 } 591 }
588 592
589 DevToolsJobFactory::~DevToolsJobFactory() {} 593 DevToolsJobFactory::~DevToolsJobFactory() {}
590 594
591 net::URLRequestJob* 595 net::URLRequestJob*
592 DevToolsJobFactory::MaybeCreateJob(net::URLRequest* request) const { 596 DevToolsJobFactory::MaybeCreateJob(
597 net::URLRequest* request, net::NetworkDelegate* network_delegate) const {
593 if (ShouldLoadFromDisk()) { 598 if (ShouldLoadFromDisk()) {
594 FilePath path; 599 FilePath path;
595 if (IsSupportedURL(request->url(), &path)) 600 if (IsSupportedURL(request->url(), &path))
596 return new net::URLRequestFileJob(request, path); 601 return new net::URLRequestFileJob(request, network_delegate, path);
597 } 602 }
598 603
599 return new URLRequestChromeJob(request, backend_); 604 return new URLRequestChromeJob(request, network_delegate, backend_);
600 } 605 }
601 606
602 } // namespace 607 } // namespace
603 608
604 net::URLRequestJobFactory::ProtocolHandler* 609 net::URLRequestJobFactory::ProtocolHandler*
605 CreateDevToolsProtocolHandler(ChromeURLDataManagerBackend* backend) { 610 CreateDevToolsProtocolHandler(ChromeURLDataManagerBackend* backend) {
606 return new DevToolsJobFactory(backend); 611 return new DevToolsJobFactory(backend);
607 } 612 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698