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