OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/sync/notifier/server_notifier_thread.h" | 5 #include "chrome/browser/sync/notifier/server_notifier_thread.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "chrome/browser/sync/notifier/chrome_invalidation_client.h" | 11 #include "chrome/browser/sync/notifier/chrome_invalidation_client.h" |
12 #include "jingle/notifier/listener/notification_defines.h" | 12 #include "jingle/notifier/listener/notification_defines.h" |
13 | 13 |
14 namespace sync_notifier { | 14 namespace sync_notifier { |
15 | 15 |
16 ServerNotifierThread::ServerNotifierThread(bool use_chrome_async_socket) | 16 ServerNotifierThread::ServerNotifierThread(bool use_chrome_async_socket) |
17 : notifier::MediatorThreadImpl(use_chrome_async_socket), | 17 : notifier::MediatorThreadImpl(use_chrome_async_socket), |
18 state_(notifier::STATE_CLOSED) {} | 18 state_(notifier::STATE_DISCONNECTED) {} |
19 | 19 |
20 ServerNotifierThread::~ServerNotifierThread() {} | 20 ServerNotifierThread::~ServerNotifierThread() {} |
21 | 21 |
22 void ServerNotifierThread::ListenForUpdates() { | 22 void ServerNotifierThread::ListenForUpdates() { |
23 DCHECK_EQ(MessageLoop::current(), parent_message_loop_); | 23 DCHECK_EQ(MessageLoop::current(), parent_message_loop_); |
24 worker_message_loop()->PostTask( | 24 worker_message_loop()->PostTask( |
25 FROM_HERE, | 25 FROM_HERE, |
26 NewRunnableMethod(this, | 26 NewRunnableMethod(this, |
27 &ServerNotifierThread::StartInvalidationListener)); | 27 &ServerNotifierThread::StartInvalidationListener)); |
28 } | 28 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 FROM_HERE, | 70 FROM_HERE, |
71 NewRunnableMethod( | 71 NewRunnableMethod( |
72 this, | 72 this, |
73 &ServerNotifierThread::SignalIncomingNotification)); | 73 &ServerNotifierThread::SignalIncomingNotification)); |
74 } | 74 } |
75 | 75 |
76 void ServerNotifierThread::OnClientStateChangeMessage( | 76 void ServerNotifierThread::OnClientStateChangeMessage( |
77 notifier::LoginConnectionState state) { | 77 notifier::LoginConnectionState state) { |
78 DCHECK_EQ(MessageLoop::current(), worker_message_loop()); | 78 DCHECK_EQ(MessageLoop::current(), worker_message_loop()); |
79 state_ = state; | 79 state_ = state; |
80 if (state_ != notifier::STATE_OPENED) { | 80 if (state_ != notifier::STATE_CONNECTED) { |
81 // Assume anything but an opened state invalidates xmpp_client(). | |
82 StopInvalidationListener(); | 81 StopInvalidationListener(); |
83 } | 82 } |
84 MediatorThreadImpl::OnClientStateChangeMessage(state); | 83 MediatorThreadImpl::OnClientStateChangeMessage(state); |
85 } | 84 } |
86 | 85 |
87 void ServerNotifierThread::StartInvalidationListener() { | 86 void ServerNotifierThread::StartInvalidationListener() { |
88 DCHECK_EQ(MessageLoop::current(), worker_message_loop()); | 87 DCHECK_EQ(MessageLoop::current(), worker_message_loop()); |
89 if (state_ != notifier::STATE_OPENED) { | 88 if (state_ != notifier::STATE_CONNECTED) { |
90 return; | 89 return; |
91 } | 90 } |
92 buzz::XmppClient* client = xmpp_client(); | 91 buzz::XmppClient* client = xmpp_client(); |
93 if (client == NULL) { | 92 if (client == NULL) { |
94 LOG(DFATAL) << "xmpp_client() unexpectedly NULL"; | 93 LOG(DFATAL) << "xmpp_client() unexpectedly NULL"; |
95 return; | 94 return; |
96 } | 95 } |
97 | 96 |
98 StopInvalidationListener(); | 97 StopInvalidationListener(); |
99 chrome_invalidation_client_.reset(new ChromeInvalidationClient()); | 98 chrome_invalidation_client_.reset(new ChromeInvalidationClient()); |
100 | 99 |
101 // TODO(akalin): Make cache_guid() part of the client ID. If we do | 100 // TODO(akalin): Make cache_guid() part of the client ID. If we do |
102 // so and we somehow propagate it up to the server somehow, we can | 101 // so and we somehow propagate it up to the server somehow, we can |
103 // make it so that we won't receive any notifications that were | 102 // make it so that we won't receive any notifications that were |
104 // generated from our own changes. | 103 // generated from our own changes. |
105 const std::string kClientId = "server_notifier_thread"; | 104 const std::string kClientId = "server_notifier_thread"; |
106 chrome_invalidation_client_->Start(kClientId, this, client); | 105 chrome_invalidation_client_->Start(kClientId, this, client); |
107 } | 106 } |
108 | 107 |
109 void ServerNotifierThread::RegisterTypesAndSignalSubscribed() { | 108 void ServerNotifierThread::RegisterTypesAndSignalSubscribed() { |
110 DCHECK_EQ(MessageLoop::current(), worker_message_loop()); | 109 DCHECK_EQ(MessageLoop::current(), worker_message_loop()); |
111 if (state_ != notifier::STATE_OPENED) { | 110 if (state_ != notifier::STATE_CONNECTED) { |
112 return; | 111 return; |
113 } | 112 } |
114 | 113 |
115 chrome_invalidation_client_->RegisterTypes(); | 114 chrome_invalidation_client_->RegisterTypes(); |
116 parent_message_loop_->PostTask( | 115 parent_message_loop_->PostTask( |
117 FROM_HERE, | 116 FROM_HERE, |
118 NewRunnableMethod( | 117 NewRunnableMethod( |
119 this, | 118 this, |
120 &ServerNotifierThread::SignalSubscribed)); | 119 &ServerNotifierThread::SignalSubscribed)); |
121 } | 120 } |
(...skipping 13 matching lines...) Expand all Loading... |
135 delegate_->OnIncomingNotification(notification_data); | 134 delegate_->OnIncomingNotification(notification_data); |
136 } | 135 } |
137 } | 136 } |
138 | 137 |
139 void ServerNotifierThread::StopInvalidationListener() { | 138 void ServerNotifierThread::StopInvalidationListener() { |
140 DCHECK_EQ(MessageLoop::current(), worker_message_loop()); | 139 DCHECK_EQ(MessageLoop::current(), worker_message_loop()); |
141 chrome_invalidation_client_.reset(); | 140 chrome_invalidation_client_.reset(); |
142 } | 141 } |
143 | 142 |
144 } // namespace sync_notifier | 143 } // namespace sync_notifier |
OLD | NEW |