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

Side by Side Diff: services/shell/public/cpp/lib/service_context_ref.cc

Issue 2259823003: Re-write many calls to WrapUnique() with MakeUnique() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "services/shell/public/cpp/service_context_ref.h" 5 #include "services/shell/public/cpp/service_context_ref.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/threading/thread_checker.h" 10 #include "base/threading/thread_checker.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 DCHECK(thread_checker_.CalledOnValidThread()); 42 DCHECK(thread_checker_.CalledOnValidThread());
43 43
44 if (service_task_runner_->BelongsToCurrentThread() && factory_) { 44 if (service_task_runner_->BelongsToCurrentThread() && factory_) {
45 factory_->AddRef(); 45 factory_->AddRef();
46 } else { 46 } else {
47 service_task_runner_->PostTask( 47 service_task_runner_->PostTask(
48 FROM_HERE, 48 FROM_HERE,
49 base::Bind(&ServiceContextRefFactory::AddRef, factory_)); 49 base::Bind(&ServiceContextRefFactory::AddRef, factory_));
50 } 50 }
51 51
52 return base::WrapUnique( 52 return base::MakeUnique<ServiceContextRefImpl>(factory_,
53 new ServiceContextRefImpl(factory_, service_task_runner_)); 53 service_task_runner_);
54 } 54 }
55 55
56 base::WeakPtr<ServiceContextRefFactory> factory_; 56 base::WeakPtr<ServiceContextRefFactory> factory_;
57 scoped_refptr<base::SingleThreadTaskRunner> service_task_runner_; 57 scoped_refptr<base::SingleThreadTaskRunner> service_task_runner_;
58 base::ThreadChecker thread_checker_; 58 base::ThreadChecker thread_checker_;
59 59
60 DISALLOW_COPY_AND_ASSIGN(ServiceContextRefImpl); 60 DISALLOW_COPY_AND_ASSIGN(ServiceContextRefImpl);
61 }; 61 };
62 62
63 ServiceContextRefFactory::ServiceContextRefFactory( 63 ServiceContextRefFactory::ServiceContextRefFactory(
64 const base::Closure& quit_closure) 64 const base::Closure& quit_closure)
65 : quit_closure_(quit_closure), weak_factory_(this) { 65 : quit_closure_(quit_closure), weak_factory_(this) {
66 DCHECK(!quit_closure_.is_null()); 66 DCHECK(!quit_closure_.is_null());
67 } 67 }
68 68
69 ServiceContextRefFactory::~ServiceContextRefFactory() {} 69 ServiceContextRefFactory::~ServiceContextRefFactory() {}
70 70
71 std::unique_ptr<ServiceContextRef> ServiceContextRefFactory::CreateRef() { 71 std::unique_ptr<ServiceContextRef> ServiceContextRefFactory::CreateRef() {
72 AddRef(); 72 AddRef();
73 return base::WrapUnique( 73 return base::MakeUnique<ServiceContextRefImpl>(
74 new ServiceContextRefImpl(weak_factory_.GetWeakPtr(), 74 weak_factory_.GetWeakPtr(), base::ThreadTaskRunnerHandle::Get());
75 base::ThreadTaskRunnerHandle::Get()));
76 } 75 }
77 76
78 void ServiceContextRefFactory::AddRef() { 77 void ServiceContextRefFactory::AddRef() {
79 ++ref_count_; 78 ++ref_count_;
80 } 79 }
81 80
82 void ServiceContextRefFactory::Release() { 81 void ServiceContextRefFactory::Release() {
83 if (!--ref_count_) 82 if (!--ref_count_)
84 quit_closure_.Run(); 83 quit_closure_.Run();
85 } 84 }
86 85
87 } // namespace shell 86 } // namespace shell
OLDNEW
« no previous file with comments | « services/shell/public/cpp/lib/interface_registry.cc ('k') | services/shell/public/cpp/lib/service_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698