| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/failed_datatypes_handler.h" | 5 #include "chrome/browser/sync/failed_datatypes_handler.h" |
| 6 #include "chrome/browser/sync/glue/data_type_manager.h" | 6 #include "chrome/browser/sync/glue/data_type_manager.h" |
| 7 #include "chrome/browser/sync/profile_sync_service.h" | 7 #include "chrome/browser/sync/profile_sync_service.h" |
| 8 | 8 |
| 9 using browser_sync::DataTypeManager; | 9 using browser_sync::DataTypeManager; |
| 10 | 10 |
| 11 FailedDatatypesHandler::FailedDatatypesHandler(ProfileSyncService* service) | 11 FailedDatatypesHandler::FailedDatatypesHandler(ProfileSyncService* service) |
| 12 : service_(service) { | 12 : service_(service) { |
| 13 } | 13 } |
| 14 | 14 |
| 15 FailedDatatypesHandler::~FailedDatatypesHandler() { | 15 FailedDatatypesHandler::~FailedDatatypesHandler() { |
| 16 } | 16 } |
| 17 | 17 |
| 18 syncable::ModelTypeSet GetTypesFromErrorsList( | 18 syncable::ModelTypeSet GetTypesFromErrorsList( |
| 19 const std::list<SyncError>& errors) { | 19 const std::list<csync::SyncError>& errors) { |
| 20 syncable::ModelTypeSet result; | 20 syncable::ModelTypeSet result; |
| 21 for (std::list<SyncError>::const_iterator it = errors.begin(); | 21 for (std::list<csync::SyncError>::const_iterator it = errors.begin(); |
| 22 it != errors.end(); ++it) { | 22 it != errors.end(); ++it) { |
| 23 DCHECK(!result.Has(it->type())); | 23 DCHECK(!result.Has(it->type())); |
| 24 result.Put(it->type()); | 24 result.Put(it->type()); |
| 25 } | 25 } |
| 26 return result; | 26 return result; |
| 27 } | 27 } |
| 28 | 28 |
| 29 syncable::ModelTypeSet FailedDatatypesHandler::GetFailedTypes() const { | 29 syncable::ModelTypeSet FailedDatatypesHandler::GetFailedTypes() const { |
| 30 syncable::ModelTypeSet result = GetTypesFromErrorsList(startup_errors_); | 30 syncable::ModelTypeSet result = GetTypesFromErrorsList(startup_errors_); |
| 31 result.PutAll(GetTypesFromErrorsList(runtime_errors_)); | 31 result.PutAll(GetTypesFromErrorsList(runtime_errors_)); |
| 32 return result; | 32 return result; |
| 33 } | 33 } |
| 34 | 34 |
| 35 bool FailedDatatypesHandler::UpdateFailedDatatypes( | 35 bool FailedDatatypesHandler::UpdateFailedDatatypes( |
| 36 const std::list<SyncError>& errors, | 36 const std::list<csync::SyncError>& errors, |
| 37 FailureType failure_type) { | 37 FailureType failure_type) { |
| 38 const syncable::ModelTypeSet types = GetFailedTypes(); | 38 const syncable::ModelTypeSet types = GetFailedTypes(); |
| 39 if (failure_type == RUNTIME) { | 39 if (failure_type == RUNTIME) { |
| 40 runtime_errors_.insert(runtime_errors_.end(), | 40 runtime_errors_.insert(runtime_errors_.end(), |
| 41 errors.begin(), | 41 errors.begin(), |
| 42 errors.end()); | 42 errors.end()); |
| 43 } else if (failure_type == STARTUP) { | 43 } else if (failure_type == STARTUP) { |
| 44 startup_errors_.insert(startup_errors_.end(), | 44 startup_errors_.insert(startup_errors_.end(), |
| 45 errors.begin(), | 45 errors.begin(), |
| 46 errors.end()); | 46 errors.end()); |
| 47 } else { | 47 } else { |
| 48 NOTREACHED(); | 48 NOTREACHED(); |
| 49 } | 49 } |
| 50 | 50 |
| 51 return !errors.empty(); | 51 return !errors.empty(); |
| 52 } | 52 } |
| 53 | 53 |
| 54 void FailedDatatypesHandler::OnUserChoseDatatypes() { | 54 void FailedDatatypesHandler::OnUserChoseDatatypes() { |
| 55 startup_errors_.clear(); | 55 startup_errors_.clear(); |
| 56 runtime_errors_.clear(); | 56 runtime_errors_.clear(); |
| 57 } | 57 } |
| 58 | 58 |
| 59 std::string GetErrorStringFromErrors(const std::list<SyncError>& errors) { | 59 std::string GetErrorStringFromErrors( |
| 60 const std::list<csync::SyncError>& errors) { |
| 60 std::string message; | 61 std::string message; |
| 61 for (std::list<SyncError>::const_iterator it = errors.begin(); | 62 for (std::list<csync::SyncError>::const_iterator it = errors.begin(); |
| 62 it != errors.end(); ++it) { | 63 it != errors.end(); ++it) { |
| 63 if (it != errors.begin()) { | 64 if (it != errors.begin()) { |
| 64 message += ", "; | 65 message += ", "; |
| 65 } | 66 } |
| 66 message += std::string(syncable::ModelTypeToString(it->type())) + " " + | 67 message += std::string(syncable::ModelTypeToString(it->type())) + " " + |
| 67 it->location().ToString() + ": " + it->message(); | 68 it->location().ToString() + ": " + it->message(); |
| 68 } | 69 } |
| 69 return message; | 70 return message; |
| 70 | 71 |
| 71 } | 72 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 84 message += GetErrorStringFromErrors(runtime_errors_); | 85 message += GetErrorStringFromErrors(runtime_errors_); |
| 85 message += "."; | 86 message += "."; |
| 86 } | 87 } |
| 87 return message; | 88 return message; |
| 88 } | 89 } |
| 89 | 90 |
| 90 bool FailedDatatypesHandler::AnyFailedDatatype() const { | 91 bool FailedDatatypesHandler::AnyFailedDatatype() const { |
| 91 return (!startup_errors_.empty() || !runtime_errors_.empty()); | 92 return (!startup_errors_.empty() || !runtime_errors_.empty()); |
| 92 } | 93 } |
| 93 | 94 |
| OLD | NEW |