Chromium Code Reviews| 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/syncable/directory_manager.h" | 5 #include "chrome/browser/sync/syncable/directory_manager.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <iterator> | 9 #include <iterator> |
| 10 | 10 |
| 11 #include "base/file_util.h" | |
| 11 #include "base/logging.h" | 12 #include "base/logging.h" |
| 12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/port.h" | 14 #include "base/port.h" |
| 14 #include "base/string_util.h" | 15 #include "base/string_util.h" |
| 15 #include "chrome/browser/sync/syncable/syncable.h" | 16 #include "chrome/browser/sync/syncable/syncable.h" |
| 16 | 17 |
| 17 using browser_sync::Cryptographer; | 18 using browser_sync::Cryptographer; |
| 18 | 19 |
| 19 namespace syncable { | 20 namespace syncable { |
| 20 | 21 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 65 << "Can't open more than one directory."; | 66 << "Can't open more than one directory."; |
| 66 opened = *was_open = true; | 67 opened = *was_open = true; |
| 67 } | 68 } |
| 68 } | 69 } |
| 69 | 70 |
| 70 if (opened) | 71 if (opened) |
| 71 return syncable::OPENED; | 72 return syncable::OPENED; |
| 72 // Otherwise, open it. | 73 // Otherwise, open it. |
| 73 | 74 |
| 74 scoped_ptr<Directory> dir(new Directory); | 75 scoped_ptr<Directory> dir(new Directory); |
| 75 const DirOpenResult result = dir->Open(path, name, delegate); | 76 DirOpenResult result = dir->Open(path, name, delegate); |
| 77 | |
| 78 if (syncable::FAILED_LOGICAL_CORRUPTION == result) { | |
| 79 // In this case, wipe out the directory and try again. | |
| 80 VLOG(ERROR) << "Database consistency checks failed. " | |
| 81 << "Will re-create sync database at " | |
| 82 << path.LossyDisplayName(); | |
| 83 dir.reset(new Directory); | |
|
tim (not reviewing)
2011/11/17 18:39:57
style nit - use Directory()
| |
| 84 file_util::Delete(path, false); | |
| 85 result = dir->Open(path, name, delegate); | |
| 86 } | |
| 87 | |
| 76 if (syncable::OPENED == result) { | 88 if (syncable::OPENED == result) { |
| 77 base::AutoLock lock(lock_); | 89 base::AutoLock lock(lock_); |
| 78 managed_directory_ = dir.release(); | 90 managed_directory_ = dir.release(); |
| 79 } | 91 } |
| 92 | |
| 80 return result; | 93 return result; |
| 81 } | 94 } |
| 82 | 95 |
| 83 // Marks a directory as closed. It might take a while until all the file | 96 // Marks a directory as closed. It might take a while until all the file |
| 84 // handles and resources are freed by other threads. | 97 // handles and resources are freed by other threads. |
| 85 void DirectoryManager::Close(const std::string& name) { | 98 void DirectoryManager::Close(const std::string& name) { |
| 86 // Erase from mounted and opened directory lists. | 99 // Erase from mounted and opened directory lists. |
| 87 { | 100 { |
| 88 base::AutoLock lock(lock_); | 101 base::AutoLock lock(lock_); |
| 89 if (!managed_directory_ || | 102 if (!managed_directory_ || |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 129 return dir_; | 142 return dir_; |
| 130 } | 143 } |
| 131 | 144 |
| 132 ScopedDirLookup::operator Directory* () const { | 145 ScopedDirLookup::operator Directory* () const { |
| 133 CHECK(good_checked_); | 146 CHECK(good_checked_); |
| 134 DCHECK(good_); | 147 DCHECK(good_); |
| 135 return dir_; | 148 return dir_; |
| 136 } | 149 } |
| 137 | 150 |
| 138 } // namespace syncable | 151 } // namespace syncable |
| OLD | NEW |