| 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/syncapi.h" | 5 #include "chrome/browser/sync/engine/syncapi.h" | 
| 6 | 6 | 
| 7 #include <algorithm> | 7 #include <algorithm> | 
| 8 #include <bitset> | 8 #include <bitset> | 
| 9 #include <iomanip> | 9 #include <iomanip> | 
| 10 #include <list> | 10 #include <list> | 
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 164                                     std::wstring* out) { | 164                                     std::wstring* out) { | 
| 165   int length_to_copy = server_name.length(); | 165   int length_to_copy = server_name.length(); | 
| 166   if (IsNameServerIllegalAfterTrimming(server_name) && | 166   if (IsNameServerIllegalAfterTrimming(server_name) && | 
| 167       EndsWithSpace(server_name)) | 167       EndsWithSpace(server_name)) | 
| 168     --length_to_copy; | 168     --length_to_copy; | 
| 169   if (!UTF8ToWide(server_name.c_str(), length_to_copy, out)) { | 169   if (!UTF8ToWide(server_name.c_str(), length_to_copy, out)) { | 
| 170     NOTREACHED() << "Could not convert server name from UTF8 to wide"; | 170     NOTREACHED() << "Could not convert server name from UTF8 to wide"; | 
| 171   } | 171   } | 
| 172 } | 172 } | 
| 173 | 173 | 
|  | 174 // Helper function that converts a PassphraseRequiredReason value to a string. | 
|  | 175 std::string PassphraseRequiredReasonToString( | 
|  | 176     PassphraseRequiredReason reason) { | 
|  | 177   switch (reason) { | 
|  | 178     case REASON_PASSPHRASE_NOT_REQUIRED: | 
|  | 179       return "REASON_PASSPHRASE_NOT_REQUIRED"; | 
|  | 180     case REASON_ENCRYPTION: | 
|  | 181       return "REASON_ENCRYPTION"; | 
|  | 182     case REASON_DECRYPTION: | 
|  | 183       return "REASON_DECRYPTION"; | 
|  | 184     case REASON_SET_PASSPHRASE_FAILED: | 
|  | 185       return "REASON_SET_PASSPHRASE_FAILED"; | 
|  | 186     default: | 
|  | 187       NOTREACHED(); | 
|  | 188       return "INVALID_REASON"; | 
|  | 189   } | 
|  | 190 } | 
|  | 191 | 
| 174 UserShare::UserShare() {} | 192 UserShare::UserShare() {} | 
| 175 | 193 | 
| 176 UserShare::~UserShare() {} | 194 UserShare::~UserShare() {} | 
| 177 | 195 | 
| 178 //////////////////////////////////// | 196 //////////////////////////////////// | 
| 179 // BaseNode member definitions. | 197 // BaseNode member definitions. | 
| 180 | 198 | 
| 181 BaseNode::BaseNode() {} | 199 BaseNode::BaseNode() {} | 
| 182 | 200 | 
| 183 BaseNode::~BaseNode() {} | 201 BaseNode::~BaseNode() {} | 
| (...skipping 1599 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1783       return; | 1801       return; | 
| 1784     } | 1802     } | 
| 1785 | 1803 | 
| 1786     nigori.CopyFrom(node.GetNigoriSpecifics()); | 1804     nigori.CopyFrom(node.GetNigoriSpecifics()); | 
| 1787     if (!nigori.encrypted().blob().empty()) { | 1805     if (!nigori.encrypted().blob().empty()) { | 
| 1788       if (cryptographer->CanDecrypt(nigori.encrypted())) { | 1806       if (cryptographer->CanDecrypt(nigori.encrypted())) { | 
| 1789         cryptographer->SetKeys(nigori.encrypted()); | 1807         cryptographer->SetKeys(nigori.encrypted()); | 
| 1790       } else { | 1808       } else { | 
| 1791         cryptographer->SetPendingKeys(nigori.encrypted()); | 1809         cryptographer->SetPendingKeys(nigori.encrypted()); | 
| 1792         FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 1810         FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 
| 1793                           OnPassphraseRequired(true)); | 1811                           OnPassphraseRequired(sync_api::REASON_DECRYPTION)); | 
| 1794       } | 1812       } | 
| 1795     } | 1813     } | 
| 1796   } | 1814   } | 
| 1797 | 1815 | 
| 1798   // Refresh list of encrypted datatypes. | 1816   // Refresh list of encrypted datatypes. | 
| 1799   syncable::ModelTypeSet encrypted_types = | 1817   syncable::ModelTypeSet encrypted_types = | 
| 1800       syncable::GetEncryptedDataTypesFromNigori(nigori); | 1818       syncable::GetEncryptedDataTypesFromNigori(nigori); | 
| 1801 | 1819 | 
| 1802   // Ensure any datatypes that need encryption are encrypted. | 1820   // Ensure any datatypes that need encryption are encrypted. | 
| 1803   EncryptDataTypes(encrypted_types); | 1821   EncryptDataTypes(encrypted_types); | 
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1945     const std::string& passphrase, bool is_explicit) { | 1963     const std::string& passphrase, bool is_explicit) { | 
| 1946   // All accesses to the cryptographer are protected by a transaction. | 1964   // All accesses to the cryptographer are protected by a transaction. | 
| 1947   WriteTransaction trans(GetUserShare()); | 1965   WriteTransaction trans(GetUserShare()); | 
| 1948   Cryptographer* cryptographer = trans.GetCryptographer(); | 1966   Cryptographer* cryptographer = trans.GetCryptographer(); | 
| 1949   KeyParams params = {"localhost", "dummy", passphrase}; | 1967   KeyParams params = {"localhost", "dummy", passphrase}; | 
| 1950 | 1968 | 
| 1951   if (cryptographer->has_pending_keys()) { | 1969   if (cryptographer->has_pending_keys()) { | 
| 1952     if (!cryptographer->DecryptPendingKeys(params)) { | 1970     if (!cryptographer->DecryptPendingKeys(params)) { | 
| 1953       VLOG(1) << "Passphrase failed to decrypt pending keys."; | 1971       VLOG(1) << "Passphrase failed to decrypt pending keys."; | 
| 1954       FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 1972       FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 
| 1955                         OnPassphraseFailed()); | 1973           OnPassphraseRequired(sync_api::REASON_SET_PASSPHRASE_FAILED)); | 
| 1956       return; | 1974       return; | 
| 1957     } | 1975     } | 
| 1958 | 1976 | 
| 1959     // TODO(tim): If this is the first time the user has entered a passphrase | 1977     // TODO(tim): If this is the first time the user has entered a passphrase | 
| 1960     // since the protocol changed to store passphrase preferences in the cloud, | 1978     // since the protocol changed to store passphrase preferences in the cloud, | 
| 1961     // make sure we update this preference. See bug 62103. | 1979     // make sure we update this preference. See bug 62103. | 
| 1962     if (is_explicit) | 1980     if (is_explicit) | 
| 1963       SetUsingExplicitPassphrasePrefForMigration(&trans); | 1981       SetUsingExplicitPassphrasePrefForMigration(&trans); | 
| 1964 | 1982 | 
| 1965     // Nudge the syncer so that encrypted datatype updates that were waiting for | 1983     // Nudge the syncer so that encrypted datatype updates that were waiting for | 
| (...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 2487           if (!nigori.encrypted().blob().empty()) { | 2505           if (!nigori.encrypted().blob().empty()) { | 
| 2488             DCHECK(!cryptographer->CanDecrypt(nigori.encrypted())); | 2506             DCHECK(!cryptographer->CanDecrypt(nigori.encrypted())); | 
| 2489             cryptographer->SetPendingKeys(nigori.encrypted()); | 2507             cryptographer->SetPendingKeys(nigori.encrypted()); | 
| 2490           } | 2508           } | 
| 2491         } | 2509         } | 
| 2492 | 2510 | 
| 2493         // If we've completed a sync cycle and the cryptographer isn't ready | 2511         // If we've completed a sync cycle and the cryptographer isn't ready | 
| 2494         // yet, prompt the user for a passphrase. | 2512         // yet, prompt the user for a passphrase. | 
| 2495         if (cryptographer->has_pending_keys()) { | 2513         if (cryptographer->has_pending_keys()) { | 
| 2496           FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 2514           FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 
| 2497                             OnPassphraseRequired(true)); | 2515                             OnPassphraseRequired(sync_api::REASON_DECRYPTION)); | 
| 2498         } else if (!cryptographer->is_ready()) { | 2516         } else if (!cryptographer->is_ready()) { | 
| 2499           FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 2517           FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 
| 2500                             OnPassphraseRequired(false)); | 2518                             OnPassphraseRequired(sync_api::REASON_ENCRYPTION)); | 
| 2501         } else { | 2519         } else { | 
| 2502           FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 2520           FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 
| 2503                             OnEncryptionComplete(encrypted_types)); | 2521                             OnEncryptionComplete(encrypted_types)); | 
| 2504         } | 2522         } | 
| 2505       } | 2523       } | 
| 2506     } | 2524     } | 
| 2507 | 2525 | 
| 2508     if (!initialized()) | 2526     if (!initialized()) | 
| 2509       return; | 2527       return; | 
| 2510 | 2528 | 
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 2821 void SyncManager::TriggerOnIncomingNotificationForTest( | 2839 void SyncManager::TriggerOnIncomingNotificationForTest( | 
| 2822     const syncable::ModelTypeBitSet& model_types) { | 2840     const syncable::ModelTypeBitSet& model_types) { | 
| 2823   syncable::ModelTypePayloadMap model_types_with_payloads = | 2841   syncable::ModelTypePayloadMap model_types_with_payloads = | 
| 2824       syncable::ModelTypePayloadMapFromBitSet(model_types, | 2842       syncable::ModelTypePayloadMapFromBitSet(model_types, | 
| 2825           std::string()); | 2843           std::string()); | 
| 2826 | 2844 | 
| 2827   data_->OnIncomingNotification(model_types_with_payloads); | 2845   data_->OnIncomingNotification(model_types_with_payloads); | 
| 2828 } | 2846 } | 
| 2829 | 2847 | 
| 2830 }  // namespace sync_api | 2848 }  // namespace sync_api | 
| OLD | NEW | 
|---|