| 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 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 cryptographer_(new Cryptographer) { | 44 cryptographer_(new Cryptographer) { |
| 45 } | 45 } |
| 46 | 46 |
| 47 DirectoryManager::~DirectoryManager() { | 47 DirectoryManager::~DirectoryManager() { |
| 48 base::AutoLock lock(lock_); | 48 base::AutoLock lock(lock_); |
| 49 DCHECK_EQ(managed_directory_, static_cast<Directory*>(NULL)) | 49 DCHECK_EQ(managed_directory_, static_cast<Directory*>(NULL)) |
| 50 << "Dir " << managed_directory_->name() << " not closed!"; | 50 << "Dir " << managed_directory_->name() << " not closed!"; |
| 51 delete channel_; | 51 delete channel_; |
| 52 } | 52 } |
| 53 | 53 |
| 54 bool DirectoryManager::Open(const std::string& name) { | 54 bool DirectoryManager::Open(const std::string& name, |
| 55 DirectoryChangeDelegate* delegate) { |
| 55 bool was_open = false; | 56 bool was_open = false; |
| 56 const DirOpenResult result = OpenImpl(name, | 57 const DirOpenResult result = |
| 57 GetSyncDataDatabasePath(), &was_open); | 58 OpenImpl(name, GetSyncDataDatabasePath(), delegate, &was_open); |
| 58 return syncable::OPENED == result; | 59 return syncable::OPENED == result; |
| 59 } | 60 } |
| 60 | 61 |
| 61 // Opens a directory. Returns false on error. | 62 // Opens a directory. Returns false on error. |
| 62 DirOpenResult DirectoryManager::OpenImpl(const std::string& name, | 63 DirOpenResult DirectoryManager::OpenImpl(const std::string& name, |
| 63 const FilePath& path, | 64 const FilePath& path, |
| 65 DirectoryChangeDelegate* delegate, |
| 64 bool* was_open) { | 66 bool* was_open) { |
| 65 bool opened = false; | 67 bool opened = false; |
| 66 { | 68 { |
| 67 base::AutoLock lock(lock_); | 69 base::AutoLock lock(lock_); |
| 68 // Check to see if it's already open. | 70 // Check to see if it's already open. |
| 69 if (managed_directory_) { | 71 if (managed_directory_) { |
| 70 DCHECK_EQ(base::strcasecmp(name.c_str(), | 72 DCHECK_EQ(base::strcasecmp(name.c_str(), |
| 71 managed_directory_->name().c_str()), 0) | 73 managed_directory_->name().c_str()), 0) |
| 72 << "Can't open more than one directory."; | 74 << "Can't open more than one directory."; |
| 73 opened = *was_open = true; | 75 opened = *was_open = true; |
| 74 } | 76 } |
| 75 } | 77 } |
| 76 | 78 |
| 77 if (opened) | 79 if (opened) |
| 78 return syncable::OPENED; | 80 return syncable::OPENED; |
| 79 // Otherwise, open it. | 81 // Otherwise, open it. |
| 80 | 82 |
| 81 scoped_ptr<Directory> dir(new Directory); | 83 scoped_ptr<Directory> dir(new Directory); |
| 82 const DirOpenResult result = dir->Open(path, name); | 84 const DirOpenResult result = dir->Open(path, name, delegate); |
| 83 if (syncable::OPENED == result) { | 85 if (syncable::OPENED == result) { |
| 84 base::AutoLock lock(lock_); | 86 base::AutoLock lock(lock_); |
| 85 managed_directory_ = dir.release(); | 87 managed_directory_ = dir.release(); |
| 86 } | 88 } |
| 87 return result; | 89 return result; |
| 88 } | 90 } |
| 89 | 91 |
| 90 // Marks a directory as closed. It might take a while until all the file | 92 // Marks a directory as closed. It might take a while until all the file |
| 91 // handles and resources are freed by other threads. | 93 // handles and resources are freed by other threads. |
| 92 void DirectoryManager::Close(const std::string& name) { | 94 void DirectoryManager::Close(const std::string& name) { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 return dir_; | 144 return dir_; |
| 143 } | 145 } |
| 144 | 146 |
| 145 ScopedDirLookup::operator Directory* () const { | 147 ScopedDirLookup::operator Directory* () const { |
| 146 CHECK(good_checked_); | 148 CHECK(good_checked_); |
| 147 DCHECK(good_); | 149 DCHECK(good_); |
| 148 return dir_; | 150 return dir_; |
| 149 } | 151 } |
| 150 | 152 |
| 151 } // namespace syncable | 153 } // namespace syncable |
| OLD | NEW |