| 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" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 using std::string; | 22 using std::string; |
| 23 using syncable::FIRST_REAL_MODEL_TYPE; | 23 using syncable::FIRST_REAL_MODEL_TYPE; |
| 24 using syncable::MODEL_TYPE_COUNT; | 24 using syncable::MODEL_TYPE_COUNT; |
| 25 | 25 |
| 26 DownloadUpdatesCommand::DownloadUpdatesCommand() {} | 26 DownloadUpdatesCommand::DownloadUpdatesCommand() {} |
| 27 DownloadUpdatesCommand::~DownloadUpdatesCommand() {} | 27 DownloadUpdatesCommand::~DownloadUpdatesCommand() {} |
| 28 | 28 |
| 29 void DownloadUpdatesCommand::ExecuteImpl(SyncSession* session) { | 29 void DownloadUpdatesCommand::ExecuteImpl(SyncSession* session) { |
| 30 ClientToServerMessage client_to_server_message; | 30 ClientToServerMessage client_to_server_message; |
| 31 ClientToServerResponse update_response; | 31 ClientToServerResponse update_response; |
| 32 SyncOperationResult result; |
| 32 | 33 |
| 33 client_to_server_message.set_share(session->context()->account_name()); | 34 client_to_server_message.set_share(session->context()->account_name()); |
| 34 client_to_server_message.set_message_contents( | 35 client_to_server_message.set_message_contents( |
| 35 ClientToServerMessage::GET_UPDATES); | 36 ClientToServerMessage::GET_UPDATES); |
| 36 GetUpdatesMessage* get_updates = | 37 GetUpdatesMessage* get_updates = |
| 37 client_to_server_message.mutable_get_updates(); | 38 client_to_server_message.mutable_get_updates(); |
| 38 if (CommandLine::ForCurrentProcess()->HasSwitch( | 39 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 39 switches::kEnableSyncedBookmarksFolder)) { | 40 switches::kEnableSyncedBookmarksFolder)) { |
| 40 get_updates->set_include_syncable_bookmarks(true); | 41 get_updates->set_include_syncable_bookmarks(true); |
| 41 } | 42 } |
| 42 | 43 |
| 43 ScopedDirLookup dir(session->context()->directory_manager(), | 44 ScopedDirLookup dir(session->context()->directory_manager(), |
| 44 session->context()->account_name()); | 45 session->context()->account_name()); |
| 45 if (!dir.good()) { | 46 if (!dir.good()) { |
| 46 LOG(ERROR) << "Scoped dir lookup failed!"; | 47 LOG(ERROR) << "Scoped dir lookup failed!"; |
| 48 result.error_type = DIRECTORY_LOOKUP_FAILED; |
| 49 session->status_controller()->set_last_download_updates_result( |
| 50 result); |
| 47 return; | 51 return; |
| 48 } | 52 } |
| 49 | 53 |
| 50 // Request updates for all enabled types. | 54 // Request updates for all enabled types. |
| 51 syncable::ModelTypeBitSet enabled_types; | 55 syncable::ModelTypeBitSet enabled_types; |
| 52 const syncable::ModelTypePayloadMap& type_payload_map = | 56 const syncable::ModelTypePayloadMap& type_payload_map = |
| 53 session->source().types; | 57 session->source().types; |
| 54 for (ModelSafeRoutingInfo::const_iterator i = session->routing_info().begin(); | 58 for (ModelSafeRoutingInfo::const_iterator i = session->routing_info().begin(); |
| 55 i != session->routing_info().end(); ++i) { | 59 i != session->routing_info().end(); ++i) { |
| 56 syncable::ModelType model_type = syncable::ModelTypeFromInt(i->first); | 60 syncable::ModelType model_type = syncable::ModelTypeFromInt(i->first); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 76 get_updates->set_fetch_folders(true); | 80 get_updates->set_fetch_folders(true); |
| 77 | 81 |
| 78 // Set GetUpdatesMessage.GetUpdatesCallerInfo information. | 82 // Set GetUpdatesMessage.GetUpdatesCallerInfo information. |
| 79 get_updates->mutable_caller_info()->set_source( | 83 get_updates->mutable_caller_info()->set_source( |
| 80 session->TestAndSetSource().updates_source); | 84 session->TestAndSetSource().updates_source); |
| 81 get_updates->mutable_caller_info()->set_notifications_enabled( | 85 get_updates->mutable_caller_info()->set_notifications_enabled( |
| 82 session->context()->notifications_enabled()); | 86 session->context()->notifications_enabled()); |
| 83 | 87 |
| 84 SyncerProtoUtil::AddRequestBirthday(dir, &client_to_server_message); | 88 SyncerProtoUtil::AddRequestBirthday(dir, &client_to_server_message); |
| 85 | 89 |
| 86 bool ok = SyncerProtoUtil::PostClientToServerMessage( | 90 result = SyncerProtoUtil::PostClientToServerMessage( |
| 87 client_to_server_message, | 91 client_to_server_message, |
| 88 &update_response, | 92 &update_response, |
| 89 session); | 93 session); |
| 90 | 94 |
| 91 VLOG(2) << SyncerProtoUtil::ClientToServerResponseDebugString( | 95 VLOG(2) << SyncerProtoUtil::ClientToServerResponseDebugString( |
| 92 update_response); | 96 update_response); |
| 93 | 97 |
| 94 StatusController* status = session->status_controller(); | 98 StatusController* status = session->status_controller(); |
| 95 status->set_updates_request_types(enabled_types); | 99 status->set_updates_request_types(enabled_types); |
| 96 if (!ok) { | 100 status->set_last_download_updates_result(result); |
| 101 if (result.error_type != OPERATION_SUCCESS) { |
| 97 status->increment_num_consecutive_errors(); | 102 status->increment_num_consecutive_errors(); |
| 98 status->mutable_updates_response()->Clear(); | 103 status->mutable_updates_response()->Clear(); |
| 99 LOG(ERROR) << "PostClientToServerMessage() failed during GetUpdates"; | 104 LOG(ERROR) << "Get updates failed with return code: " |
| 105 << browser_sync::GetSyncErrorTypeString(result.error_type); |
| 100 return; | 106 return; |
| 101 } | 107 } |
| 102 | 108 |
| 103 status->mutable_updates_response()->CopyFrom(update_response); | 109 status->mutable_updates_response()->CopyFrom(update_response); |
| 104 | 110 |
| 105 VLOG(1) << "GetUpdates " | 111 VLOG(1) << "GetUpdates " |
| 106 << " returned " << update_response.get_updates().entries_size() | 112 << " returned " << update_response.get_updates().entries_size() |
| 107 << " updates and indicated " | 113 << " updates and indicated " |
| 108 << update_response.get_updates().changes_remaining() | 114 << update_response.get_updates().changes_remaining() |
| 109 << " updates left on server."; | 115 << " updates left on server."; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 120 if (target_datatypes[i]) { | 126 if (target_datatypes[i]) { |
| 121 requested_type_count++; | 127 requested_type_count++; |
| 122 syncable::AddDefaultExtensionValue(syncable::ModelTypeFromInt(i), | 128 syncable::AddDefaultExtensionValue(syncable::ModelTypeFromInt(i), |
| 123 filter_protobuf); | 129 filter_protobuf); |
| 124 } | 130 } |
| 125 } | 131 } |
| 126 DCHECK_LT(0, requested_type_count) << "Doing GetUpdates with empty filter."; | 132 DCHECK_LT(0, requested_type_count) << "Doing GetUpdates with empty filter."; |
| 127 } | 133 } |
| 128 | 134 |
| 129 } // namespace browser_sync | 135 } // namespace browser_sync |
| OLD | NEW |