OLD | NEW |
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/custom_handlers/protocol_handler_registry.h" | 5 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 | 156 |
157 // JobInterceptorFactory ------------------------------------------------------- | 157 // JobInterceptorFactory ------------------------------------------------------- |
158 | 158 |
159 // Instances of JobInterceptorFactory are produced for ownership by the IO | 159 // Instances of JobInterceptorFactory are produced for ownership by the IO |
160 // thread where it handler URL requests. We should never hold | 160 // thread where it handler URL requests. We should never hold |
161 // any pointers on this class, only produce them in response to | 161 // any pointers on this class, only produce them in response to |
162 // requests via |ProtocolHandlerRegistry::CreateJobInterceptorFactory|. | 162 // requests via |ProtocolHandlerRegistry::CreateJobInterceptorFactory|. |
163 ProtocolHandlerRegistry::JobInterceptorFactory::JobInterceptorFactory( | 163 ProtocolHandlerRegistry::JobInterceptorFactory::JobInterceptorFactory( |
164 IOThreadDelegate* io_thread_delegate) | 164 IOThreadDelegate* io_thread_delegate) |
165 : io_thread_delegate_(io_thread_delegate) { | 165 : io_thread_delegate_(io_thread_delegate) { |
166 DCHECK(io_thread_delegate_); | 166 DCHECK(io_thread_delegate_.get()); |
167 DetachFromThread(); | 167 DetachFromThread(); |
168 } | 168 } |
169 | 169 |
170 ProtocolHandlerRegistry::JobInterceptorFactory::~JobInterceptorFactory() { | 170 ProtocolHandlerRegistry::JobInterceptorFactory::~JobInterceptorFactory() { |
171 } | 171 } |
172 | 172 |
173 void ProtocolHandlerRegistry::JobInterceptorFactory::Chain( | 173 void ProtocolHandlerRegistry::JobInterceptorFactory::Chain( |
174 scoped_ptr<net::URLRequestJobFactory> job_factory) { | 174 scoped_ptr<net::URLRequestJobFactory> job_factory) { |
175 job_factory_ = job_factory.Pass(); | 175 job_factory_ = job_factory.Pass(); |
176 } | 176 } |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 } | 294 } |
295 | 295 |
296 void ProtocolHandlerRegistry::Delegate::RegisterWithOSAsDefaultClient( | 296 void ProtocolHandlerRegistry::Delegate::RegisterWithOSAsDefaultClient( |
297 const std::string& protocol, ProtocolHandlerRegistry* registry) { | 297 const std::string& protocol, ProtocolHandlerRegistry* registry) { |
298 DefaultClientObserver* observer = CreateShellObserver(registry); | 298 DefaultClientObserver* observer = CreateShellObserver(registry); |
299 // The worker pointer is reference counted. While it is running the | 299 // The worker pointer is reference counted. While it is running the |
300 // message loops of the FILE and UI thread will hold references to it | 300 // message loops of the FILE and UI thread will hold references to it |
301 // and it will be automatically freed once all its tasks have finished. | 301 // and it will be automatically freed once all its tasks have finished. |
302 scoped_refptr<ShellIntegration::DefaultProtocolClientWorker> worker; | 302 scoped_refptr<ShellIntegration::DefaultProtocolClientWorker> worker; |
303 worker = CreateShellWorker(observer, protocol); | 303 worker = CreateShellWorker(observer, protocol); |
304 observer->SetWorker(worker); | 304 observer->SetWorker(worker.get()); |
305 registry->default_client_observers_.push_back(observer); | 305 registry->default_client_observers_.push_back(observer); |
306 worker->StartSetAsDefault(); | 306 worker->StartSetAsDefault(); |
307 } | 307 } |
308 | 308 |
309 // ProtocolHandlerRegistry ----------------------------------------------------- | 309 // ProtocolHandlerRegistry ----------------------------------------------------- |
310 | 310 |
311 ProtocolHandlerRegistry::ProtocolHandlerRegistry(Profile* profile, | 311 ProtocolHandlerRegistry::ProtocolHandlerRegistry(Profile* profile, |
312 Delegate* delegate) | 312 Delegate* delegate) |
313 : profile_(profile), | 313 : profile_(profile), |
314 delegate_(delegate), | 314 delegate_(delegate), |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 | 467 |
468 // For each default protocol handler, check that we are still registered | 468 // For each default protocol handler, check that we are still registered |
469 // with the OS as the default application. | 469 // with the OS as the default application. |
470 if (ShouldRemoveHandlersNotInOS()) { | 470 if (ShouldRemoveHandlersNotInOS()) { |
471 for (ProtocolHandlerMap::const_iterator p = default_handlers_.begin(); | 471 for (ProtocolHandlerMap::const_iterator p = default_handlers_.begin(); |
472 p != default_handlers_.end(); ++p) { | 472 p != default_handlers_.end(); ++p) { |
473 ProtocolHandler handler = p->second; | 473 ProtocolHandler handler = p->second; |
474 DefaultClientObserver* observer = delegate_->CreateShellObserver(this); | 474 DefaultClientObserver* observer = delegate_->CreateShellObserver(this); |
475 scoped_refptr<ShellIntegration::DefaultProtocolClientWorker> worker; | 475 scoped_refptr<ShellIntegration::DefaultProtocolClientWorker> worker; |
476 worker = delegate_->CreateShellWorker(observer, handler.protocol()); | 476 worker = delegate_->CreateShellWorker(observer, handler.protocol()); |
477 observer->SetWorker(worker); | 477 observer->SetWorker(worker.get()); |
478 default_client_observers_.push_back(observer); | 478 default_client_observers_.push_back(observer); |
479 worker->StartCheckIsDefault(); | 479 worker->StartCheckIsDefault(); |
480 } | 480 } |
481 } | 481 } |
482 } | 482 } |
483 | 483 |
484 int ProtocolHandlerRegistry::GetHandlerIndex(const std::string& scheme) const { | 484 int ProtocolHandlerRegistry::GetHandlerIndex(const std::string& scheme) const { |
485 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 485 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
486 const ProtocolHandler& handler = GetHandlerFor(scheme); | 486 const ProtocolHandler& handler = GetHandlerFor(scheme); |
487 if (handler.IsEmpty()) | 487 if (handler.IsEmpty()) |
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
875 RegisterProtocolHandler(handler); | 875 RegisterProtocolHandler(handler); |
876 SetDefault(handler); | 876 SetDefault(handler); |
877 } | 877 } |
878 | 878 |
879 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> | 879 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> |
880 ProtocolHandlerRegistry::CreateJobInterceptorFactory() { | 880 ProtocolHandlerRegistry::CreateJobInterceptorFactory() { |
881 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 881 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
882 // this is always created on the UI thread (in profile_io's | 882 // this is always created on the UI thread (in profile_io's |
883 // InitializeOnUIThread. Any method calls must be done | 883 // InitializeOnUIThread. Any method calls must be done |
884 // on the IO thread (this is checked). | 884 // on the IO thread (this is checked). |
885 return scoped_ptr<JobInterceptorFactory>(new JobInterceptorFactory( | 885 return scoped_ptr<JobInterceptorFactory>( |
886 io_thread_delegate_)); | 886 new JobInterceptorFactory(io_thread_delegate_.get())); |
887 } | 887 } |
OLD | NEW |