1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "components/sync/engine_impl/commit_util.h"
6 
7 namespace syncer {
8 
9 namespace commit_util {
10 
AddExtensionsActivityToMessage(ExtensionsActivity * activity,ExtensionsActivity::Records * extensions_activity_buffer,sync_pb::CommitMessage * message)11 void AddExtensionsActivityToMessage(
12     ExtensionsActivity* activity,
13     ExtensionsActivity::Records* extensions_activity_buffer,
14     sync_pb::CommitMessage* message) {
15   // This isn't perfect, since the set of extensions activity may not correlate
16   // exactly with the items being committed.  That's OK as long as we're looking
17   // for a rough estimate of extensions activity, not an precise mapping of
18   // which commits were triggered by which extension.
19   //
20   // We will push this list of extensions activity back into the
21   // ExtensionsActivityMonitor if this commit fails.  That's why we must keep a
22   // copy of these records in the cycle.
23   activity->GetAndClearRecords(extensions_activity_buffer);
24 
25   const ExtensionsActivity::Records& records = *extensions_activity_buffer;
26   for (auto it = records.begin(); it != records.end(); ++it) {
27     sync_pb::ChromiumExtensionsActivity* activity_message =
28         message->add_extensions_activity();
29     activity_message->set_extension_id(it->second.extension_id);
30     activity_message->set_bookmark_writes_since_last_commit(
31         it->second.bookmark_write_count);
32   }
33 }
34 
AddClientConfigParamsToMessage(ModelTypeSet enabled_types,bool cookie_jar_mismatch,bool single_client,sync_pb::CommitMessage * message)35 void AddClientConfigParamsToMessage(ModelTypeSet enabled_types,
36                                     bool cookie_jar_mismatch,
37                                     bool single_client,
38                                     sync_pb::CommitMessage* message) {
39   sync_pb::ClientConfigParams* config_params = message->mutable_config_params();
40   for (ModelType type : enabled_types) {
41     if (ProxyTypes().Has(type))
42       continue;
43     int field_number = GetSpecificsFieldNumberFromModelType(type);
44     config_params->mutable_enabled_type_ids()->Add(field_number);
45   }
46   config_params->set_tabs_datatype_enabled(enabled_types.Has(PROXY_TABS));
47   config_params->set_cookie_jar_mismatch(cookie_jar_mismatch);
48   config_params->set_single_client(single_client);
49 }
50 
51 }  // namespace commit_util
52 
53 }  // namespace syncer
54