Chromium Code Reviews| 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 <cstddef> | 5 #include <cstddef> |
| 6 #include <cstdio> | 6 #include <cstdio> |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/at_exit.h" | 9 #include "base/at_exit.h" |
| 10 #include "base/base64.h" | 10 #include "base/base64.h" |
| 11 #include "base/bind.h" | |
| 12 #include "base/callback.h" | |
| 11 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 12 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 15 #include "base/location.h" | |
| 13 #include "base/logging.h" | 16 #include "base/logging.h" |
| 14 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/memory/weak_ptr.h" | 19 #include "base/memory/weak_ptr.h" |
| 17 #include "base/message_loop.h" | 20 #include "base/message_loop.h" |
| 18 #include "base/threading/thread.h" | 21 #include "base/threading/thread.h" |
| 19 #include "jingle/notifier/base/notification_method.h" | 22 #include "jingle/notifier/base/notification_method.h" |
| 20 #include "jingle/notifier/base/notifier_options.h" | 23 #include "jingle/notifier/base/notifier_options.h" |
| 21 #include "net/base/host_port_pair.h" | 24 #include "net/base/host_port_pair.h" |
| 22 #include "net/base/host_resolver.h" | 25 #include "net/base/host_resolver.h" |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 41 namespace syncer { | 44 namespace syncer { |
| 42 namespace { | 45 namespace { |
| 43 | 46 |
| 44 const char kEmailSwitch[] = "email"; | 47 const char kEmailSwitch[] = "email"; |
| 45 const char kTokenSwitch[] = "token"; | 48 const char kTokenSwitch[] = "token"; |
| 46 const char kHostPortSwitch[] = "host-port"; | 49 const char kHostPortSwitch[] = "host-port"; |
| 47 const char kTrySslTcpFirstSwitch[] = "try-ssltcp-first"; | 50 const char kTrySslTcpFirstSwitch[] = "try-ssltcp-first"; |
| 48 const char kAllowInsecureConnectionSwitch[] = "allow-insecure-connection"; | 51 const char kAllowInsecureConnectionSwitch[] = "allow-insecure-connection"; |
| 49 const char kNotificationMethodSwitch[] = "notification-method"; | 52 const char kNotificationMethodSwitch[] = "notification-method"; |
| 50 | 53 |
| 54 void GenerateAckHandlesReplyHelper( | |
|
akalin
2012/10/19 13:27:16
bind callback / ackhandles directly
dcheng
2012/10/19 19:38:11
Done.
| |
| 55 base::Callback<void(const AckHandleMap&)> callback, | |
| 56 const AckHandleMap& ack_handles) { | |
| 57 callback.Run(ack_handles); | |
| 58 } | |
| 59 | |
| 51 // Class to print received notifications events. | 60 // Class to print received notifications events. |
| 52 class NotificationPrinter : public InvalidationHandler { | 61 class NotificationPrinter : public InvalidationHandler { |
| 53 public: | 62 public: |
| 54 NotificationPrinter() {} | 63 NotificationPrinter() {} |
| 55 virtual ~NotificationPrinter() {} | 64 virtual ~NotificationPrinter() {} |
| 56 | 65 |
| 57 virtual void OnInvalidatorStateChange(InvalidatorState state) OVERRIDE { | 66 virtual void OnInvalidatorStateChange(InvalidatorState state) OVERRIDE { |
| 58 LOG(INFO) << "Invalidator state changed to " | 67 LOG(INFO) << "Invalidator state changed to " |
| 59 << InvalidatorStateToString(state); | 68 << InvalidatorStateToString(state); |
| 60 } | 69 } |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 78 DISALLOW_COPY_AND_ASSIGN(NotificationPrinter); | 87 DISALLOW_COPY_AND_ASSIGN(NotificationPrinter); |
| 79 }; | 88 }; |
| 80 | 89 |
| 81 class NullInvalidationStateTracker | 90 class NullInvalidationStateTracker |
| 82 : public base::SupportsWeakPtr<NullInvalidationStateTracker>, | 91 : public base::SupportsWeakPtr<NullInvalidationStateTracker>, |
| 83 public InvalidationStateTracker { | 92 public InvalidationStateTracker { |
| 84 public: | 93 public: |
| 85 NullInvalidationStateTracker() {} | 94 NullInvalidationStateTracker() {} |
| 86 virtual ~NullInvalidationStateTracker() {} | 95 virtual ~NullInvalidationStateTracker() {} |
| 87 | 96 |
| 88 virtual InvalidationVersionMap GetAllMaxVersions() const OVERRIDE { | 97 virtual InvalidationStateMap GetStateMap() const OVERRIDE { |
| 89 return InvalidationVersionMap(); | 98 return InvalidationStateMap(); |
| 90 } | 99 } |
| 91 | 100 |
| 92 virtual void SetMaxVersion( | 101 virtual void SetMaxVersion( |
| 93 const invalidation::ObjectId& id, | 102 const invalidation::ObjectId& id, |
| 94 int64 max_invalidation_version) OVERRIDE { | 103 int64 max_invalidation_version) OVERRIDE { |
| 95 LOG(INFO) << "Setting max invalidation version for " | 104 LOG(INFO) << "Setting max invalidation version for " |
| 96 << ObjectIdToString(id) << " to " << max_invalidation_version; | 105 << ObjectIdToString(id) << " to " << max_invalidation_version; |
| 97 } | 106 } |
| 98 | 107 |
| 99 virtual void Forget(const ObjectIdSet& ids) OVERRIDE { | 108 virtual void Forget(const ObjectIdSet& ids) OVERRIDE { |
| 100 for (ObjectIdSet::const_iterator it = ids.begin(); it != ids.end(); ++it) { | 109 for (ObjectIdSet::const_iterator it = ids.begin(); it != ids.end(); ++it) { |
| 101 LOG(INFO) << "Forgetting saved state for " << ObjectIdToString(*it); | 110 LOG(INFO) << "Forgetting saved state for " << ObjectIdToString(*it); |
| 102 } | 111 } |
| 103 } | 112 } |
| 104 | 113 |
| 105 virtual std::string GetBootstrapData() const OVERRIDE { | 114 virtual std::string GetBootstrapData() const OVERRIDE { |
| 106 return std::string(); | 115 return std::string(); |
| 107 } | 116 } |
| 108 | 117 |
| 109 virtual void SetBootstrapData(const std::string& data) OVERRIDE { | 118 virtual void SetBootstrapData(const std::string& data) OVERRIDE { |
| 110 std::string base64_data; | 119 std::string base64_data; |
| 111 CHECK(base::Base64Encode(data, &base64_data)); | 120 CHECK(base::Base64Encode(data, &base64_data)); |
| 112 LOG(INFO) << "Setting bootstrap data to: " << base64_data; | 121 LOG(INFO) << "Setting bootstrap data to: " << base64_data; |
| 113 } | 122 } |
| 123 | |
| 124 virtual void GenerateAckHandles( | |
| 125 const ObjectIdSet& ids, | |
| 126 const scoped_refptr<base::TaskRunner>& task_runner, | |
| 127 base::Callback<void(const AckHandleMap&)> callback) OVERRIDE { | |
| 128 AckHandleMap ack_handles; | |
| 129 for (ObjectIdSet::const_iterator it = ids.begin(); it != ids.end(); ++it) { | |
| 130 ack_handles.insert(std::make_pair(*it, AckHandle::InvalidAckHandle())); | |
| 131 } | |
| 132 task_runner->PostTask(FROM_HERE, | |
| 133 base::Bind(&GenerateAckHandlesReplyHelper, | |
| 134 callback, ack_handles)); | |
| 135 } | |
| 136 | |
| 137 virtual void Acknowledge(const invalidation::ObjectId& id, | |
| 138 const AckHandle& ack_handle) OVERRIDE { | |
| 139 LOG(INFO) << "Received ack for " << ObjectIdToString(id); | |
| 140 } | |
| 114 }; | 141 }; |
| 115 | 142 |
| 116 // Needed to use a real host resolver. | 143 // Needed to use a real host resolver. |
| 117 class MyTestURLRequestContext : public TestURLRequestContext { | 144 class MyTestURLRequestContext : public TestURLRequestContext { |
| 118 public: | 145 public: |
| 119 MyTestURLRequestContext() : TestURLRequestContext(true) { | 146 MyTestURLRequestContext() : TestURLRequestContext(true) { |
| 120 context_storage_.set_host_resolver( | 147 context_storage_.set_host_resolver( |
| 121 net::CreateSystemHostResolver( | 148 net::CreateSystemHostResolver( |
| 122 net::HostResolver::kDefaultParallelism, | 149 net::HostResolver::kDefaultParallelism, |
| 123 net::HostResolver::kDefaultRetryAttempts, | 150 net::HostResolver::kDefaultRetryAttempts, |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 257 io_thread.Stop(); | 284 io_thread.Stop(); |
| 258 return 0; | 285 return 0; |
| 259 } | 286 } |
| 260 | 287 |
| 261 } // namespace | 288 } // namespace |
| 262 } // namespace syncer | 289 } // namespace syncer |
| 263 | 290 |
| 264 int main(int argc, char* argv[]) { | 291 int main(int argc, char* argv[]) { |
| 265 return syncer::SyncListenNotificationsMain(argc, argv); | 292 return syncer::SyncListenNotificationsMain(argc, argv); |
| 266 } | 293 } |
| OLD | NEW |