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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/p2p_invalidation_service.h"
6
7 #include "base/base64.h"
8 #include "base/command_line.h"
9 #include "base/rand_util.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/common/chrome_switches.h"
12 #include "sync/notifier/p2p_invalidator.h"
13
14 namespace net {
15 class URLRequestContextGetter;
16 }
17
18 // FIXME: duplicated code.
19 namespace {
20 // Parses the given command line for notifier options.
21 notifier::NotifierOptions ParseNotifierOptions(
22 const CommandLine& command_line,
23 const scoped_refptr<net::URLRequestContextGetter>&
24 request_context_getter) {
25 notifier::NotifierOptions notifier_options;
26 notifier_options.request_context_getter = request_context_getter;
27
28 if (command_line.HasSwitch(switches::kSyncNotificationHostPort)) {
29 notifier_options.xmpp_host_port =
30 net::HostPortPair::FromString(
31 command_line.GetSwitchValueASCII(
32 switches::kSyncNotificationHostPort));
33 DVLOG(1) << "Using " << notifier_options.xmpp_host_port.ToString()
34 << " for test sync notification server.";
35 }
36
37 notifier_options.try_ssltcp_first =
38 command_line.HasSwitch(switches::kSyncTrySsltcpFirstForXmpp);
39 DVLOG_IF(1, notifier_options.try_ssltcp_first)
40 << "Trying SSL/TCP port before XMPP port for notifications.";
41
42 notifier_options.invalidate_xmpp_login =
43 command_line.HasSwitch(switches::kSyncInvalidateXmppLogin);
44 DVLOG_IF(1, notifier_options.invalidate_xmpp_login)
45 << "Invalidating sync XMPP login.";
46
47 notifier_options.allow_insecure_connection =
48 command_line.HasSwitch(switches::kSyncAllowInsecureXmppConnection);
49 DVLOG_IF(1, notifier_options.allow_insecure_connection)
50 << "Allowing insecure XMPP connections.";
51
52 if (command_line.HasSwitch(switches::kSyncNotificationMethod)) {
53 const std::string notification_method_str(
54 command_line.GetSwitchValueASCII(switches::kSyncNotificationMethod));
55 notifier_options.notification_method =
56 notifier::StringToNotificationMethod(notification_method_str);
57 }
58
59 return notifier_options;
60 }
61
62 std::string GenerateInvalidatorClientId() {
63 // Generate a GUID with 128 bits worth of base64-encoded randomness.
64 // This format is similar to that of sync's cache_guid.
65 const int kGuidBytes = 128 / 8;
66 std::string guid;
67 base::Base64Encode(base::RandBytesAsString(kGuidBytes), &guid);
68 return guid;
69 }
70
71 } // namespace
72
73 P2PInvalidationService::P2PInvalidationService() {
74 }
75
76 P2PInvalidationService::~P2PInvalidationService() {
77 }
78
79 void P2PInvalidationService::Init(Profile* profile) {
80 notifier::NotifierOptions notifier_options =
81 ParseNotifierOptions(*CommandLine::ForCurrentProcess(),
82 profile->GetRequestContext());
83 invalidator_id_ = GenerateInvalidatorClientId();
84 invalidator_.reset(new syncer::P2PInvalidator(
85 notifier::PushClient::CreateDefault(notifier_options),
86 invalidator_id_,
87 syncer::NOTIFY_ALL));
88 }
89
90 void P2PInvalidationService::UpdateCredentials(const std::string& username,
91 const std::string& password) {
92 invalidator_->UpdateCredentials(username, password);
93 }
94
95 void P2PInvalidationService::Shutdown() {
96 invalidator_.reset();
97 }
98
99 void P2PInvalidationService::RegisterInvalidationHandler(
100 syncer::InvalidationHandler* handler) {
101 invalidator_->RegisterHandler(handler);
102 }
103
104 void P2PInvalidationService::UpdateRegisteredInvalidationIds(
105 syncer::InvalidationHandler* handler,
106 const syncer::ObjectIdSet& ids) {
107 invalidator_->UpdateRegisteredIds(handler, ids);
108 }
109
110 void P2PInvalidationService::UnregisterInvalidationHandler(
111 syncer::InvalidationHandler* handler) {
112 invalidator_->UnregisterHandler(handler);
113 }
114
115 void P2PInvalidationService::AcknowledgeInvalidation(
116 const invalidation::ObjectId& id,
117 const syncer::AckHandle& ack_handle) {
118 invalidator_->Acknowledge(id, ack_handle);
119 }
120
121 void P2PInvalidationService::SendInvalidation(
122 const syncer::ObjectIdInvalidationMap& invalidation_map) {
123 invalidator_->SendInvalidation(invalidation_map);
124 }
125
126 syncer::InvalidatorState P2PInvalidationService::GetInvalidatorState() const {
127 return invalidator_->GetInvalidatorState();
128 }
129
130 std::string P2PInvalidationService::GetInvalidatorClientId() const {
131 return invalidator_id_;
132 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698