Add FindInPageBridge
[chromium-blink-merge.git] / net / socket_stream / socket_stream_job_manager.cc
blob6418be4eb71ad5502f12f9c2dfcb11ad07b8ea4e
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "net/socket_stream/socket_stream_job_manager.h"
7 #include "base/memory/singleton.h"
9 namespace net {
11 SocketStreamJobManager::SocketStreamJobManager() {
14 SocketStreamJobManager::~SocketStreamJobManager() {
17 // static
18 SocketStreamJobManager* SocketStreamJobManager::GetInstance() {
19 return Singleton<SocketStreamJobManager>::get();
22 SocketStreamJob* SocketStreamJobManager::CreateJob(
23 const GURL& url, SocketStream::Delegate* delegate,
24 URLRequestContext* context, CookieStore* cookie_store) const {
25 // If url is invalid, create plain SocketStreamJob, which will close
26 // the socket immediately.
27 if (!url.is_valid()) {
28 SocketStreamJob* job = new SocketStreamJob();
29 job->InitSocketStream(new SocketStream(url, delegate, context,
30 cookie_store));
31 return job;
34 const std::string& scheme = url.scheme(); // already lowercase
36 base::AutoLock locked(lock_);
37 FactoryMap::const_iterator found = factories_.find(scheme);
38 if (found != factories_.end()) {
39 SocketStreamJob* job = found->second(url, delegate, context, cookie_store);
40 if (job)
41 return job;
43 SocketStreamJob* job = new SocketStreamJob();
44 job->InitSocketStream(new SocketStream(url, delegate, context, cookie_store));
45 return job;
48 SocketStreamJob::ProtocolFactory*
49 SocketStreamJobManager::RegisterProtocolFactory(
50 const std::string& scheme, SocketStreamJob::ProtocolFactory* factory) {
51 base::AutoLock locked(lock_);
53 SocketStreamJob::ProtocolFactory* old_factory;
54 FactoryMap::iterator found = factories_.find(scheme);
55 if (found != factories_.end()) {
56 old_factory = found->second;
57 } else {
58 old_factory = NULL;
60 if (factory) {
61 factories_[scheme] = factory;
62 } else if (found != factories_.end()) {
63 factories_.erase(found);
65 return old_factory;
68 } // namespace net