| 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 "sync/notifier/invalidation_notifier.h" | 5 #include "sync/notifier/invalidation_notifier.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/message_loop_proxy.h" | 8 #include "base/message_loop_proxy.h" |
| 9 #include "base/metrics/histogram.h" |
| 9 #include "jingle/notifier/listener/push_client.h" | 10 #include "jingle/notifier/listener/push_client.h" |
| 10 #include "net/url_request/url_request_context.h" | 11 #include "net/url_request/url_request_context.h" |
| 11 #include "sync/notifier/sync_notifier_observer.h" | 12 #include "sync/notifier/sync_notifier_observer.h" |
| 12 #include "sync/syncable/model_type_payload_map.h" | 13 #include "sync/syncable/model_type_payload_map.h" |
| 13 #include "talk/xmpp/jid.h" | 14 #include "talk/xmpp/jid.h" |
| 14 #include "talk/xmpp/xmppclientsettings.h" | 15 #include "talk/xmpp/xmppclientsettings.h" |
| 15 | 16 |
| 16 namespace sync_notifier { | 17 namespace sync_notifier { |
| 17 | 18 |
| 18 InvalidationNotifier::InvalidationNotifier( | 19 InvalidationNotifier::InvalidationNotifier( |
| 19 scoped_ptr<notifier::PushClient> push_client, | 20 scoped_ptr<notifier::PushClient> push_client, |
| 20 const InvalidationVersionMap& initial_max_invalidation_versions, | 21 const InvalidationVersionMap& initial_max_invalidation_versions, |
| 22 const std::string& initial_invalidation_state, |
| 21 const browser_sync::WeakHandle<InvalidationStateTracker>& | 23 const browser_sync::WeakHandle<InvalidationStateTracker>& |
| 22 invalidation_state_tracker, | 24 invalidation_state_tracker, |
| 23 const std::string& client_info) | 25 const std::string& client_info) |
| 24 : state_(STOPPED), | 26 : state_(STOPPED), |
| 25 initial_max_invalidation_versions_(initial_max_invalidation_versions), | 27 initial_max_invalidation_versions_(initial_max_invalidation_versions), |
| 26 invalidation_state_tracker_(invalidation_state_tracker), | 28 invalidation_state_tracker_(invalidation_state_tracker), |
| 27 client_info_(client_info), | 29 client_info_(client_info), |
| 30 invalidation_state_(initial_invalidation_state), |
| 28 invalidation_client_(push_client.Pass()) { | 31 invalidation_client_(push_client.Pass()) { |
| 29 } | 32 } |
| 30 | 33 |
| 31 InvalidationNotifier::~InvalidationNotifier() { | 34 InvalidationNotifier::~InvalidationNotifier() { |
| 32 DCHECK(non_thread_safe_.CalledOnValidThread()); | 35 DCHECK(non_thread_safe_.CalledOnValidThread()); |
| 33 } | 36 } |
| 34 | 37 |
| 35 void InvalidationNotifier::AddObserver(SyncNotifierObserver* observer) { | 38 void InvalidationNotifier::AddObserver(SyncNotifierObserver* observer) { |
| 36 DCHECK(non_thread_safe_.CalledOnValidThread()); | 39 DCHECK(non_thread_safe_.CalledOnValidThread()); |
| 37 observers_.AddObserver(observer); | 40 observers_.AddObserver(observer); |
| 38 } | 41 } |
| 39 | 42 |
| 40 void InvalidationNotifier::RemoveObserver(SyncNotifierObserver* observer) { | 43 void InvalidationNotifier::RemoveObserver(SyncNotifierObserver* observer) { |
| 41 DCHECK(non_thread_safe_.CalledOnValidThread()); | 44 DCHECK(non_thread_safe_.CalledOnValidThread()); |
| 42 observers_.RemoveObserver(observer); | 45 observers_.RemoveObserver(observer); |
| 43 } | 46 } |
| 44 | 47 |
| 45 void InvalidationNotifier::SetUniqueId(const std::string& unique_id) { | 48 void InvalidationNotifier::SetUniqueId(const std::string& unique_id) { |
| 46 DCHECK(non_thread_safe_.CalledOnValidThread()); | 49 DCHECK(non_thread_safe_.CalledOnValidThread()); |
| 47 invalidation_client_id_ = unique_id; | 50 invalidation_client_id_ = unique_id; |
| 48 DVLOG(1) << "Setting unique ID to " << unique_id; | 51 DVLOG(1) << "Setting unique ID to " << unique_id; |
| 49 CHECK(!invalidation_client_id_.empty()); | 52 CHECK(!invalidation_client_id_.empty()); |
| 50 } | 53 } |
| 51 | 54 |
| 52 void InvalidationNotifier::SetState(const std::string& state) { | 55 void InvalidationNotifier::SetStateDeprecated(const std::string& state) { |
| 53 DCHECK(non_thread_safe_.CalledOnValidThread()); | 56 DCHECK(non_thread_safe_.CalledOnValidThread()); |
| 54 invalidation_state_ = state; | 57 DCHECK_LT(state_, STARTED); |
| 55 DVLOG(1) << "Setting new state"; | 58 if (invalidation_state_.empty()) { |
| 59 // Migrate state from sync to invalidation state tracker (bug |
| 60 // 124140). We've just been handed state from the syncable::Directory, and |
| 61 // the initial invalidation state was empty, implying we've never written |
| 62 // to the new store. Do this here to ensure we always migrate (even if |
| 63 // we fail to establish an initial connection or receive an initial |
| 64 // invalidation) so that we can make the old code obsolete as soon as |
| 65 // possible. |
| 66 invalidation_state_ = state; |
| 67 invalidation_state_tracker_.Call( |
| 68 FROM_HERE, &InvalidationStateTracker::SetInvalidationState, state); |
| 69 UMA_HISTOGRAM_BOOLEAN("InvalidationNotifier.UsefulSetState", true); |
| 70 } else { |
| 71 UMA_HISTOGRAM_BOOLEAN("InvalidationNotifier.UsefulSetState", false); |
| 72 } |
| 56 } | 73 } |
| 57 | 74 |
| 58 void InvalidationNotifier::UpdateCredentials( | 75 void InvalidationNotifier::UpdateCredentials( |
| 59 const std::string& email, const std::string& token) { | 76 const std::string& email, const std::string& token) { |
| 60 if (state_ == STOPPED) { | 77 if (state_ == STOPPED) { |
| 61 invalidation_client_.Start( | 78 invalidation_client_.Start( |
| 62 invalidation_client_id_, client_info_, invalidation_state_, | 79 invalidation_client_id_, client_info_, invalidation_state_, |
| 63 initial_max_invalidation_versions_, | 80 initial_max_invalidation_versions_, |
| 64 invalidation_state_tracker_, | 81 invalidation_state_tracker_, |
| 65 this, this); | 82 this); |
| 66 invalidation_state_.clear(); | 83 invalidation_state_.clear(); |
| 67 state_ = STARTED; | 84 state_ = STARTED; |
| 68 } | 85 } |
| 69 invalidation_client_.UpdateCredentials(email, token); | 86 invalidation_client_.UpdateCredentials(email, token); |
| 70 } | 87 } |
| 71 | 88 |
| 72 void InvalidationNotifier::UpdateEnabledTypes( | 89 void InvalidationNotifier::UpdateEnabledTypes( |
| 73 syncable::ModelTypeSet enabled_types) { | 90 syncable::ModelTypeSet enabled_types) { |
| 74 DCHECK(non_thread_safe_.CalledOnValidThread()); | 91 DCHECK(non_thread_safe_.CalledOnValidThread()); |
| 75 CHECK(!invalidation_client_id_.empty()); | 92 CHECK(!invalidation_client_id_.empty()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 88 FOR_EACH_OBSERVER(SyncNotifierObserver, observers_, | 105 FOR_EACH_OBSERVER(SyncNotifierObserver, observers_, |
| 89 OnIncomingNotification(type_payloads, | 106 OnIncomingNotification(type_payloads, |
| 90 sync_notifier::REMOTE_NOTIFICATION)); | 107 sync_notifier::REMOTE_NOTIFICATION)); |
| 91 } | 108 } |
| 92 | 109 |
| 93 void InvalidationNotifier::OnSessionStatusChanged(bool has_session) { | 110 void InvalidationNotifier::OnSessionStatusChanged(bool has_session) { |
| 94 FOR_EACH_OBSERVER(SyncNotifierObserver, observers_, | 111 FOR_EACH_OBSERVER(SyncNotifierObserver, observers_, |
| 95 OnNotificationStateChange(has_session)); | 112 OnNotificationStateChange(has_session)); |
| 96 } | 113 } |
| 97 | 114 |
| 98 void InvalidationNotifier::WriteState(const std::string& state) { | |
| 99 DCHECK(non_thread_safe_.CalledOnValidThread()); | |
| 100 DVLOG(1) << "WriteState"; | |
| 101 FOR_EACH_OBSERVER(SyncNotifierObserver, observers_, StoreState(state)); | |
| 102 } | |
| 103 | |
| 104 } // namespace sync_notifier | 115 } // namespace sync_notifier |
| OLD | NEW |