OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/logging.h" | 11 #include "base/logging.h" |
12 #include "base/port.h" | 12 #include "base/port.h" |
| 13 #include "base/scoped_ptr.h" |
13 #include "chrome/browser/sync/syncable/syncable.h" | 14 #include "chrome/browser/sync/syncable/syncable.h" |
14 #include "chrome/browser/sync/util/event_sys-inl.h" | 15 #include "chrome/browser/sync/util/event_sys-inl.h" |
15 #include "chrome/browser/sync/util/path_helpers.h" | 16 #include "chrome/browser/sync/util/path_helpers.h" |
16 | 17 |
17 namespace syncable { | 18 namespace syncable { |
18 | 19 |
19 static const PSTR_CHAR kSyncDataDatabaseFilename[] = PSTR("SyncData.sqlite3"); | 20 static const FilePath::CharType kSyncDataDatabaseFilename[] = |
| 21 FILE_PATH_LITERAL("SyncData.sqlite3"); |
20 | 22 |
21 DirectoryManagerEvent DirectoryManagerShutdownEvent() { | 23 DirectoryManagerEvent DirectoryManagerShutdownEvent() { |
22 DirectoryManagerEvent event; | 24 DirectoryManagerEvent event; |
23 event.what_happened = DirectoryManagerEvent::SHUTDOWN; | 25 event.what_happened = DirectoryManagerEvent::SHUTDOWN; |
24 return event; | 26 return event; |
25 } | 27 } |
26 | 28 |
27 // static | 29 // static |
28 const PathString DirectoryManager::GetSyncDataDatabaseFilename() { | 30 const FilePath DirectoryManager::GetSyncDataDatabaseFilename() { |
29 return PathString(kSyncDataDatabaseFilename); | 31 return FilePath(kSyncDataDatabaseFilename); |
30 } | 32 } |
31 | 33 |
32 const PathString DirectoryManager::GetSyncDataDatabasePath() const { | 34 const FilePath DirectoryManager::GetSyncDataDatabasePath() const { |
33 PathString path(root_path_); | 35 return root_path_.Append(GetSyncDataDatabaseFilename()); |
34 path.append(kSyncDataDatabaseFilename); | |
35 return path; | |
36 } | 36 } |
37 | 37 |
38 DirectoryManager::DirectoryManager(const PathString& path) | 38 DirectoryManager::DirectoryManager(const FilePath& path) |
39 : root_path_(AppendSlash(path)), | 39 : root_path_(path), |
40 managed_directory_(NULL), | 40 managed_directory_(NULL), |
41 channel_(new Channel(DirectoryManagerShutdownEvent())) { | 41 channel_(new Channel(DirectoryManagerShutdownEvent())) { |
42 } | 42 } |
43 | 43 |
44 DirectoryManager::~DirectoryManager() { | 44 DirectoryManager::~DirectoryManager() { |
45 AutoLock lock(lock_); | 45 AutoLock lock(lock_); |
46 DCHECK_EQ(managed_directory_, static_cast<Directory*>(NULL)) | 46 DCHECK_EQ(managed_directory_, static_cast<Directory*>(NULL)) |
47 << "Dir " << managed_directory_->name() << " not closed!"; | 47 << "Dir " << managed_directory_->name() << " not closed!"; |
48 delete channel_; | 48 delete channel_; |
49 } | 49 } |
(...skipping 11 matching lines...) Expand all Loading... |
61 event.what_happened = DirectoryManagerEvent::OPEN_FAILED; | 61 event.what_happened = DirectoryManagerEvent::OPEN_FAILED; |
62 event.error = result; | 62 event.error = result; |
63 } | 63 } |
64 channel_->NotifyListeners(event); | 64 channel_->NotifyListeners(event); |
65 } | 65 } |
66 return syncable::OPENED == result; | 66 return syncable::OPENED == result; |
67 } | 67 } |
68 | 68 |
69 // Opens a directory. Returns false on error. | 69 // Opens a directory. Returns false on error. |
70 DirOpenResult DirectoryManager::OpenImpl(const PathString& name, | 70 DirOpenResult DirectoryManager::OpenImpl(const PathString& name, |
71 const PathString& path, | 71 const FilePath& path, |
72 bool* was_open) { | 72 bool* was_open) { |
73 bool opened = false; | 73 bool opened = false; |
74 { | 74 { |
75 AutoLock lock(lock_); | 75 AutoLock lock(lock_); |
76 // Check to see if it's already open. | 76 // Check to see if it's already open. |
77 if (managed_directory_) { | 77 if (managed_directory_) { |
78 DCHECK_EQ(ComparePathNames(name, managed_directory_->name()), 0) | 78 DCHECK_EQ(ComparePathNames(name, managed_directory_->name()), 0) |
79 << "Can't open more than one directory."; | 79 << "Can't open more than one directory."; |
80 opened = *was_open = true; | 80 opened = *was_open = true; |
81 } | 81 } |
82 } | 82 } |
83 | 83 |
84 if (opened) | 84 if (opened) |
85 return syncable::OPENED; | 85 return syncable::OPENED; |
86 // Otherwise, open it. | 86 // Otherwise, open it. |
87 | 87 |
88 Directory* dir = new Directory; | 88 scoped_ptr<Directory> dir(new Directory); |
89 const DirOpenResult result = dir->Open(path, name); | 89 const DirOpenResult result = dir->Open(path, name); |
90 if (syncable::OPENED == result) { | 90 if (syncable::OPENED == result) { |
91 AutoLock lock(lock_); | 91 AutoLock lock(lock_); |
92 managed_directory_ = dir; | 92 managed_directory_ = dir.release(); |
93 } else { | |
94 delete dir; | |
95 } | 93 } |
96 return result; | 94 return result; |
97 } | 95 } |
98 | 96 |
99 // Marks a directory as closed. It might take a while until all the file | 97 // Marks a directory as closed. It might take a while until all the file |
100 // handles and resources are freed by other threads. | 98 // handles and resources are freed by other threads. |
101 void DirectoryManager::Close(const PathString& name) { | 99 void DirectoryManager::Close(const PathString& name) { |
102 // Erase from mounted and opened directory lists. | 100 // Erase from mounted and opened directory lists. |
103 { | 101 { |
104 AutoLock lock(lock_); | 102 AutoLock lock(lock_); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 return dir_; | 147 return dir_; |
150 } | 148 } |
151 | 149 |
152 ScopedDirLookup::operator Directory* () const { | 150 ScopedDirLookup::operator Directory* () const { |
153 CHECK(good_checked_); | 151 CHECK(good_checked_); |
154 DCHECK(good_); | 152 DCHECK(good_); |
155 return dir_; | 153 return dir_; |
156 } | 154 } |
157 | 155 |
158 } // namespace syncable | 156 } // namespace syncable |
OLD | NEW |