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

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

Issue 10435007: [Sync] Fix sync_listen_notifications to use a real host resolver (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix DEPS Created 8 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 | Annotate | Revision Log
« no previous file with comments | « sync/tools/DEPS ('k') | sync/util/DEPS » ('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 <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
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 }
szym 2012/05/24 04:33:44 nit: no need for braces
akalin 2012/05/24 23:19:36 Done.
158 return context_.get();
159 }
160
161 private:
162 virtual ~MyTestURLRequestContextGetter() {}
163
164 scoped_ptr<MyTestURLRequestContext> context_;
165 };
166
130 } // namespace 167 } // namespace
131 168
132 int main(int argc, char* argv[]) { 169 int main(int argc, char* argv[]) {
133 base::AtExitManager exit_manager; 170 base::AtExitManager exit_manager;
134 CommandLine::Init(argc, argv); 171 CommandLine::Init(argc, argv);
135 logging::InitLogging( 172 logging::InitLogging(
136 NULL, 173 NULL,
137 logging::LOG_ONLY_TO_SYSTEM_DEBUG_LOG, 174 logging::LOG_ONLY_TO_SYSTEM_DEBUG_LOG,
138 logging::LOCK_LOG_FILE, 175 logging::LOCK_LOG_FILE,
139 logging::DELETE_OLD_LOG_FILE, 176 logging::DELETE_OLD_LOG_FILE,
(...skipping 22 matching lines...) Expand all
162 argv[0], 199 argv[0],
163 kEmailSwitch, kTokenSwitch, kHostPortSwitch, 200 kEmailSwitch, kTokenSwitch, kHostPortSwitch,
164 kTrySslTcpFirstSwitch, kAllowInsecureConnectionSwitch, 201 kTrySslTcpFirstSwitch, kAllowInsecureConnectionSwitch,
165 kNotificationMethodSwitch); 202 kNotificationMethodSwitch);
166 return -1; 203 return -1;
167 } 204 }
168 205
169 const notifier::NotifierOptions& notifier_options = 206 const notifier::NotifierOptions& notifier_options =
170 ParseNotifierOptions( 207 ParseNotifierOptions(
171 command_line, 208 command_line,
172 new TestURLRequestContextGetter(io_thread.message_loop_proxy())); 209 new MyTestURLRequestContextGetter(io_thread.message_loop_proxy()));
173 const char kClientInfo[] = "sync_listen_notifications"; 210 const char kClientInfo[] = "sync_listen_notifications";
174 NullInvalidationStateTracker null_invalidation_state_tracker; 211 NullInvalidationStateTracker null_invalidation_state_tracker;
175 sync_notifier::SyncNotifierFactory sync_notifier_factory( 212 sync_notifier::SyncNotifierFactory sync_notifier_factory(
176 notifier_options, kClientInfo, 213 notifier_options, kClientInfo,
177 null_invalidation_state_tracker.AsWeakPtr()); 214 null_invalidation_state_tracker.AsWeakPtr());
178 scoped_ptr<sync_notifier::SyncNotifier> sync_notifier( 215 scoped_ptr<sync_notifier::SyncNotifier> sync_notifier(
179 sync_notifier_factory.CreateSyncNotifier()); 216 sync_notifier_factory.CreateSyncNotifier());
180 NotificationPrinter notification_printer; 217 NotificationPrinter notification_printer;
181 sync_notifier->AddObserver(&notification_printer); 218 sync_notifier->AddObserver(&notification_printer);
182 219
183 const char kUniqueId[] = "fake_unique_id"; 220 const char kUniqueId[] = "fake_unique_id";
184 sync_notifier->SetUniqueId(kUniqueId); 221 sync_notifier->SetUniqueId(kUniqueId);
185 sync_notifier->SetState(""); 222 sync_notifier->SetState("");
186 sync_notifier->UpdateCredentials(email, token); 223 sync_notifier->UpdateCredentials(email, token);
187 // Listen for notifications for all known types. 224 // Listen for notifications for all known types.
188 sync_notifier->UpdateEnabledTypes(syncable::ModelTypeSet::All()); 225 sync_notifier->UpdateEnabledTypes(syncable::ModelTypeSet::All());
189 226
190 ui_loop.Run(); 227 ui_loop.Run();
191 228
192 sync_notifier->RemoveObserver(&notification_printer); 229 sync_notifier->RemoveObserver(&notification_printer);
193 io_thread.Stop(); 230 io_thread.Stop();
194 return 0; 231 return 0;
195 } 232 }
OLDNEW
« no previous file with comments | « sync/tools/DEPS ('k') | sync/util/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698