OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "chrome/browser/sync/engine/syncer.h" | 10 #include "chrome/browser/sync/engine/syncer.h" |
11 #include "chrome/browser/sync/engine/syncer_proto_util.h" | 11 #include "chrome/browser/sync/engine/syncer_proto_util.h" |
12 #include "chrome/browser/sync/engine/syncproto.h" | 12 #include "chrome/browser/sync/engine/syncproto.h" |
13 #include "chrome/browser/sync/syncable/directory_manager.h" | 13 #include "chrome/browser/sync/syncable/directory_manager.h" |
14 #include "chrome/browser/sync/syncable/model_type_payload_map.h" | 14 #include "chrome/browser/sync/syncable/model_type_payload_map.h" |
15 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
16 | 16 |
17 using syncable::ScopedDirLookup; | 17 using syncable::ScopedDirLookup; |
18 | 18 |
19 using sync_pb::DebugInfo; | 19 using sync_pb::DebugInfo; |
20 | 20 |
21 namespace browser_sync { | 21 namespace browser_sync { |
22 using sessions::StatusController; | 22 using sessions::StatusController; |
23 using sessions::SyncSession; | 23 using sessions::SyncSession; |
24 using std::string; | 24 using std::string; |
25 using syncable::FIRST_REAL_MODEL_TYPE; | 25 using syncable::FIRST_REAL_MODEL_TYPE; |
26 using syncable::MODEL_TYPE_COUNT; | 26 using syncable::MODEL_TYPE_COUNT; |
| 27 using syncable::ModelEnumSet; |
| 28 using syncable::ModelEnumSetToString; |
27 | 29 |
28 DownloadUpdatesCommand::DownloadUpdatesCommand() {} | 30 DownloadUpdatesCommand::DownloadUpdatesCommand() {} |
29 DownloadUpdatesCommand::~DownloadUpdatesCommand() {} | 31 DownloadUpdatesCommand::~DownloadUpdatesCommand() {} |
30 | 32 |
31 void DownloadUpdatesCommand::ExecuteImpl(SyncSession* session) { | 33 void DownloadUpdatesCommand::ExecuteImpl(SyncSession* session) { |
32 ClientToServerMessage client_to_server_message; | 34 ClientToServerMessage client_to_server_message; |
33 ClientToServerResponse update_response; | 35 ClientToServerResponse update_response; |
34 | 36 |
35 client_to_server_message.set_share(session->context()->account_name()); | 37 client_to_server_message.set_share(session->context()->account_name()); |
36 client_to_server_message.set_message_contents( | 38 client_to_server_message.set_message_contents( |
37 ClientToServerMessage::GET_UPDATES); | 39 ClientToServerMessage::GET_UPDATES); |
38 GetUpdatesMessage* get_updates = | 40 GetUpdatesMessage* get_updates = |
39 client_to_server_message.mutable_get_updates(); | 41 client_to_server_message.mutable_get_updates(); |
40 if (CommandLine::ForCurrentProcess()->HasSwitch( | 42 if (CommandLine::ForCurrentProcess()->HasSwitch( |
41 switches::kCreateMobileBookmarksFolder)) { | 43 switches::kCreateMobileBookmarksFolder)) { |
42 get_updates->set_include_syncable_bookmarks(true); | 44 get_updates->set_include_syncable_bookmarks(true); |
43 } | 45 } |
44 | 46 |
45 ScopedDirLookup dir(session->context()->directory_manager(), | 47 ScopedDirLookup dir(session->context()->directory_manager(), |
46 session->context()->account_name()); | 48 session->context()->account_name()); |
47 if (!dir.good()) { | 49 if (!dir.good()) { |
48 LOG(ERROR) << "Scoped dir lookup failed!"; | 50 LOG(ERROR) << "Scoped dir lookup failed!"; |
49 return; | 51 return; |
50 } | 52 } |
51 | 53 |
52 // Request updates for all enabled types. | 54 // Request updates for all enabled types. |
53 syncable::ModelTypeBitSet enabled_types; | 55 const ModelEnumSet enabled_types = |
| 56 GetRoutingInfoTypes(session->routing_info()); |
| 57 DVLOG(1) << "Getting updates for types " |
| 58 << ModelEnumSetToString(enabled_types); |
| 59 DCHECK(!enabled_types.Empty()); |
| 60 |
54 const syncable::ModelTypePayloadMap& type_payload_map = | 61 const syncable::ModelTypePayloadMap& type_payload_map = |
55 session->source().types; | 62 session->source().types; |
56 for (ModelSafeRoutingInfo::const_iterator i = session->routing_info().begin(); | 63 for (ModelEnumSet::Iterator it = enabled_types.First(); |
57 i != session->routing_info().end(); ++i) { | 64 it.Good(); it.Inc()) { |
58 syncable::ModelType model_type = syncable::ModelTypeFromInt(i->first); | |
59 enabled_types[i->first] = true; | |
60 sync_pb::DataTypeProgressMarker* progress_marker = | 65 sync_pb::DataTypeProgressMarker* progress_marker = |
61 get_updates->add_from_progress_marker(); | 66 get_updates->add_from_progress_marker(); |
62 dir->GetDownloadProgress(model_type, progress_marker); | 67 dir->GetDownloadProgress(it.Get(), progress_marker); |
63 | 68 |
64 // Set notification hint if present. | 69 // Set notification hint if present. |
65 syncable::ModelTypePayloadMap::const_iterator type_payload = | 70 syncable::ModelTypePayloadMap::const_iterator type_payload = |
66 type_payload_map.find(i->first); | 71 type_payload_map.find(it.Get()); |
67 if (type_payload != type_payload_map.end()) { | 72 if (type_payload != type_payload_map.end()) { |
68 progress_marker->set_notification_hint(type_payload->second); | 73 progress_marker->set_notification_hint(type_payload->second); |
69 } | 74 } |
70 } | 75 } |
71 | 76 |
72 DVLOG(1) << "Getting updates for types " << enabled_types.to_string(); | |
73 DCHECK(enabled_types.any()); | |
74 | |
75 // We want folders for our associated types, always. If we were to set | 77 // We want folders for our associated types, always. If we were to set |
76 // this to false, the server would send just the non-container items | 78 // this to false, the server would send just the non-container items |
77 // (e.g. Bookmark URLs but not their containing folders). | 79 // (e.g. Bookmark URLs but not their containing folders). |
78 get_updates->set_fetch_folders(true); | 80 get_updates->set_fetch_folders(true); |
79 | 81 |
80 // Set GetUpdatesMessage.GetUpdatesCallerInfo information. | 82 // Set GetUpdatesMessage.GetUpdatesCallerInfo information. |
81 get_updates->mutable_caller_info()->set_source( | 83 get_updates->mutable_caller_info()->set_source( |
82 session->TestAndSetSource().updates_source); | 84 session->TestAndSetSource().updates_source); |
83 get_updates->mutable_caller_info()->set_notifications_enabled( | 85 get_updates->mutable_caller_info()->set_notifications_enabled( |
84 session->context()->notifications_enabled()); | 86 session->context()->notifications_enabled()); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 if (session->context()->debug_info_getter()) { | 128 if (session->context()->debug_info_getter()) { |
127 session->context()->debug_info_getter()->GetAndClearDebugInfo( | 129 session->context()->debug_info_getter()->GetAndClearDebugInfo( |
128 debug_info); | 130 debug_info); |
129 } | 131 } |
130 session->mutable_status_controller()->set_debug_info_sent(); | 132 session->mutable_status_controller()->set_debug_info_sent(); |
131 } | 133 } |
132 } | 134 } |
133 | 135 |
134 | 136 |
135 } // namespace browser_sync | 137 } // namespace browser_sync |
OLD | NEW |