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 <cstdio> | 5 #include <cstdio> |
6 #include <string> | 6 #include <string> |
7 | 7 |
8 #include "base/at_exit.h" | 8 #include "base/at_exit.h" |
9 #include "base/base64.h" | 9 #include "base/base64.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "base/message_loop.h" | 16 #include "base/message_loop.h" |
17 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
18 #include "jingle/notifier/base/notification_method.h" | 18 #include "jingle/notifier/base/notification_method.h" |
19 #include "jingle/notifier/base/notifier_options.h" | 19 #include "jingle/notifier/base/notifier_options.h" |
20 #include "net/base/host_port_pair.h" | 20 #include "net/base/host_port_pair.h" |
| 21 #include "net/base/host_resolver.h" |
21 #include "net/url_request/url_request_test_util.h" | 22 #include "net/url_request/url_request_test_util.h" |
22 #include "sync/notifier/invalidation_state_tracker.h" | 23 #include "sync/notifier/invalidation_state_tracker.h" |
23 #include "sync/notifier/sync_notifier.h" | 24 #include "sync/notifier/sync_notifier.h" |
24 #include "sync/notifier/sync_notifier_factory.h" | 25 #include "sync/notifier/sync_notifier_factory.h" |
25 #include "sync/notifier/sync_notifier_observer.h" | 26 #include "sync/notifier/sync_notifier_observer.h" |
26 #include "sync/syncable/model_type.h" | 27 #include "sync/syncable/model_type.h" |
27 #include "sync/syncable/model_type_payload_map.h" | 28 #include "sync/syncable/model_type_payload_map.h" |
28 | 29 |
29 // This is a simple utility that initializes a sync notifier and | 30 // This is a simple utility that initializes a sync notifier and |
30 // listens to any received notifications. | 31 // listens to any received notifications. |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 | 121 |
121 if (command_line.HasSwitch(kNotificationMethodSwitch)) { | 122 if (command_line.HasSwitch(kNotificationMethodSwitch)) { |
122 notifier_options.notification_method = | 123 notifier_options.notification_method = |
123 notifier::StringToNotificationMethod( | 124 notifier::StringToNotificationMethod( |
124 command_line.GetSwitchValueASCII(kNotificationMethodSwitch)); | 125 command_line.GetSwitchValueASCII(kNotificationMethodSwitch)); |
125 } | 126 } |
126 | 127 |
127 return notifier_options; | 128 return notifier_options; |
128 } | 129 } |
129 | 130 |
| 131 // Needed to use a real host resolver. |
| 132 class MyTestURLRequestContext : public TestURLRequestContext { |
| 133 public: |
| 134 MyTestURLRequestContext() : TestURLRequestContext(true) { |
| 135 context_storage_.set_host_resolver( |
| 136 net::CreateSystemHostResolver( |
| 137 net::HostResolver::kDefaultParallelism, |
| 138 net::HostResolver::kDefaultRetryAttempts, |
| 139 NULL)); |
| 140 Init(); |
| 141 } |
| 142 |
| 143 virtual ~MyTestURLRequestContext() {} |
| 144 }; |
| 145 |
| 146 class MyTestURLRequestContextGetter : public TestURLRequestContextGetter { |
| 147 public: |
| 148 explicit MyTestURLRequestContextGetter( |
| 149 const scoped_refptr<base::MessageLoopProxy>& io_message_loop_proxy) |
| 150 : TestURLRequestContextGetter(io_message_loop_proxy) {} |
| 151 |
| 152 virtual TestURLRequestContext* GetURLRequestContext() OVERRIDE { |
| 153 // Construct |context_| lazily so it gets constructed on the right |
| 154 // thread (the IO thread). |
| 155 if (!context_.get()) |
| 156 context_.reset(new MyTestURLRequestContext()); |
| 157 return context_.get(); |
| 158 } |
| 159 |
| 160 private: |
| 161 virtual ~MyTestURLRequestContextGetter() {} |
| 162 |
| 163 scoped_ptr<MyTestURLRequestContext> context_; |
| 164 }; |
| 165 |
130 } // namespace | 166 } // namespace |
131 | 167 |
132 int main(int argc, char* argv[]) { | 168 int main(int argc, char* argv[]) { |
133 base::AtExitManager exit_manager; | 169 base::AtExitManager exit_manager; |
134 CommandLine::Init(argc, argv); | 170 CommandLine::Init(argc, argv); |
135 logging::InitLogging( | 171 logging::InitLogging( |
136 NULL, | 172 NULL, |
137 logging::LOG_ONLY_TO_SYSTEM_DEBUG_LOG, | 173 logging::LOG_ONLY_TO_SYSTEM_DEBUG_LOG, |
138 logging::LOCK_LOG_FILE, | 174 logging::LOCK_LOG_FILE, |
139 logging::DELETE_OLD_LOG_FILE, | 175 logging::DELETE_OLD_LOG_FILE, |
(...skipping 22 matching lines...) Expand all Loading... |
162 argv[0], | 198 argv[0], |
163 kEmailSwitch, kTokenSwitch, kHostPortSwitch, | 199 kEmailSwitch, kTokenSwitch, kHostPortSwitch, |
164 kTrySslTcpFirstSwitch, kAllowInsecureConnectionSwitch, | 200 kTrySslTcpFirstSwitch, kAllowInsecureConnectionSwitch, |
165 kNotificationMethodSwitch); | 201 kNotificationMethodSwitch); |
166 return -1; | 202 return -1; |
167 } | 203 } |
168 | 204 |
169 const notifier::NotifierOptions& notifier_options = | 205 const notifier::NotifierOptions& notifier_options = |
170 ParseNotifierOptions( | 206 ParseNotifierOptions( |
171 command_line, | 207 command_line, |
172 new TestURLRequestContextGetter(io_thread.message_loop_proxy())); | 208 new MyTestURLRequestContextGetter(io_thread.message_loop_proxy())); |
173 const char kClientInfo[] = "sync_listen_notifications"; | 209 const char kClientInfo[] = "sync_listen_notifications"; |
174 NullInvalidationStateTracker null_invalidation_state_tracker; | 210 NullInvalidationStateTracker null_invalidation_state_tracker; |
175 sync_notifier::SyncNotifierFactory sync_notifier_factory( | 211 sync_notifier::SyncNotifierFactory sync_notifier_factory( |
176 notifier_options, kClientInfo, | 212 notifier_options, kClientInfo, |
177 null_invalidation_state_tracker.AsWeakPtr()); | 213 null_invalidation_state_tracker.AsWeakPtr()); |
178 scoped_ptr<sync_notifier::SyncNotifier> sync_notifier( | 214 scoped_ptr<sync_notifier::SyncNotifier> sync_notifier( |
179 sync_notifier_factory.CreateSyncNotifier()); | 215 sync_notifier_factory.CreateSyncNotifier()); |
180 NotificationPrinter notification_printer; | 216 NotificationPrinter notification_printer; |
181 sync_notifier->AddObserver(¬ification_printer); | 217 sync_notifier->AddObserver(¬ification_printer); |
182 | 218 |
183 const char kUniqueId[] = "fake_unique_id"; | 219 const char kUniqueId[] = "fake_unique_id"; |
184 sync_notifier->SetUniqueId(kUniqueId); | 220 sync_notifier->SetUniqueId(kUniqueId); |
185 sync_notifier->SetState(""); | 221 sync_notifier->SetState(""); |
186 sync_notifier->UpdateCredentials(email, token); | 222 sync_notifier->UpdateCredentials(email, token); |
187 // Listen for notifications for all known types. | 223 // Listen for notifications for all known types. |
188 sync_notifier->UpdateEnabledTypes(syncable::ModelTypeSet::All()); | 224 sync_notifier->UpdateEnabledTypes(syncable::ModelTypeSet::All()); |
189 | 225 |
190 ui_loop.Run(); | 226 ui_loop.Run(); |
191 | 227 |
192 sync_notifier->RemoveObserver(¬ification_printer); | 228 sync_notifier->RemoveObserver(¬ification_printer); |
193 io_thread.Stop(); | 229 io_thread.Stop(); |
194 return 0; | 230 return 0; |
195 } | 231 } |
OLD | NEW |