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

Side by Side Diff: chrome/browser/custom_handlers/protocol_handler_registry.cc

Issue 2896473002: Remove FILE thread dependency in protocol_handler_registry_unittest.cc (Closed)
Patch Set: MakeShared to MakeRefCounted Created 3 years, 7 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
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/custom_handlers/protocol_handler_registry.h" 5 #include "chrome/browser/custom_handlers/protocol_handler_registry.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/memory/ptr_util.h" 16 #include "base/memory/ptr_util.h"
17 #include "base/memory/ref_counted.h"
17 #include "build/build_config.h" 18 #include "build/build_config.h"
18 #include "chrome/browser/chrome_notification_types.h" 19 #include "chrome/browser/chrome_notification_types.h"
19 #include "chrome/browser/profiles/profile_io_data.h" 20 #include "chrome/browser/profiles/profile_io_data.h"
20 #include "chrome/common/custom_handlers/protocol_handler.h" 21 #include "chrome/common/custom_handlers/protocol_handler.h"
21 #include "chrome/common/pref_names.h" 22 #include "chrome/common/pref_names.h"
22 #include "chrome/grit/generated_resources.h" 23 #include "chrome/grit/generated_resources.h"
23 #include "components/pref_registry/pref_registry_syncable.h" 24 #include "components/pref_registry/pref_registry_syncable.h"
24 #include "components/prefs/pref_service.h" 25 #include "components/prefs/pref_service.h"
25 #include "components/user_prefs/user_prefs.h" 26 #include "components/user_prefs/user_prefs.h"
26 #include "content/public/browser/child_process_security_policy.h" 27 #include "content/public/browser/child_process_security_policy.h"
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 const std::string& protocol) { 241 const std::string& protocol) {
241 } 242 }
242 243
243 bool ProtocolHandlerRegistry::Delegate::IsExternalHandlerRegistered( 244 bool ProtocolHandlerRegistry::Delegate::IsExternalHandlerRegistered(
244 const std::string& protocol) { 245 const std::string& protocol) {
245 // NOTE(koz): This function is safe to call from any thread, despite living 246 // NOTE(koz): This function is safe to call from any thread, despite living
246 // in ProfileIOData. 247 // in ProfileIOData.
247 return ProfileIOData::IsHandledProtocol(protocol); 248 return ProfileIOData::IsHandledProtocol(protocol);
248 } 249 }
249 250
250 scoped_refptr<shell_integration::DefaultProtocolClientWorker>
251 ProtocolHandlerRegistry::Delegate::CreateShellWorker(
252 const shell_integration::DefaultWebClientWorkerCallback& callback,
253 const std::string& protocol) {
254 return new shell_integration::DefaultProtocolClientWorker(callback, protocol);
255 }
256
257 void ProtocolHandlerRegistry::Delegate::RegisterWithOSAsDefaultClient( 251 void ProtocolHandlerRegistry::Delegate::RegisterWithOSAsDefaultClient(
258 const std::string& protocol, ProtocolHandlerRegistry* registry) { 252 const std::string& protocol, ProtocolHandlerRegistry* registry) {
259 // The worker pointer is reference counted. While it is running, the 253 // The worker pointer is reference counted. While it is running, the
260 // message loops of the FILE and UI thread will hold references to it 254 // sequence it runs on will hold references it will be automatically freed
261 // and it will be automatically freed once all its tasks have finished. 255 // once all its tasks have finished.
262 CreateShellWorker(registry->GetDefaultWebClientCallback(protocol), protocol) 256 base::MakeRefCounted<shell_integration::DefaultProtocolClientWorker>(
257 registry->GetDefaultWebClientCallback(protocol), protocol)
263 ->StartSetAsDefault(); 258 ->StartSetAsDefault();
264 } 259 }
265 260
266 // ProtocolHandlerRegistry ----------------------------------------------------- 261 // ProtocolHandlerRegistry -----------------------------------------------------
267 262
268 ProtocolHandlerRegistry::ProtocolHandlerRegistry( 263 ProtocolHandlerRegistry::ProtocolHandlerRegistry(
269 content::BrowserContext* context, 264 content::BrowserContext* context,
270 Delegate* delegate) 265 Delegate* delegate)
271 : context_(context), 266 : context_(context),
272 delegate_(delegate), 267 delegate_(delegate),
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 IgnoreProtocolHandlersFromPref(prefs::kIgnoredProtocolHandlers, USER); 402 IgnoreProtocolHandlersFromPref(prefs::kIgnoredProtocolHandlers, USER);
408 403
409 is_loading_ = false; 404 is_loading_ = false;
410 405
411 // For each default protocol handler, check that we are still registered 406 // For each default protocol handler, check that we are still registered
412 // with the OS as the default application. 407 // with the OS as the default application.
413 if (ShouldRemoveHandlersNotInOS()) { 408 if (ShouldRemoveHandlersNotInOS()) {
414 for (ProtocolHandlerMap::const_iterator p = default_handlers_.begin(); 409 for (ProtocolHandlerMap::const_iterator p = default_handlers_.begin();
415 p != default_handlers_.end(); ++p) { 410 p != default_handlers_.end(); ++p) {
416 ProtocolHandler handler = p->second; 411 ProtocolHandler handler = p->second;
417 // The worker pointer is reference counted. While it is running the 412 delegate_->RegisterWithOSAsDefaultClient(handler.protocol(), this);
418 // message loops of the FILE and UI thread will hold references to it
419 // and it will be automatically freed once all its tasks have finished.
420 delegate_
421 ->CreateShellWorker(GetDefaultWebClientCallback(handler.protocol()),
422 handler.protocol())
423 ->StartSetAsDefault();
424 } 413 }
425 } 414 }
426 } 415 }
427 416
428 int ProtocolHandlerRegistry::GetHandlerIndex(const std::string& scheme) const { 417 int ProtocolHandlerRegistry::GetHandlerIndex(const std::string& scheme) const {
429 DCHECK_CURRENTLY_ON(BrowserThread::UI); 418 DCHECK_CURRENTLY_ON(BrowserThread::UI);
430 const ProtocolHandler& handler = GetHandlerFor(scheme); 419 const ProtocolHandler& handler = GetHandlerFor(scheme);
431 if (handler.IsEmpty()) 420 if (handler.IsEmpty())
432 return -1; 421 return -1;
433 const ProtocolHandlerList* handlers = GetHandlerList(scheme); 422 const ProtocolHandlerList* handlers = GetHandlerList(scheme);
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after
913 902
914 std::unique_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> 903 std::unique_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>
915 ProtocolHandlerRegistry::CreateJobInterceptorFactory() { 904 ProtocolHandlerRegistry::CreateJobInterceptorFactory() {
916 DCHECK_CURRENTLY_ON(BrowserThread::UI); 905 DCHECK_CURRENTLY_ON(BrowserThread::UI);
917 // this is always created on the UI thread (in profile_io's 906 // this is always created on the UI thread (in profile_io's
918 // InitializeOnUIThread. Any method calls must be done 907 // InitializeOnUIThread. Any method calls must be done
919 // on the IO thread (this is checked). 908 // on the IO thread (this is checked).
920 return std::unique_ptr<JobInterceptorFactory>( 909 return std::unique_ptr<JobInterceptorFactory>(
921 new JobInterceptorFactory(io_thread_delegate_.get())); 910 new JobInterceptorFactory(io_thread_delegate_.get()));
922 } 911 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698