OLD | NEW |
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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/sync/engine/download_updates_command.h" | 5 #include "chrome/browser/sync/engine/download_updates_command.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "chrome/browser/sync/engine/syncer.h" | 9 #include "chrome/browser/sync/engine/syncer.h" |
10 #include "chrome/browser/sync/engine/syncer_proto_util.h" | 10 #include "chrome/browser/sync/engine/syncer_proto_util.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 GetUpdatesMessage* get_updates = | 34 GetUpdatesMessage* get_updates = |
35 client_to_server_message.mutable_get_updates(); | 35 client_to_server_message.mutable_get_updates(); |
36 | 36 |
37 ScopedDirLookup dir(session->context()->directory_manager(), | 37 ScopedDirLookup dir(session->context()->directory_manager(), |
38 session->context()->account_name()); | 38 session->context()->account_name()); |
39 if (!dir.good()) { | 39 if (!dir.good()) { |
40 LOG(ERROR) << "Scoped dir lookup failed!"; | 40 LOG(ERROR) << "Scoped dir lookup failed!"; |
41 return; | 41 return; |
42 } | 42 } |
43 | 43 |
44 // Pick some subset of the enabled types where all types in the set | 44 // Request updates for all enabled types. |
45 // are at the same last_download_timestamp. Do an update for those types. | |
46 syncable::ModelTypeBitSet enabled_types; | 45 syncable::ModelTypeBitSet enabled_types; |
47 for (ModelSafeRoutingInfo::const_iterator i = session->routing_info().begin(); | 46 for (ModelSafeRoutingInfo::const_iterator i = session->routing_info().begin(); |
48 i != session->routing_info().end(); ++i) { | 47 i != session->routing_info().end(); ++i) { |
| 48 syncable::ModelType model_type = syncable::ModelTypeFromInt(i->first); |
49 enabled_types[i->first] = true; | 49 enabled_types[i->first] = true; |
| 50 dir->GetDownloadProgress(model_type, |
| 51 get_updates->add_from_progress_marker()); |
50 } | 52 } |
51 syncable::MultiTypeTimeStamp target = | |
52 dir->GetTypesWithOldestLastDownloadTimestamp(enabled_types); | |
53 VLOG(1) << "Getting updates from ts " << target.timestamp | |
54 << " for types " << target.data_types.to_string() | |
55 << " (of possible " << enabled_types.to_string() << ")"; | |
56 DCHECK(target.data_types.any()); | |
57 target.data_types.set(syncable::TOP_LEVEL_FOLDER); // Always fetched. | |
58 | 53 |
59 get_updates->set_from_timestamp(target.timestamp); | 54 VLOG(1) << "Getting updates for types " << enabled_types.to_string(); |
60 | 55 DCHECK(enabled_types.any()); |
61 // Set the requested_types protobuf field so that we fetch all enabled types. | |
62 SetRequestedTypes(target.data_types, get_updates->mutable_requested_types()); | |
63 | 56 |
64 // We want folders for our associated types, always. If we were to set | 57 // We want folders for our associated types, always. If we were to set |
65 // this to false, the server would send just the non-container items | 58 // this to false, the server would send just the non-container items |
66 // (e.g. Bookmark URLs but not their containing folders). | 59 // (e.g. Bookmark URLs but not their containing folders). |
67 get_updates->set_fetch_folders(true); | 60 get_updates->set_fetch_folders(true); |
68 | 61 |
69 // Set GetUpdatesMessage.GetUpdatesCallerInfo information. | 62 // Set GetUpdatesMessage.GetUpdatesCallerInfo information. |
70 get_updates->mutable_caller_info()->set_source( | 63 get_updates->mutable_caller_info()->set_source( |
71 session->TestAndSetSource().first); | 64 session->TestAndSetSource().first); |
72 get_updates->mutable_caller_info()->set_notifications_enabled( | 65 get_updates->mutable_caller_info()->set_notifications_enabled( |
73 session->context()->notifications_enabled()); | 66 session->context()->notifications_enabled()); |
74 | 67 |
75 SyncerProtoUtil::AddRequestBirthday(dir, &client_to_server_message); | 68 SyncerProtoUtil::AddRequestBirthday(dir, &client_to_server_message); |
76 | 69 |
77 bool ok = SyncerProtoUtil::PostClientToServerMessage( | 70 bool ok = SyncerProtoUtil::PostClientToServerMessage( |
78 client_to_server_message, | 71 client_to_server_message, |
79 &update_response, | 72 &update_response, |
80 session); | 73 session); |
81 | 74 |
82 VLOG(1) << SyncerProtoUtil::ClientToServerResponseDebugString( | 75 VLOG(1) << SyncerProtoUtil::ClientToServerResponseDebugString( |
83 update_response); | 76 update_response); |
84 | 77 |
85 StatusController* status = session->status_controller(); | 78 StatusController* status = session->status_controller(); |
86 status->set_updates_request_parameters(target); | 79 status->set_updates_request_types(enabled_types); |
87 if (!ok) { | 80 if (!ok) { |
88 status->increment_num_consecutive_errors(); | 81 status->increment_num_consecutive_errors(); |
89 status->mutable_updates_response()->Clear(); | 82 status->mutable_updates_response()->Clear(); |
90 LOG(ERROR) << "PostClientToServerMessage() failed during GetUpdates"; | 83 LOG(ERROR) << "PostClientToServerMessage() failed during GetUpdates"; |
91 return; | 84 return; |
92 } | 85 } |
93 | 86 |
94 status->mutable_updates_response()->CopyFrom(update_response); | 87 status->mutable_updates_response()->CopyFrom(update_response); |
95 | 88 |
96 VLOG(1) << "GetUpdates from ts " << get_updates->from_timestamp() | 89 VLOG(1) << "GetUpdates " |
97 << " returned " << update_response.get_updates().entries_size() | 90 << " returned " << update_response.get_updates().entries_size() |
98 << " updates and indicated " | 91 << " updates and indicated " |
99 << update_response.get_updates().changes_remaining() | 92 << update_response.get_updates().changes_remaining() |
100 << " updates left on server."; | 93 << " updates left on server."; |
101 } | 94 } |
102 | 95 |
103 void DownloadUpdatesCommand::SetRequestedTypes( | 96 void DownloadUpdatesCommand::SetRequestedTypes( |
104 const syncable::ModelTypeBitSet& target_datatypes, | 97 const syncable::ModelTypeBitSet& target_datatypes, |
105 sync_pb::EntitySpecifics* filter_protobuf) { | 98 sync_pb::EntitySpecifics* filter_protobuf) { |
106 // The datatypes which should be synced are dictated by the value of the | 99 // The datatypes which should be synced are dictated by the value of the |
107 // ModelSafeRoutingInfo. If a datatype is in the routing info map, it | 100 // ModelSafeRoutingInfo. If a datatype is in the routing info map, it |
108 // should be synced (even if it's GROUP_PASSIVE). | 101 // should be synced (even if it's GROUP_PASSIVE). |
109 int requested_type_count = 0; | 102 int requested_type_count = 0; |
110 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) { | 103 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) { |
111 if (target_datatypes[i]) { | 104 if (target_datatypes[i]) { |
112 requested_type_count++; | 105 requested_type_count++; |
113 syncable::AddDefaultExtensionValue(syncable::ModelTypeFromInt(i), | 106 syncable::AddDefaultExtensionValue(syncable::ModelTypeFromInt(i), |
114 filter_protobuf); | 107 filter_protobuf); |
115 } | 108 } |
116 } | 109 } |
117 DCHECK_LT(0, requested_type_count) << "Doing GetUpdates with empty filter."; | 110 DCHECK_LT(0, requested_type_count) << "Doing GetUpdates with empty filter."; |
118 } | 111 } |
119 | 112 |
120 } // namespace browser_sync | 113 } // namespace browser_sync |
OLD | NEW |