| 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> updated_ids) { |
| 48 InvalidationLoggerObserver, observer_list_, OnUpdateIds(details)); | 45 for (std::map<std::string, syncer::ObjectIdSet>::iterator it = |
| 46 updated_ids.begin(); it != updated_ids.end(); ++it) { |
| 47 latest_ids_[it->first] = syncer::ObjectIdSet(it->second); |
| 48 } |
| 49 EmitUpdatedIds(); |
| 50 } |
| 51 |
| 52 void InvalidationLogger::EmitUpdatedIds() { |
| 53 for (std::map<std::string, syncer::ObjectIdSet>::iterator it = |
| 54 latest_ids_.begin(); it != latest_ids_.end(); ++it) { |
| 55 FOR_EACH_OBSERVER(InvalidationLoggerObserver, |
| 56 observer_list_, |
| 57 OnUpdateIds(it->first, it->second)); |
| 58 } |
| 49 } | 59 } |
| 50 | 60 |
| 51 void InvalidationLogger::OnDebugMessage(const base::DictionaryValue& details) { | 61 void InvalidationLogger::OnDebugMessage(const base::DictionaryValue& details) { |
| 52 FOR_EACH_OBSERVER( | 62 FOR_EACH_OBSERVER( |
| 53 InvalidationLoggerObserver, observer_list_, OnDebugMessage(details)); | 63 InvalidationLoggerObserver, observer_list_, OnDebugMessage(details)); |
| 54 } | 64 } |
| 55 | 65 |
| 56 void InvalidationLogger::OnInvalidation( | 66 void InvalidationLogger::OnInvalidation( |
| 57 const syncer::ObjectIdInvalidationMap& details) { | 67 const syncer::ObjectIdInvalidationMap& details) { |
| 58 FOR_EACH_OBSERVER( | 68 FOR_EACH_OBSERVER( |
| 59 InvalidationLoggerObserver, observer_list_, OnInvalidation(details)); | 69 InvalidationLoggerObserver, observer_list_, OnInvalidation(details)); |
| 60 } | 70 } |
| 61 | 71 |
| 62 void InvalidationLogger::EmitContent() { | 72 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(); | 73 EmitState(); |
| 74 EmitUpdatedIds(); |
| 66 } | 75 } |
| 67 | 76 |
| 68 // Obtain a target object to call whenever we have | 77 void InvalidationLogger::RegisterObserver( |
| 69 // debug messages to display | |
| 70 void InvalidationLogger::RegisterForDebug( | |
| 71 InvalidationLoggerObserver* debug_observer) { | 78 InvalidationLoggerObserver* debug_observer) { |
| 72 observer_list_.AddObserver(debug_observer); | 79 observer_list_.AddObserver(debug_observer); |
| 73 } | 80 } |
| 74 | 81 |
| 75 // Removes the target object to call whenever we have | 82 void InvalidationLogger::UnregisterObserver( |
| 76 // debug messages to display | |
| 77 void InvalidationLogger::UnregisterForDebug( | |
| 78 InvalidationLoggerObserver* debug_observer) { | 83 InvalidationLoggerObserver* debug_observer) { |
| 79 observer_list_.RemoveObserver(debug_observer); | 84 observer_list_.RemoveObserver(debug_observer); |
| 80 } | 85 } |
| 81 } // namespace invalidation | 86 } // namespace invalidation |
| OLD | NEW |