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

Unified Diff: chrome/browser/p2p_invalidation_service.cc

Issue 13197004: Draft: InvalidationService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Passes tests Created 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/p2p_invalidation_service.cc
diff --git a/chrome/browser/p2p_invalidation_service.cc b/chrome/browser/p2p_invalidation_service.cc
new file mode 100644
index 0000000000000000000000000000000000000000..deff822bb661c182eaeb179d89294499c5a3416b
--- /dev/null
+++ b/chrome/browser/p2p_invalidation_service.cc
@@ -0,0 +1,132 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/p2p_invalidation_service.h"
+
+#include "base/base64.h"
+#include "base/command_line.h"
+#include "base/rand_util.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/common/chrome_switches.h"
+#include "sync/notifier/p2p_invalidator.h"
+
+namespace net {
+class URLRequestContextGetter;
+}
+
+// FIXME: duplicated code.
+namespace {
+// Parses the given command line for notifier options.
+notifier::NotifierOptions ParseNotifierOptions(
+ const CommandLine& command_line,
+ const scoped_refptr<net::URLRequestContextGetter>&
+ request_context_getter) {
+ notifier::NotifierOptions notifier_options;
+ notifier_options.request_context_getter = request_context_getter;
+
+ if (command_line.HasSwitch(switches::kSyncNotificationHostPort)) {
+ notifier_options.xmpp_host_port =
+ net::HostPortPair::FromString(
+ command_line.GetSwitchValueASCII(
+ switches::kSyncNotificationHostPort));
+ DVLOG(1) << "Using " << notifier_options.xmpp_host_port.ToString()
+ << " for test sync notification server.";
+ }
+
+ notifier_options.try_ssltcp_first =
+ command_line.HasSwitch(switches::kSyncTrySsltcpFirstForXmpp);
+ DVLOG_IF(1, notifier_options.try_ssltcp_first)
+ << "Trying SSL/TCP port before XMPP port for notifications.";
+
+ notifier_options.invalidate_xmpp_login =
+ command_line.HasSwitch(switches::kSyncInvalidateXmppLogin);
+ DVLOG_IF(1, notifier_options.invalidate_xmpp_login)
+ << "Invalidating sync XMPP login.";
+
+ notifier_options.allow_insecure_connection =
+ command_line.HasSwitch(switches::kSyncAllowInsecureXmppConnection);
+ DVLOG_IF(1, notifier_options.allow_insecure_connection)
+ << "Allowing insecure XMPP connections.";
+
+ if (command_line.HasSwitch(switches::kSyncNotificationMethod)) {
+ const std::string notification_method_str(
+ command_line.GetSwitchValueASCII(switches::kSyncNotificationMethod));
+ notifier_options.notification_method =
+ notifier::StringToNotificationMethod(notification_method_str);
+ }
+
+ return notifier_options;
+}
+
+std::string GenerateInvalidatorClientId() {
+ // Generate a GUID with 128 bits worth of base64-encoded randomness.
+ // This format is similar to that of sync's cache_guid.
+ const int kGuidBytes = 128 / 8;
+ std::string guid;
+ base::Base64Encode(base::RandBytesAsString(kGuidBytes), &guid);
+ return guid;
+}
+
+} // namespace
+
+P2PInvalidationService::P2PInvalidationService() {
+}
+
+P2PInvalidationService::~P2PInvalidationService() {
+}
+
+void P2PInvalidationService::Init(Profile* profile) {
+ notifier::NotifierOptions notifier_options =
+ ParseNotifierOptions(*CommandLine::ForCurrentProcess(),
+ profile->GetRequestContext());
+ invalidator_id_ = GenerateInvalidatorClientId();
+ invalidator_.reset(new syncer::P2PInvalidator(
+ notifier::PushClient::CreateDefault(notifier_options),
+ invalidator_id_,
+ syncer::NOTIFY_ALL));
+}
+
+void P2PInvalidationService::UpdateCredentials(const std::string& username,
+ const std::string& password) {
+ invalidator_->UpdateCredentials(username, password);
+}
+
+void P2PInvalidationService::Shutdown() {
+ invalidator_.reset();
+}
+
+void P2PInvalidationService::RegisterInvalidationHandler(
+ syncer::InvalidationHandler* handler) {
+ invalidator_->RegisterHandler(handler);
+}
+
+void P2PInvalidationService::UpdateRegisteredInvalidationIds(
+ syncer::InvalidationHandler* handler,
+ const syncer::ObjectIdSet& ids) {
+ invalidator_->UpdateRegisteredIds(handler, ids);
+}
+
+void P2PInvalidationService::UnregisterInvalidationHandler(
+ syncer::InvalidationHandler* handler) {
+ invalidator_->UnregisterHandler(handler);
+}
+
+void P2PInvalidationService::AcknowledgeInvalidation(
+ const invalidation::ObjectId& id,
+ const syncer::AckHandle& ack_handle) {
+ invalidator_->Acknowledge(id, ack_handle);
+}
+
+void P2PInvalidationService::SendInvalidation(
+ const syncer::ObjectIdInvalidationMap& invalidation_map) {
+ invalidator_->SendInvalidation(invalidation_map);
+}
+
+syncer::InvalidatorState P2PInvalidationService::GetInvalidatorState() const {
+ return invalidator_->GetInvalidatorState();
+}
+
+std::string P2PInvalidationService::GetInvalidatorClientId() const {
+ return invalidator_id_;
+}

Powered by Google App Engine
This is Rietveld 408576698