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

Side by Side Diff: content/browser/webui/url_data_manager_backend.cc

Issue 11308362: Add StoragePartition's ProtocolHandlers at URLRequestContext construction time. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address awong's comments Created 7 years, 10 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 "content/browser/webui/url_data_manager_backend.h" 5 #include "content/browser/webui/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"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/debug/trace_event.h" 13 #include "base/debug/trace_event.h"
14 #include "base/file_util.h" 14 #include "base/file_util.h"
15 #include "base/lazy_instance.h" 15 #include "base/lazy_instance.h"
16 #include "base/memory/ref_counted.h" 16 #include "base/memory/ref_counted.h"
17 #include "base/memory/ref_counted_memory.h" 17 #include "base/memory/ref_counted_memory.h"
18 #include "base/memory/weak_ptr.h" 18 #include "base/memory/weak_ptr.h"
19 #include "base/message_loop.h" 19 #include "base/message_loop.h"
20 #include "base/string_util.h" 20 #include "base/string_util.h"
21 #include "content/browser/resource_context_impl.h"
21 #include "content/browser/webui/shared_resources_data_source.h" 22 #include "content/browser/webui/shared_resources_data_source.h"
22 #include "content/browser/webui/url_data_source_impl.h" 23 #include "content/browser/webui/url_data_source_impl.h"
23 #include "content/public/browser/browser_thread.h" 24 #include "content/public/browser/browser_thread.h"
24 #include "content/public/common/url_constants.h" 25 #include "content/public/common/url_constants.h"
25 #include "googleurl/src/url_util.h" 26 #include "googleurl/src/url_util.h"
26 #include "net/base/io_buffer.h" 27 #include "net/base/io_buffer.h"
27 #include "net/base/net_errors.h" 28 #include "net/base/net_errors.h"
28 #include "net/http/http_response_headers.h" 29 #include "net/http/http_response_headers.h"
29 #include "net/url_request/url_request.h" 30 #include "net/url_request/url_request.h"
30 #include "net/url_request/url_request_context.h" 31 #include "net/url_request/url_request_context.h"
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 } 327 }
327 328
328 } // namespace 329 } // namespace
329 330
330 namespace { 331 namespace {
331 332
332 class ChromeProtocolHandler 333 class ChromeProtocolHandler
333 : public net::URLRequestJobFactory::ProtocolHandler { 334 : public net::URLRequestJobFactory::ProtocolHandler {
334 public: 335 public:
335 // |is_incognito| should be set for incognito profiles. 336 // |is_incognito| should be set for incognito profiles.
336 explicit ChromeProtocolHandler(URLDataManagerBackend* backend, 337 explicit ChromeProtocolHandler(content::ResourceContext* resource_context,
337 bool is_incognito); 338 bool is_incognito);
338 ~ChromeProtocolHandler(); 339 ~ChromeProtocolHandler();
339 340
340 virtual net::URLRequestJob* MaybeCreateJob( 341 virtual net::URLRequestJob* MaybeCreateJob(
341 net::URLRequest* request, 342 net::URLRequest* request,
342 net::NetworkDelegate* network_delegate) const OVERRIDE; 343 net::NetworkDelegate* network_delegate) const OVERRIDE;
343 344
344 private: 345 private:
345 // These members are owned by ProfileIOData, which owns this ProtocolHandler. 346 // These members are owned by ProfileIOData, which owns this ProtocolHandler.
346 URLDataManagerBackend* const backend_; 347 content::ResourceContext* const resource_context_;
347 348
348 // True when generated from an incognito profile. 349 // True when generated from an incognito profile.
349 const bool is_incognito_; 350 const bool is_incognito_;
350 351
351 DISALLOW_COPY_AND_ASSIGN(ChromeProtocolHandler); 352 DISALLOW_COPY_AND_ASSIGN(ChromeProtocolHandler);
352 }; 353 };
353 354
354 ChromeProtocolHandler::ChromeProtocolHandler( 355 ChromeProtocolHandler::ChromeProtocolHandler(
355 URLDataManagerBackend* backend, bool is_incognito) 356 content::ResourceContext* resource_context, bool is_incognito)
356 : backend_(backend), is_incognito_(is_incognito) {} 357 : resource_context_(resource_context), is_incognito_(is_incognito) {}
357 358
358 ChromeProtocolHandler::~ChromeProtocolHandler() {} 359 ChromeProtocolHandler::~ChromeProtocolHandler() {}
359 360
360 net::URLRequestJob* ChromeProtocolHandler::MaybeCreateJob( 361 net::URLRequestJob* ChromeProtocolHandler::MaybeCreateJob(
361 net::URLRequest* request, net::NetworkDelegate* network_delegate) const { 362 net::URLRequest* request, net::NetworkDelegate* network_delegate) const {
362 DCHECK(request); 363 DCHECK(request);
363 364
364 // Fall back to using a custom handler 365 // Fall back to using a custom handler
365 return new URLRequestChromeJob(request, network_delegate, backend_, 366 return new URLRequestChromeJob(
366 is_incognito_); 367 request, network_delegate,
368 GetURLDataManagerForResourceContext(resource_context_), is_incognito_);
367 } 369 }
368 370
369 } // namespace 371 } // namespace
370 372
371 URLDataManagerBackend::URLDataManagerBackend() 373 URLDataManagerBackend::URLDataManagerBackend()
372 : next_request_id_(0) { 374 : next_request_id_(0) {
373 URLDataSource* shared_source = new SharedResourcesDataSource(); 375 URLDataSource* shared_source = new SharedResourcesDataSource();
374 URLDataSourceImpl* source_impl = 376 URLDataSourceImpl* source_impl =
375 new URLDataSourceImpl(shared_source->GetSource(), shared_source); 377 new URLDataSourceImpl(shared_source->GetSource(), shared_source);
376 AddDataSource(source_impl); 378 AddDataSource(source_impl);
377 } 379 }
378 380
379 URLDataManagerBackend::~URLDataManagerBackend() { 381 URLDataManagerBackend::~URLDataManagerBackend() {
380 for (DataSourceMap::iterator i = data_sources_.begin(); 382 for (DataSourceMap::iterator i = data_sources_.begin();
381 i != data_sources_.end(); ++i) { 383 i != data_sources_.end(); ++i) {
382 i->second->backend_ = NULL; 384 i->second->backend_ = NULL;
383 } 385 }
384 data_sources_.clear(); 386 data_sources_.clear();
385 } 387 }
386 388
387 // static 389 // static
388 net::URLRequestJobFactory::ProtocolHandler* 390 net::URLRequestJobFactory::ProtocolHandler*
389 URLDataManagerBackend::CreateProtocolHandler( 391 URLDataManagerBackend::CreateProtocolHandler(
390 URLDataManagerBackend* backend, bool is_incognito) { 392 content::ResourceContext* resource_context, bool is_incognito) {
391 DCHECK(backend); 393 DCHECK(resource_context);
392 return new ChromeProtocolHandler(backend, is_incognito); 394 return new ChromeProtocolHandler(resource_context, is_incognito);
393 } 395 }
394 396
395 void URLDataManagerBackend::AddDataSource( 397 void URLDataManagerBackend::AddDataSource(
396 URLDataSourceImpl* source) { 398 URLDataSourceImpl* source) {
397 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 399 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
398 DataSourceMap::iterator i = data_sources_.find(source->source_name()); 400 DataSourceMap::iterator i = data_sources_.find(source->source_name());
399 if (i != data_sources_.end()) { 401 if (i != data_sources_.end()) {
400 if (!source->source()->ShouldReplaceExistingSource()) 402 if (!source->source()->ShouldReplaceExistingSource())
401 return; 403 return;
402 i->second->backend_ = NULL; 404 i->second->backend_ = NULL;
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 job->DataAvailable(bytes); 516 job->DataAvailable(bytes);
515 } 517 }
516 } 518 }
517 519
518 namespace { 520 namespace {
519 521
520 class DevToolsJobFactory 522 class DevToolsJobFactory
521 : public net::URLRequestJobFactory::ProtocolHandler { 523 : public net::URLRequestJobFactory::ProtocolHandler {
522 public: 524 public:
523 // |is_incognito| should be set for incognito profiles. 525 // |is_incognito| should be set for incognito profiles.
524 DevToolsJobFactory(URLDataManagerBackend* backend, 526 DevToolsJobFactory(content::ResourceContext* resource_context,
525 bool is_incognito); 527 bool is_incognito);
526 virtual ~DevToolsJobFactory(); 528 virtual ~DevToolsJobFactory();
527 529
528 virtual net::URLRequestJob* MaybeCreateJob( 530 virtual net::URLRequestJob* MaybeCreateJob(
529 net::URLRequest* request, 531 net::URLRequest* request,
530 net::NetworkDelegate* network_delegate) const OVERRIDE; 532 net::NetworkDelegate* network_delegate) const OVERRIDE;
531 533
532 private: 534 private:
533 // |backend_| and |network_delegate_| are owned by ProfileIOData, which owns 535 // |resource_context_| and |network_delegate_| are owned by ProfileIOData,
534 // this ProtocolHandler. 536 // which owns this ProtocolHandler.
535 URLDataManagerBackend* const backend_; 537 content::ResourceContext* const resource_context_;
536 538
537 // True when generated from an incognito profile. 539 // True when generated from an incognito profile.
538 const bool is_incognito_; 540 const bool is_incognito_;
539 541
540 DISALLOW_COPY_AND_ASSIGN(DevToolsJobFactory); 542 DISALLOW_COPY_AND_ASSIGN(DevToolsJobFactory);
541 }; 543 };
542 544
543 DevToolsJobFactory::DevToolsJobFactory(URLDataManagerBackend* backend, 545 DevToolsJobFactory::DevToolsJobFactory(
544 bool is_incognito) 546 content::ResourceContext* resource_context,
545 : backend_(backend), 547 bool is_incognito)
548 : resource_context_(resource_context),
546 is_incognito_(is_incognito) { 549 is_incognito_(is_incognito) {
547 DCHECK(backend_); 550 DCHECK(resource_context_);
548 } 551 }
549 552
550 DevToolsJobFactory::~DevToolsJobFactory() {} 553 DevToolsJobFactory::~DevToolsJobFactory() {}
551 554
552 net::URLRequestJob* 555 net::URLRequestJob*
553 DevToolsJobFactory::MaybeCreateJob( 556 DevToolsJobFactory::MaybeCreateJob(
554 net::URLRequest* request, net::NetworkDelegate* network_delegate) const { 557 net::URLRequest* request, net::NetworkDelegate* network_delegate) const {
555 return new URLRequestChromeJob(request, network_delegate, backend_, 558 return new URLRequestChromeJob(
556 is_incognito_); 559 request, network_delegate,
560 GetURLDataManagerForResourceContext(resource_context_), is_incognito_);
557 } 561 }
558 562
559 } // namespace 563 } // namespace
560 564
561 net::URLRequestJobFactory::ProtocolHandler* 565 net::URLRequestJobFactory::ProtocolHandler*
562 CreateDevToolsProtocolHandler(URLDataManagerBackend* backend, 566 CreateDevToolsProtocolHandler(content::ResourceContext* resource_context,
563 bool is_incognito) { 567 bool is_incognito) {
564 return new DevToolsJobFactory(backend, is_incognito); 568 return new DevToolsJobFactory(resource_context, is_incognito);
565 } 569 }
566 570
567 } // namespace content 571 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698