Skip to content

Commit

Permalink
[invalidations] Added a total invalidations received counter.
Browse files Browse the repository at this point in the history
This patch adds to about:invalidations a counter per objectID of all
the invalidations received since establising the server connection.
This was made to resemble the Notifications tab removed from
about:sync-internals.

BUG=263863

Review URL: https://codereview.chromium.org/216423009

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@260591 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
mferreria@chromium.org committed Mar 31, 2014
1 parent d655a1c commit 9364154
Show file tree
Hide file tree
Showing 10 changed files with 137 additions and 40 deletions.
18 changes: 17 additions & 1 deletion chrome/browser/invalidation/invalidation_logger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,17 @@ void InvalidationLogger::OnUpdateIds(
void InvalidationLogger::EmitUpdatedIds() {
for (std::map<std::string, syncer::ObjectIdSet>::const_iterator it =
latest_ids_.begin(); it != latest_ids_.end(); ++it) {
const syncer::ObjectIdSet& object_ids_for_handler = it->second;
syncer::ObjectIdCountMap per_object_invalidation_count;
for (syncer::ObjectIdSet::const_iterator oid_it =
object_ids_for_handler.begin();
oid_it != object_ids_for_handler.end();
++oid_it) {
per_object_invalidation_count[*oid_it] = invalidation_count_[*oid_it];
}
FOR_EACH_OBSERVER(InvalidationLoggerObserver,
observer_list_,
OnUpdateIds(it->first, it->second));
OnUpdateIds(it->first, per_object_invalidation_count));
}
}

Expand All @@ -74,6 +82,14 @@ void InvalidationLogger::OnDebugMessage(const base::DictionaryValue& details) {

void InvalidationLogger::OnInvalidation(
const syncer::ObjectIdInvalidationMap& details) {
std::vector<syncer::Invalidation> internal_invalidations;
details.GetAllInvalidations(&internal_invalidations);
for (std::vector<syncer::Invalidation>::const_iterator it =
internal_invalidations.begin();
it != internal_invalidations.end();
++it) {
invalidation_count_[it->object_id()]++;
}
FOR_EACH_OBSERVER(
InvalidationLoggerObserver, observer_list_, OnInvalidation(details));
}
Expand Down
3 changes: 3 additions & 0 deletions chrome/browser/invalidation/invalidation_logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ class InvalidationLogger {
// and its owner.
std::map<std::string, syncer::ObjectIdSet> latest_ids_;

// The map that counts how many invalidations per objectId there has been.
syncer::ObjectIdCountMap invalidation_count_;

// The name of all invalidatorHandler registered (note that this is not
// necessarily the same as the keys of latest_ids_, because they might
// have not registered any object id).
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/invalidation/invalidation_logger_observer.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class InvalidationLoggerObserver {
const std::multiset<std::string>& registered_handlers) = 0;
virtual void OnStateChange(const syncer::InvalidatorState& new_state) = 0;
virtual void OnUpdateIds(const std::string& handler_name,
const syncer::ObjectIdSet& details) = 0;
const syncer::ObjectIdCountMap& details) = 0;
virtual void OnDebugMessage(const base::DictionaryValue& details) = 0;
virtual void OnInvalidation(
const syncer::ObjectIdInvalidationMap& details) = 0;
Expand Down
107 changes: 87 additions & 20 deletions chrome/browser/invalidation/invalidation_logger_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class InvalidationLoggerObserverTest : public InvalidationLoggerObserver {
debug_message_received = false;
invalidation_received = false;
detailed_status_received = false;
update_id_replicated = std::map<std::string, syncer::ObjectIdSet>();
update_id_replicated = std::map<std::string, syncer::ObjectIdCountMap>();
registered_handlers = std::multiset<std::string>();
}

Expand All @@ -36,7 +36,7 @@ class InvalidationLoggerObserverTest : public InvalidationLoggerObserver {
}

virtual void OnUpdateIds(const std::string& handler,
const syncer::ObjectIdSet& details) OVERRIDE {
const syncer::ObjectIdCountMap& details) OVERRIDE {
update_id_received = true;
update_id_replicated[handler] = details;
}
Expand All @@ -60,7 +60,7 @@ class InvalidationLoggerObserverTest : public InvalidationLoggerObserver {
bool debug_message_received;
bool invalidation_received;
bool detailed_status_received;
std::map<std::string, syncer::ObjectIdSet> update_id_replicated;
std::map<std::string, syncer::ObjectIdCountMap> update_id_replicated;
std::multiset<std::string> registered_handlers;
};

Expand Down Expand Up @@ -152,38 +152,106 @@ TEST(InvalidationLoggerTest, TestEmitContent) {
log.UnregisterObserver(&observer_test);
}

// Test that the updateId notification actually sends
// what was sent to the Observer.
// Test that the updateId notification actually sends the same ObjectId that
// was sent to the Observer.
// The ObserverTest rebuilds the map that was sent in pieces by the logger.
TEST(InvalidationLoggerTest, TestUpdateIdsMap) {
InvalidationLogger log;
InvalidationLoggerObserverTest observer_test;
std::map<std::string, syncer::ObjectIdSet> test_map;
std::map<std::string, syncer::ObjectIdSet> send_test_map;
std::map<std::string, syncer::ObjectIdCountMap> expected_received_map;
log.RegisterObserver(&observer_test);

syncer::ObjectIdSet sync_set_A;
sync_set_A.insert(ObjectId(1000, "DataType1"));
sync_set_A.insert(ObjectId(1000, "DataType2"));
syncer::ObjectIdCountMap counted_sync_set_A;

ObjectId o1(1000, "DataType1");
sync_set_A.insert(o1);
counted_sync_set_A[o1] = 0;

ObjectId o2(1000, "DataType2");
sync_set_A.insert(o2);
counted_sync_set_A[o2] = 0;

syncer::ObjectIdSet sync_set_B;
sync_set_B.insert(ObjectId(1020, "DataTypeA"));
test_map["TestA"] = sync_set_A;
test_map["TestB"] = sync_set_B;
syncer::ObjectIdCountMap counted_sync_set_B;

log.OnUpdateIds(test_map);
EXPECT_EQ(test_map, observer_test.update_id_replicated);
ObjectId o3(1020, "DataTypeA");
sync_set_B.insert(o3);
counted_sync_set_B[o3] = 0;

send_test_map["TestA"] = sync_set_A;
send_test_map["TestB"] = sync_set_B;
expected_received_map["TestA"] = counted_sync_set_A;
expected_received_map["TestB"] = counted_sync_set_B;

// Send the objects ids registered for the two different handler name.
log.OnUpdateIds(send_test_map);
EXPECT_EQ(expected_received_map, observer_test.update_id_replicated);

syncer::ObjectIdSet sync_set_B2;
sync_set_B2.insert(ObjectId(1020, "DataTypeF"));
sync_set_B2.insert(ObjectId(1020, "DataTypeG"));
test_map["TestB"] = sync_set_B2;
syncer::ObjectIdCountMap counted_sync_set_B2;

log.OnUpdateIds(test_map);
EXPECT_EQ(test_map, observer_test.update_id_replicated);
ObjectId o4(1020, "DataTypeF");
sync_set_B2.insert(o4);
counted_sync_set_B2[o4] = 0;

ObjectId o5(1020, "DataTypeG");
sync_set_B2.insert(o5);
counted_sync_set_B2[o5] = 0;

send_test_map["TestB"] = sync_set_B2;
expected_received_map["TestB"] = counted_sync_set_B2;

// Test now that if we replace the registered datatypes for TestB, the
// original don't show up again.
log.OnUpdateIds(send_test_map);
EXPECT_EQ(expected_received_map, observer_test.update_id_replicated);

// The emit content should return the same map too.
observer_test.ResetStates();
log.EmitContent();
EXPECT_EQ(test_map, observer_test.update_id_replicated);
EXPECT_EQ(expected_received_map, observer_test.update_id_replicated);
log.UnregisterObserver(&observer_test);
}

// Test that the invalidation notification changes the total count
// of invalidations received for that datatype.
TEST(InvalidationLoggerTest, TestInvalidtionsTotalCount) {
InvalidationLogger log;
InvalidationLoggerObserverTest observer_test;
log.RegisterObserver(&observer_test);

std::map<std::string, syncer::ObjectIdSet> send_test_map;
std::map<std::string, syncer::ObjectIdCountMap> expected_received_map;
syncer::ObjectIdSet sync_set;
syncer::ObjectIdCountMap counted_sync_set;

ObjectId o1(1020, "DataTypeA");
sync_set.insert(o1);
counted_sync_set[o1] = 1;

// Generate invalidation for datatype A only.
syncer::ObjectIdInvalidationMap fake_invalidations =
syncer::ObjectIdInvalidationMap::InvalidateAll(sync_set);

ObjectId o2(1040, "DataTypeB");
sync_set.insert(o2);
counted_sync_set[o2] = 0;

// Registed the two objectIds and send an invalidation only for the
// Datatype A.
send_test_map["Test"] = sync_set;
log.OnUpdateIds(send_test_map);
log.OnInvalidation(fake_invalidations);

expected_received_map["Test"] = counted_sync_set;

// Reset the state of the observer to receive the ObjectIds with the
// count of invalidations received (1 and 0).
observer_test.ResetStates();
log.EmitContent();
EXPECT_EQ(expected_received_map, observer_test.update_id_replicated);

log.UnregisterObserver(&observer_test);
}
Expand All @@ -192,7 +260,6 @@ TEST(InvalidationLoggerTest, TestUpdateIdsMap) {
TEST(InvalidationLoggerTest, TestRegisteredHandlers) {
InvalidationLogger log;
InvalidationLoggerObserverTest observer_test;
std::map<std::string, syncer::ObjectIdSet> test_map;
log.RegisterObserver(&observer_test);

log.OnRegistration(std::string("FakeHandler1"));
Expand Down
8 changes: 5 additions & 3 deletions chrome/browser/resources/about_invalidations.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ <h1>Invalidations Debug Information</h1>
<th>Registrar</th>
<th>Source</th>
<th>Name</th>
<th>Count</th>
<th>Total Count</th>
<th>Session Count</th>
<th>Version</th>
<th>Time</th>
<th>Last Payload</th>
Expand All @@ -41,10 +42,11 @@ <h1>Invalidations Debug Information</h1>
<td jscontent="registrar" width=5%></td>
<td jscontent="source" width=5%></td>
<td jscontent="name" width=20%></td>
<td jscontent="count" width=5%></td>
<td jscontent="totalCount" width=5%></td>
<td jscontent="sessionCount" width=5%></td>
<td jscontent="version" width=10%></td>
<td jscontent="time" width=20%></td>
<td jscontent="payload" width=35%></td>
<td jscontent="payload" width=30%></td>
</tr>
</tbody>
</table>
Expand Down
7 changes: 5 additions & 2 deletions chrome/browser/resources/about_invalidations.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ cr.define('chrome.invalidations', function() {
var registrar = oId.registrar;
var name = oId.objectId.name;
var source = oId.objectId.source;
var totalCount = oId.objectId.totalCount || 0;
var key = source + '-' + name;
var time = new Date();
var version = oId.isUnknownVersion ? '?' :
Expand All @@ -112,7 +113,8 @@ cr.define('chrome.invalidations', function() {
tableObjects[key] = {
name: name,
source: source,
count: 0,
totalCount: totalCount,
sessionCount: 0,
registrar: registrar,
time: '',
version: '',
Expand All @@ -124,7 +126,8 @@ cr.define('chrome.invalidations', function() {
// greyed out.
tableObjects[key].type = 'content';
if (isInvalidation) {
tableObjects[key].count = tableObjects[key].count + 1;
tableObjects[key].totalCount = tableObjects[key].totalCount + 1;
tableObjects[key].sessionCount = tableObjects[key].sessionCount + 1;
tableObjects[key].time = time.toTimeString();
tableObjects[key].version = version;
tableObjects[key].payload = payload;
Expand Down
12 changes: 7 additions & 5 deletions chrome/browser/ui/webui/invalidations_message_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,15 @@ void InvalidationsMessageHandler::OnStateChange(

void InvalidationsMessageHandler::OnUpdateIds(
const std::string& handler_name,
const syncer::ObjectIdSet& ids_set) {
const syncer::ObjectIdCountMap& ids) {
base::ListValue list_of_objects;
for (syncer::ObjectIdSet::const_iterator it = ids_set.begin();
it != ids_set.end(); ++it) {
for (syncer::ObjectIdCountMap::const_iterator it = ids.begin();
it != ids.end();
++it) {
scoped_ptr<base::DictionaryValue> dic(new base::DictionaryValue());
dic->SetString("name", it->name());
dic->SetInteger("source", it->source());
dic->SetString("name", (it->first).name());
dic->SetInteger("source", (it->first).source());
dic->SetInteger("totalCount", it->second);
list_of_objects.Append(dic.release());
}
web_ui()->CallJavascriptFunction("chrome.invalidations.updateIds",
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/ui/webui/invalidations_message_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class InvalidationsMessageHandler
virtual void OnStateChange(const syncer::InvalidatorState& new_state)
OVERRIDE;
virtual void OnUpdateIds(const std::string& handler_name,
const syncer::ObjectIdSet& ids_set) OVERRIDE;
const syncer::ObjectIdCountMap& ids_set) OVERRIDE;
virtual void OnDebugMessage(const base::DictionaryValue& details) OVERRIDE;
virtual void OnInvalidation(
const syncer::ObjectIdInvalidationMap& new_invalidations) OVERRIDE;
Expand Down
14 changes: 7 additions & 7 deletions chrome/test/data/webui/about_invalidations_browsertest.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ TEST_F('InvalidationsWebUITest', 'testRegisteringNewInvalidation', function() {
var invalidation = [{
isUnknownVersion: 'true',
objectId: {name: 'EXTENSIONS', source: 1004}
}];
}];
invalidationsLog.value = '';
chrome.invalidations.logInvalidations(invalidation);
var isContained =
Expand Down Expand Up @@ -63,15 +63,15 @@ TEST_F('InvalidationsWebUITest', 'testChangingInvalidationsState', function() {
// Test that objects ids appear on the table.
TEST_F('InvalidationsWebUITest', 'testRegisteringNewIds', function() {
var newDataType = [
{ name: 'EXTENSIONS', source: 1004},
{ name: 'FAVICON_IMAGE', source: 1004}
];
var pattern1 = ['Fake', '1004', 'EXTENSIONS', '0', '', '', ''];
var pattern2 = ['Fake', '1004', 'FAVICON_IMAGE', '0', '', '', ''];
{ name: 'EXTENSIONS', source: 1004, totalCount: 0},
{ name: 'FAVICON_IMAGE', source: 1004, totalCount: 0}
];
var pattern1 = ['Fake', '1004', 'EXTENSIONS', '0', '0', '', '', ''];
var pattern2 = ['Fake', '1004', 'FAVICON_IMAGE', '0', '0', '', '', ''];
// Register two objects ID with 'Fake' registrar
chrome.invalidations.updateIds('Fake', newDataType);
// Disable the Extensions ObjectId by only sending FAVICON_IMAGE
newDataType = [{ name: 'FAVICON_IMAGE', source: 1004}];
newDataType = [{name: 'FAVICON_IMAGE', source: 1004}];
chrome.invalidations.updateIds('Fake', newDataType);

// Test that the two patterns are contained in the table.
Expand Down
4 changes: 4 additions & 0 deletions sync/notifier/invalidation_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#define SYNC_NOTIFIER_INVALIDATION_UTIL_H_

#include <iosfwd>
#include <map>
#include <set>
#include <string>

Expand Down Expand Up @@ -46,6 +47,9 @@ struct InvalidationVersionLessThan {

typedef std::set<invalidation::ObjectId, ObjectIdLessThan> ObjectIdSet;

typedef std::map<invalidation::ObjectId, int, ObjectIdLessThan>
ObjectIdCountMap;

SYNC_EXPORT bool RealModelTypeToObjectId(ModelType model_type,
invalidation::ObjectId* object_id);

Expand Down

0 comments on commit 9364154

Please sign in to comment.