OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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 "chrome/browser/sync/engine/download_updates_command.h" | |
6 | |
7 #include <string> | |
8 | |
9 #include "base/command_line.h" | |
10 #include "chrome/browser/sync/engine/syncer.h" | |
11 #include "chrome/browser/sync/engine/syncer_proto_util.h" | |
12 #include "chrome/browser/sync/engine/syncproto.h" | |
13 #include "chrome/browser/sync/syncable/model_type_payload_map.h" | |
14 #include "chrome/browser/sync/syncable/syncable.h" | |
15 | |
16 using sync_pb::DebugInfo; | |
17 | |
18 namespace browser_sync { | |
19 using sessions::StatusController; | |
20 using sessions::SyncSession; | |
21 using std::string; | |
22 using syncable::FIRST_REAL_MODEL_TYPE; | |
23 using syncable::MODEL_TYPE_COUNT; | |
24 using syncable::ModelTypeSet; | |
25 using syncable::ModelTypeSetToString; | |
26 | |
27 DownloadUpdatesCommand::DownloadUpdatesCommand( | |
28 bool create_mobile_bookmarks_folder) | |
29 : create_mobile_bookmarks_folder_(create_mobile_bookmarks_folder) {} | |
30 | |
31 DownloadUpdatesCommand::~DownloadUpdatesCommand() {} | |
32 | |
33 SyncerError DownloadUpdatesCommand::ExecuteImpl(SyncSession* session) { | |
34 ClientToServerMessage client_to_server_message; | |
35 ClientToServerResponse update_response; | |
36 | |
37 client_to_server_message.set_share(session->context()->account_name()); | |
38 client_to_server_message.set_message_contents( | |
39 ClientToServerMessage::GET_UPDATES); | |
40 GetUpdatesMessage* get_updates = | |
41 client_to_server_message.mutable_get_updates(); | |
42 get_updates->set_create_mobile_bookmarks_folder( | |
43 create_mobile_bookmarks_folder_); | |
44 | |
45 syncable::Directory* dir = session->context()->directory(); | |
46 | |
47 // Request updates for all enabled types. | |
48 const ModelTypeSet enabled_types = | |
49 GetRoutingInfoTypes(session->routing_info()); | |
50 DVLOG(1) << "Getting updates for types " | |
51 << ModelTypeSetToString(enabled_types); | |
52 DCHECK(!enabled_types.Empty()); | |
53 | |
54 const syncable::ModelTypePayloadMap& type_payload_map = | |
55 session->source().types; | |
56 for (ModelTypeSet::Iterator it = enabled_types.First(); | |
57 it.Good(); it.Inc()) { | |
58 sync_pb::DataTypeProgressMarker* progress_marker = | |
59 get_updates->add_from_progress_marker(); | |
60 dir->GetDownloadProgress(it.Get(), progress_marker); | |
61 | |
62 // Set notification hint if present. | |
63 syncable::ModelTypePayloadMap::const_iterator type_payload = | |
64 type_payload_map.find(it.Get()); | |
65 if (type_payload != type_payload_map.end()) { | |
66 progress_marker->set_notification_hint(type_payload->second); | |
67 } | |
68 } | |
69 | |
70 // We want folders for our associated types, always. If we were to set | |
71 // this to false, the server would send just the non-container items | |
72 // (e.g. Bookmark URLs but not their containing folders). | |
73 get_updates->set_fetch_folders(true); | |
74 | |
75 // Set GetUpdatesMessage.GetUpdatesCallerInfo information. | |
76 get_updates->mutable_caller_info()->set_source( | |
77 session->source().updates_source); | |
78 get_updates->mutable_caller_info()->set_notifications_enabled( | |
79 session->context()->notifications_enabled()); | |
80 | |
81 SyncerProtoUtil::AddRequestBirthday(dir, &client_to_server_message); | |
82 | |
83 DebugInfo* debug_info = client_to_server_message.mutable_debug_info(); | |
84 | |
85 AppendClientDebugInfoIfNeeded(session, debug_info); | |
86 | |
87 SyncerError result = SyncerProtoUtil::PostClientToServerMessage( | |
88 client_to_server_message, | |
89 &update_response, | |
90 session); | |
91 | |
92 DVLOG(2) << SyncerProtoUtil::ClientToServerResponseDebugString( | |
93 update_response); | |
94 | |
95 StatusController* status = session->mutable_status_controller(); | |
96 status->set_updates_request_types(enabled_types); | |
97 if (result != SYNCER_OK) { | |
98 status->mutable_updates_response()->Clear(); | |
99 LOG(ERROR) << "PostClientToServerMessage() failed during GetUpdates"; | |
100 return result; | |
101 } | |
102 | |
103 status->mutable_updates_response()->CopyFrom(update_response); | |
104 | |
105 DVLOG(1) << "GetUpdates " | |
106 << " returned " << update_response.get_updates().entries_size() | |
107 << " updates and indicated " | |
108 << update_response.get_updates().changes_remaining() | |
109 << " updates left on server."; | |
110 return result; | |
111 } | |
112 | |
113 void DownloadUpdatesCommand::AppendClientDebugInfoIfNeeded( | |
114 sessions::SyncSession* session, | |
115 DebugInfo* debug_info) { | |
116 // We want to send the debug info only once per sync cycle. Check if it has | |
117 // already been sent. | |
118 if (!session->status_controller().debug_info_sent()) { | |
119 DVLOG(1) << "Sending client debug info ..."; | |
120 // could be null in some unit tests. | |
121 if (session->context()->debug_info_getter()) { | |
122 session->context()->debug_info_getter()->GetAndClearDebugInfo( | |
123 debug_info); | |
124 } | |
125 session->mutable_status_controller()->set_debug_info_sent(); | |
126 } | |
127 } | |
128 | |
129 | |
130 } // namespace browser_sync | |
OLD | NEW |