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

Side by Side Diff: sync/tools/sync_listen_notifications.cc

Issue 1866243002: Convert //sync from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 <cstddef> 5 #include <cstddef>
6 #include <cstdio> 6 #include <cstdio>
7 #include <memory>
7 #include <string> 8 #include <string>
8 9
9 #include "base/at_exit.h" 10 #include "base/at_exit.h"
10 #include "base/command_line.h" 11 #include "base/command_line.h"
11 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
12 #include "base/logging.h" 13 #include "base/logging.h"
13 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/ptr_util.h"
14 #include "base/memory/ref_counted.h" 16 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/message_loop/message_loop.h" 17 #include "base/message_loop/message_loop.h"
17 #include "base/rand_util.h" 18 #include "base/rand_util.h"
18 #include "base/threading/thread.h" 19 #include "base/threading/thread.h"
19 #include "build/build_config.h" 20 #include "build/build_config.h"
20 #include "components/invalidation/impl/invalidation_state_tracker.h" 21 #include "components/invalidation/impl/invalidation_state_tracker.h"
21 #include "components/invalidation/impl/invalidator.h" 22 #include "components/invalidation/impl/invalidator.h"
22 #include "components/invalidation/impl/non_blocking_invalidator.h" 23 #include "components/invalidation/impl/non_blocking_invalidator.h"
23 #include "components/invalidation/public/invalidation_handler.h" 24 #include "components/invalidation/public/invalidation_handler.h"
24 #include "components/invalidation/public/invalidation_util.h" 25 #include "components/invalidation/public/invalidation_util.h"
25 #include "components/invalidation/public/object_id_invalidation_map.h" 26 #include "components/invalidation/public/object_id_invalidation_map.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 DISALLOW_COPY_AND_ASSIGN(NotificationPrinter); 77 DISALLOW_COPY_AND_ASSIGN(NotificationPrinter);
77 }; 78 };
78 79
79 // Needed to use a real host resolver. 80 // Needed to use a real host resolver.
80 class MyTestURLRequestContext : public net::TestURLRequestContext { 81 class MyTestURLRequestContext : public net::TestURLRequestContext {
81 public: 82 public:
82 MyTestURLRequestContext() : TestURLRequestContext(true) { 83 MyTestURLRequestContext() : TestURLRequestContext(true) {
83 context_storage_.set_host_resolver( 84 context_storage_.set_host_resolver(
84 net::HostResolver::CreateDefaultResolver(NULL)); 85 net::HostResolver::CreateDefaultResolver(NULL));
85 context_storage_.set_transport_security_state( 86 context_storage_.set_transport_security_state(
86 make_scoped_ptr(new net::TransportSecurityState())); 87 base::WrapUnique(new net::TransportSecurityState()));
87 Init(); 88 Init();
88 } 89 }
89 90
90 ~MyTestURLRequestContext() override {} 91 ~MyTestURLRequestContext() override {}
91 }; 92 };
92 93
93 class MyTestURLRequestContextGetter : public net::TestURLRequestContextGetter { 94 class MyTestURLRequestContextGetter : public net::TestURLRequestContextGetter {
94 public: 95 public:
95 explicit MyTestURLRequestContextGetter( 96 explicit MyTestURLRequestContextGetter(
96 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner) 97 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner)
97 : TestURLRequestContextGetter(io_task_runner) {} 98 : TestURLRequestContextGetter(io_task_runner) {}
98 99
99 net::TestURLRequestContext* GetURLRequestContext() override { 100 net::TestURLRequestContext* GetURLRequestContext() override {
100 // Construct |context_| lazily so it gets constructed on the right 101 // Construct |context_| lazily so it gets constructed on the right
101 // thread (the IO thread). 102 // thread (the IO thread).
102 if (!context_) 103 if (!context_)
103 context_.reset(new MyTestURLRequestContext()); 104 context_.reset(new MyTestURLRequestContext());
104 return context_.get(); 105 return context_.get();
105 } 106 }
106 107
107 private: 108 private:
108 ~MyTestURLRequestContextGetter() override {} 109 ~MyTestURLRequestContextGetter() override {}
109 110
110 scoped_ptr<MyTestURLRequestContext> context_; 111 std::unique_ptr<MyTestURLRequestContext> context_;
111 }; 112 };
112 113
113 notifier::NotifierOptions ParseNotifierOptions( 114 notifier::NotifierOptions ParseNotifierOptions(
114 const base::CommandLine& command_line, 115 const base::CommandLine& command_line,
115 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter) { 116 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter) {
116 notifier::NotifierOptions notifier_options; 117 notifier::NotifierOptions notifier_options;
117 notifier_options.request_context_getter = request_context_getter; 118 notifier_options.request_context_getter = request_context_getter;
118 119
119 if (command_line.HasSwitch(kHostPortSwitch)) { 120 if (command_line.HasSwitch(kHostPortSwitch)) {
120 notifier_options.xmpp_host_port = 121 notifier_options.xmpp_host_port =
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 "syncer::SyncManagerImpl::UpdateCredentials() " 168 "syncer::SyncManagerImpl::UpdateCredentials() "
168 "after logging into\n" 169 "after logging into\n"
169 "sync to get the token to pass into this utility.\n", 170 "sync to get the token to pass into this utility.\n",
170 argv[0], 171 argv[0],
171 kEmailSwitch, kTokenSwitch, kHostPortSwitch, 172 kEmailSwitch, kTokenSwitch, kHostPortSwitch,
172 kTrySslTcpFirstSwitch, kAllowInsecureConnectionSwitch); 173 kTrySslTcpFirstSwitch, kAllowInsecureConnectionSwitch);
173 return -1; 174 return -1;
174 } 175 }
175 176
176 // Set up objects that monitor the network. 177 // Set up objects that monitor the network.
177 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier( 178 std::unique_ptr<net::NetworkChangeNotifier> network_change_notifier(
178 net::NetworkChangeNotifier::Create()); 179 net::NetworkChangeNotifier::Create());
179 180
180 const notifier::NotifierOptions& notifier_options = 181 const notifier::NotifierOptions& notifier_options =
181 ParseNotifierOptions( 182 ParseNotifierOptions(
182 command_line, 183 command_line,
183 new MyTestURLRequestContextGetter(io_thread.task_runner())); 184 new MyTestURLRequestContextGetter(io_thread.task_runner()));
184 syncer::NetworkChannelCreator network_channel_creator = 185 syncer::NetworkChannelCreator network_channel_creator =
185 syncer::NonBlockingInvalidator::MakePushClientChannelCreator( 186 syncer::NonBlockingInvalidator::MakePushClientChannelCreator(
186 notifier_options); 187 notifier_options);
187 const char kClientInfo[] = "sync_listen_notifications"; 188 const char kClientInfo[] = "sync_listen_notifications";
188 NullInvalidationStateTracker null_invalidation_state_tracker; 189 NullInvalidationStateTracker null_invalidation_state_tracker;
189 scoped_ptr<Invalidator> invalidator( 190 std::unique_ptr<Invalidator> invalidator(new NonBlockingInvalidator(
190 new NonBlockingInvalidator( 191 network_channel_creator, base::RandBytesAsString(8),
191 network_channel_creator, 192 null_invalidation_state_tracker.GetSavedInvalidations(),
192 base::RandBytesAsString(8), 193 null_invalidation_state_tracker.GetBootstrapData(),
193 null_invalidation_state_tracker.GetSavedInvalidations(), 194 &null_invalidation_state_tracker, kClientInfo,
194 null_invalidation_state_tracker.GetBootstrapData(), 195 notifier_options.request_context_getter));
195 &null_invalidation_state_tracker,
196 kClientInfo,
197 notifier_options.request_context_getter));
198 196
199 NotificationPrinter notification_printer; 197 NotificationPrinter notification_printer;
200 198
201 invalidator->UpdateCredentials(email, token); 199 invalidator->UpdateCredentials(email, token);
202 200
203 // Listen for notifications for all known types. 201 // Listen for notifications for all known types.
204 invalidator->RegisterHandler(&notification_printer); 202 invalidator->RegisterHandler(&notification_printer);
205 CHECK(invalidator->UpdateRegisteredIds( 203 CHECK(invalidator->UpdateRegisteredIds(
206 &notification_printer, ModelTypeSetToObjectIdSet(ModelTypeSet::All()))); 204 &notification_printer, ModelTypeSetToObjectIdSet(ModelTypeSet::All())));
207 205
208 ui_loop.Run(); 206 ui_loop.Run();
209 207
210 invalidator->UnregisterHandler(&notification_printer); 208 invalidator->UnregisterHandler(&notification_printer);
211 io_thread.Stop(); 209 io_thread.Stop();
212 return 0; 210 return 0;
213 } 211 }
214 212
215 } // namespace 213 } // namespace
216 } // namespace syncer 214 } // namespace syncer
217 215
218 int main(int argc, char* argv[]) { 216 int main(int argc, char* argv[]) {
219 return syncer::SyncListenNotificationsMain(argc, argv); 217 return syncer::SyncListenNotificationsMain(argc, argv);
220 } 218 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698