| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/invalidation/invalidation_logger.h" | 5 #include "chrome/browser/invalidation/invalidation_logger.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "chrome/browser/invalidation/invalidation_logger_observer.h" | 9 #include "chrome/browser/invalidation/invalidation_logger_observer.h" |
| 10 | 10 #include "sync/notifier/invalidation_handler.h" |
| 11 namespace syncer { | |
| 12 class ObjectIdInvalidationMap; | |
| 13 } | |
| 14 | 11 |
| 15 namespace invalidation { | 12 namespace invalidation { |
| 16 class InvalidationLoggerObserver; | 13 class InvalidationLoggerObserver; |
| 17 | 14 |
| 18 InvalidationLogger::InvalidationLogger() | 15 InvalidationLogger::InvalidationLogger() |
| 19 : last_invalidator_state_(syncer::TRANSIENT_INVALIDATION_ERROR) {} | 16 : last_invalidator_state_(syncer::TRANSIENT_INVALIDATION_ERROR) {} |
| 20 | 17 |
| 21 InvalidationLogger::~InvalidationLogger() {} | 18 InvalidationLogger::~InvalidationLogger() {} |
| 22 | 19 |
| 23 void InvalidationLogger::OnRegistration(const base::DictionaryValue& details) { | 20 void InvalidationLogger::OnRegistration(const base::DictionaryValue& details) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 36 last_invalidator_state_ = newState; | 33 last_invalidator_state_ = newState; |
| 37 EmitState(); | 34 EmitState(); |
| 38 } | 35 } |
| 39 | 36 |
| 40 void InvalidationLogger::EmitState() { | 37 void InvalidationLogger::EmitState() { |
| 41 FOR_EACH_OBSERVER(InvalidationLoggerObserver, | 38 FOR_EACH_OBSERVER(InvalidationLoggerObserver, |
| 42 observer_list_, | 39 observer_list_, |
| 43 OnStateChange(last_invalidator_state_)); | 40 OnStateChange(last_invalidator_state_)); |
| 44 } | 41 } |
| 45 | 42 |
| 46 void InvalidationLogger::OnUpdateIds(const base::DictionaryValue& details) { | 43 void InvalidationLogger::OnUpdateIds( |
| 47 FOR_EACH_OBSERVER( | 44 std::map<std::string, syncer::ObjectIdSet> updatedIds) { |
| 48 InvalidationLoggerObserver, observer_list_, OnUpdateIds(details)); | 45 for (std::map<std::string, syncer::ObjectIdSet>::iterator it = |
| 46 updatedIds.begin(); |
| 47 it != updatedIds.end(); |
| 48 ++it) { |
| 49 latest_ids_[it->first] = syncer::ObjectIdSet(it->second); |
| 50 } |
| 51 EmitUpdatedIds(); |
| 52 } |
| 53 |
| 54 void InvalidationLogger::EmitUpdatedIds() { |
| 55 for (std::map<std::string, syncer::ObjectIdSet>::iterator it = |
| 56 latest_ids_.begin(); |
| 57 it != latest_ids_.end(); |
| 58 ++it) { |
| 59 FOR_EACH_OBSERVER(InvalidationLoggerObserver, |
| 60 observer_list_, |
| 61 OnUpdateIds(it->first, it->second)); |
| 62 } |
| 49 } | 63 } |
| 50 | 64 |
| 51 void InvalidationLogger::OnDebugMessage(const base::DictionaryValue& details) { | 65 void InvalidationLogger::OnDebugMessage(const base::DictionaryValue& details) { |
| 52 FOR_EACH_OBSERVER( | 66 FOR_EACH_OBSERVER( |
| 53 InvalidationLoggerObserver, observer_list_, OnDebugMessage(details)); | 67 InvalidationLoggerObserver, observer_list_, OnDebugMessage(details)); |
| 54 } | 68 } |
| 55 | 69 |
| 56 void InvalidationLogger::OnInvalidation( | 70 void InvalidationLogger::OnInvalidation( |
| 57 const syncer::ObjectIdInvalidationMap& details) { | 71 const syncer::ObjectIdInvalidationMap& details) { |
| 58 FOR_EACH_OBSERVER( | 72 FOR_EACH_OBSERVER( |
| 59 InvalidationLoggerObserver, observer_list_, OnInvalidation(details)); | 73 InvalidationLoggerObserver, observer_list_, OnInvalidation(details)); |
| 60 } | 74 } |
| 61 | 75 |
| 62 void InvalidationLogger::EmitContent() { | 76 void InvalidationLogger::EmitContent() { |
| 63 // Here we add content to send to the observers not via real time push | |
| 64 // but on explicit request. | |
| 65 EmitState(); | 77 EmitState(); |
| 78 EmitUpdatedIds(); |
| 66 } | 79 } |
| 67 | 80 |
| 68 // Obtain a target object to call whenever we have | 81 void InvalidationLogger::RegisterObserver( |
| 69 // debug messages to display | |
| 70 void InvalidationLogger::RegisterForDebug( | |
| 71 InvalidationLoggerObserver* debug_observer) { | 82 InvalidationLoggerObserver* debug_observer) { |
| 72 observer_list_.AddObserver(debug_observer); | 83 observer_list_.AddObserver(debug_observer); |
| 73 } | 84 } |
| 74 | 85 |
| 75 // Removes the target object to call whenever we have | 86 void InvalidationLogger::UnregisterObserver( |
| 76 // debug messages to display | |
| 77 void InvalidationLogger::UnregisterForDebug( | |
| 78 InvalidationLoggerObserver* debug_observer) { | 87 InvalidationLoggerObserver* debug_observer) { |
| 79 observer_list_.RemoveObserver(debug_observer); | 88 observer_list_.RemoveObserver(debug_observer); |
| 80 } | 89 } |
| 81 } // namespace invalidation | 90 } // namespace invalidation |
| OLD | NEW |