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

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

Issue 2130453004: [Sync] Move //sync to //components/sync. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. 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
« no previous file with comments | « components/sync/tools/sync_client.cc ('k') | components/sync/tools/sync_tools.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <memory>
8 #include <string> 8 #include <string>
9 9
10 #include "base/at_exit.h" 10 #include "base/at_exit.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/ptr_util.h" 15 #include "base/memory/ptr_util.h"
16 #include "base/memory/ref_counted.h" 16 #include "base/memory/ref_counted.h"
17 #include "base/message_loop/message_loop.h" 17 #include "base/message_loop/message_loop.h"
18 #include "base/rand_util.h" 18 #include "base/rand_util.h"
19 #include "base/run_loop.h" 19 #include "base/run_loop.h"
20 #include "base/threading/thread.h" 20 #include "base/threading/thread.h"
21 #include "build/build_config.h" 21 #include "build/build_config.h"
22 #include "components/invalidation/impl/invalidation_state_tracker.h" 22 #include "components/invalidation/impl/invalidation_state_tracker.h"
23 #include "components/invalidation/impl/invalidator.h" 23 #include "components/invalidation/impl/invalidator.h"
24 #include "components/invalidation/impl/non_blocking_invalidator.h" 24 #include "components/invalidation/impl/non_blocking_invalidator.h"
25 #include "components/invalidation/public/invalidation_handler.h" 25 #include "components/invalidation/public/invalidation_handler.h"
26 #include "components/invalidation/public/invalidation_util.h" 26 #include "components/invalidation/public/invalidation_util.h"
27 #include "components/invalidation/public/object_id_invalidation_map.h" 27 #include "components/invalidation/public/object_id_invalidation_map.h"
28 #include "components/sync/base/model_type.h"
29 #include "components/sync/tools/null_invalidation_state_tracker.h"
28 #include "components/sync_driver/invalidation_helper.h" 30 #include "components/sync_driver/invalidation_helper.h"
29 #include "jingle/notifier/base/notification_method.h" 31 #include "jingle/notifier/base/notification_method.h"
30 #include "jingle/notifier/base/notifier_options.h" 32 #include "jingle/notifier/base/notifier_options.h"
31 #include "net/base/host_port_pair.h" 33 #include "net/base/host_port_pair.h"
32 #include "net/base/network_change_notifier.h" 34 #include "net/base/network_change_notifier.h"
33 #include "net/dns/host_resolver.h" 35 #include "net/dns/host_resolver.h"
34 #include "net/http/transport_security_state.h" 36 #include "net/http/transport_security_state.h"
35 #include "net/url_request/url_request_test_util.h" 37 #include "net/url_request/url_request_test_util.h"
36 #include "sync/internal_api/public/base/model_type.h"
37 #include "sync/tools/null_invalidation_state_tracker.h"
38 38
39 #if defined(OS_MACOSX) 39 #if defined(OS_MACOSX)
40 #include "base/mac/scoped_nsautorelease_pool.h" 40 #include "base/mac/scoped_nsautorelease_pool.h"
41 #endif 41 #endif
42 42
43 // This is a simple utility that initializes a sync notifier and 43 // This is a simple utility that initializes a sync notifier and
44 // listens to any received notifications. 44 // listens to any received notifications.
45 45
46 namespace syncer { 46 namespace syncer {
47 namespace { 47 namespace {
(...skipping 12 matching lines...) Expand all
60 60
61 void OnInvalidatorStateChange(InvalidatorState state) override { 61 void OnInvalidatorStateChange(InvalidatorState state) override {
62 LOG(INFO) << "Invalidator state changed to " 62 LOG(INFO) << "Invalidator state changed to "
63 << InvalidatorStateToString(state); 63 << InvalidatorStateToString(state);
64 } 64 }
65 65
66 void OnIncomingInvalidation( 66 void OnIncomingInvalidation(
67 const ObjectIdInvalidationMap& invalidation_map) override { 67 const ObjectIdInvalidationMap& invalidation_map) override {
68 ObjectIdSet ids = invalidation_map.GetObjectIds(); 68 ObjectIdSet ids = invalidation_map.GetObjectIds();
69 for (ObjectIdSet::const_iterator it = ids.begin(); it != ids.end(); ++it) { 69 for (ObjectIdSet::const_iterator it = ids.begin(); it != ids.end(); ++it) {
70 LOG(INFO) << "Remote invalidation: " 70 LOG(INFO) << "Remote invalidation: " << invalidation_map.ToString();
71 << invalidation_map.ToString();
72 } 71 }
73 } 72 }
74 73
75 std::string GetOwnerName() const override { return "NotificationPrinter"; } 74 std::string GetOwnerName() const override { return "NotificationPrinter"; }
76 75
77 private: 76 private:
78 DISALLOW_COPY_AND_ASSIGN(NotificationPrinter); 77 DISALLOW_COPY_AND_ASSIGN(NotificationPrinter);
79 }; 78 };
80 79
81 // Needed to use a real host resolver. 80 // Needed to use a real host resolver.
(...skipping 30 matching lines...) Expand all
112 std::unique_ptr<MyTestURLRequestContext> context_; 111 std::unique_ptr<MyTestURLRequestContext> context_;
113 }; 112 };
114 113
115 notifier::NotifierOptions ParseNotifierOptions( 114 notifier::NotifierOptions ParseNotifierOptions(
116 const base::CommandLine& command_line, 115 const base::CommandLine& command_line,
117 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter) { 116 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter) {
118 notifier::NotifierOptions notifier_options; 117 notifier::NotifierOptions notifier_options;
119 notifier_options.request_context_getter = request_context_getter; 118 notifier_options.request_context_getter = request_context_getter;
120 119
121 if (command_line.HasSwitch(kHostPortSwitch)) { 120 if (command_line.HasSwitch(kHostPortSwitch)) {
122 notifier_options.xmpp_host_port = 121 notifier_options.xmpp_host_port = net::HostPortPair::FromString(
123 net::HostPortPair::FromString( 122 command_line.GetSwitchValueASCII(kHostPortSwitch));
124 command_line.GetSwitchValueASCII(kHostPortSwitch));
125 LOG(INFO) << "Using " << notifier_options.xmpp_host_port.ToString() 123 LOG(INFO) << "Using " << notifier_options.xmpp_host_port.ToString()
126 << " for test sync notification server."; 124 << " for test sync notification server.";
127 } 125 }
128 126
129 notifier_options.try_ssltcp_first = 127 notifier_options.try_ssltcp_first =
130 command_line.HasSwitch(kTrySslTcpFirstSwitch); 128 command_line.HasSwitch(kTrySslTcpFirstSwitch);
131 LOG_IF(INFO, notifier_options.try_ssltcp_first) 129 LOG_IF(INFO, notifier_options.try_ssltcp_first)
132 << "Trying SSL/TCP port before XMPP port for notifications."; 130 << "Trying SSL/TCP port before XMPP port for notifications.";
133 131
134 notifier_options.allow_insecure_connection = 132 notifier_options.allow_insecure_connection =
(...skipping 21 matching lines...) Expand all
156 io_thread.StartWithOptions(options); 154 io_thread.StartWithOptions(options);
157 155
158 // Parse command line. 156 // Parse command line.
159 const base::CommandLine& command_line = 157 const base::CommandLine& command_line =
160 *base::CommandLine::ForCurrentProcess(); 158 *base::CommandLine::ForCurrentProcess();
161 std::string email = command_line.GetSwitchValueASCII(kEmailSwitch); 159 std::string email = command_line.GetSwitchValueASCII(kEmailSwitch);
162 std::string token = command_line.GetSwitchValueASCII(kTokenSwitch); 160 std::string token = command_line.GetSwitchValueASCII(kTokenSwitch);
163 // TODO(akalin): Write a wrapper script that gets a token for an 161 // TODO(akalin): Write a wrapper script that gets a token for an
164 // email and password and passes that in to this utility. 162 // email and password and passes that in to this utility.
165 if (email.empty() || token.empty()) { 163 if (email.empty() || token.empty()) {
166 std::printf("Usage: %s --%s=foo@bar.com --%s=token\n" 164 std::printf(
167 "[--%s=host:port] [--%s] [--%s]\n" 165 "Usage: %s --%s=foo@bar.com --%s=token\n"
168 "Run chrome and set a breakpoint on\n" 166 "[--%s=host:port] [--%s] [--%s]\n"
169 "syncer::SyncManagerImpl::UpdateCredentials() " 167 "Run chrome and set a breakpoint on\n"
170 "after logging into\n" 168 "syncer::SyncManagerImpl::UpdateCredentials() "
171 "sync to get the token to pass into this utility.\n", 169 "after logging into\n"
172 argv[0], 170 "sync to get the token to pass into this utility.\n",
173 kEmailSwitch, kTokenSwitch, kHostPortSwitch, 171 argv[0], kEmailSwitch, kTokenSwitch, kHostPortSwitch,
174 kTrySslTcpFirstSwitch, kAllowInsecureConnectionSwitch); 172 kTrySslTcpFirstSwitch, kAllowInsecureConnectionSwitch);
175 return -1; 173 return -1;
176 } 174 }
177 175
178 // Set up objects that monitor the network. 176 // Set up objects that monitor the network.
179 std::unique_ptr<net::NetworkChangeNotifier> network_change_notifier( 177 std::unique_ptr<net::NetworkChangeNotifier> network_change_notifier(
180 net::NetworkChangeNotifier::Create()); 178 net::NetworkChangeNotifier::Create());
181 179
182 const notifier::NotifierOptions& notifier_options = 180 const notifier::NotifierOptions& notifier_options = ParseNotifierOptions(
183 ParseNotifierOptions( 181 command_line, new MyTestURLRequestContextGetter(io_thread.task_runner()));
184 command_line,
185 new MyTestURLRequestContextGetter(io_thread.task_runner()));
186 syncer::NetworkChannelCreator network_channel_creator = 182 syncer::NetworkChannelCreator network_channel_creator =
187 syncer::NonBlockingInvalidator::MakePushClientChannelCreator( 183 syncer::NonBlockingInvalidator::MakePushClientChannelCreator(
188 notifier_options); 184 notifier_options);
189 const char kClientInfo[] = "sync_listen_notifications"; 185 const char kClientInfo[] = "sync_listen_notifications";
190 NullInvalidationStateTracker null_invalidation_state_tracker; 186 NullInvalidationStateTracker null_invalidation_state_tracker;
191 std::unique_ptr<Invalidator> invalidator(new NonBlockingInvalidator( 187 std::unique_ptr<Invalidator> invalidator(new NonBlockingInvalidator(
192 network_channel_creator, base::RandBytesAsString(8), 188 network_channel_creator, base::RandBytesAsString(8),
193 null_invalidation_state_tracker.GetSavedInvalidations(), 189 null_invalidation_state_tracker.GetSavedInvalidations(),
194 null_invalidation_state_tracker.GetBootstrapData(), 190 null_invalidation_state_tracker.GetBootstrapData(),
195 &null_invalidation_state_tracker, kClientInfo, 191 &null_invalidation_state_tracker, kClientInfo,
(...skipping 14 matching lines...) Expand all
210 io_thread.Stop(); 206 io_thread.Stop();
211 return 0; 207 return 0;
212 } 208 }
213 209
214 } // namespace 210 } // namespace
215 } // namespace syncer 211 } // namespace syncer
216 212
217 int main(int argc, char* argv[]) { 213 int main(int argc, char* argv[]) {
218 return syncer::SyncListenNotificationsMain(argc, argv); 214 return syncer::SyncListenNotificationsMain(argc, argv);
219 } 215 }
OLDNEW
« no previous file with comments | « components/sync/tools/sync_client.cc ('k') | components/sync/tools/sync_tools.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698