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 // This used to do a lot of TLS-based management of multiple Directory objects. | 5 // This used to do a lot of TLS-based management of multiple Directory objects. |
6 // We now can access Directory objects from any thread for general purpose | 6 // We now can access Directory objects from any thread for general purpose |
7 // operations and we only ever have one Directory, so this class isn't doing | 7 // operations and we only ever have one Directory, so this class isn't doing |
8 // anything too fancy besides keeping calling and access conventions the same | 8 // anything too fancy besides keeping calling and access conventions the same |
9 // for now. | 9 // for now. |
10 // TODO(timsteele): We can probably nuke this entire class and use raw | 10 // TODO(timsteele): We can probably nuke this entire class and use raw |
11 // Directory objects everywhere. | 11 // Directory objects everywhere. |
12 #ifndef CHROME_BROWSER_SYNC_SYNCABLE_DIRECTORY_MANAGER_H_ | 12 #ifndef CHROME_BROWSER_SYNC_SYNCABLE_DIRECTORY_MANAGER_H_ |
13 #define CHROME_BROWSER_SYNC_SYNCABLE_DIRECTORY_MANAGER_H_ | 13 #define CHROME_BROWSER_SYNC_SYNCABLE_DIRECTORY_MANAGER_H_ |
14 | 14 |
15 #include <vector> | 15 #include <vector> |
16 | 16 |
17 #include "base/atomicops.h" | 17 #include "base/atomicops.h" |
| 18 #include "base/basictypes.h" |
| 19 #include "base/file_path.h" |
18 #include "base/lock.h" | 20 #include "base/lock.h" |
19 #include "base/basictypes.h" | |
20 #include "chrome/browser/sync/syncable/dir_open_result.h" | 21 #include "chrome/browser/sync/syncable/dir_open_result.h" |
21 #include "chrome/browser/sync/syncable/path_name_cmp.h" | 22 #include "chrome/browser/sync/syncable/path_name_cmp.h" |
22 #include "chrome/browser/sync/syncable/syncable.h" | 23 #include "chrome/browser/sync/syncable/syncable.h" |
23 #include "chrome/browser/sync/util/event_sys.h" | 24 #include "chrome/browser/sync/util/event_sys.h" |
24 #include "chrome/browser/sync/util/sync_types.h" | 25 #include "chrome/browser/sync/util/sync_types.h" |
25 | 26 |
26 namespace sync_api { class BaseTransaction; } | 27 namespace sync_api { class BaseTransaction; } |
27 | 28 |
28 namespace syncable { | 29 namespace syncable { |
29 | 30 |
(...skipping 13 matching lines...) Expand all Loading... |
43 } | 44 } |
44 }; | 45 }; |
45 | 46 |
46 DirectoryManagerEvent DirectoryManagerShutdownEvent(); | 47 DirectoryManagerEvent DirectoryManagerShutdownEvent(); |
47 | 48 |
48 class DirectoryManager { | 49 class DirectoryManager { |
49 public: | 50 public: |
50 typedef EventChannel<DirectoryManagerEvent> Channel; | 51 typedef EventChannel<DirectoryManagerEvent> Channel; |
51 | 52 |
52 // root_path specifies where db is stored. | 53 // root_path specifies where db is stored. |
53 explicit DirectoryManager(const PathString& root_path); | 54 explicit DirectoryManager(const FilePath& root_path); |
54 ~DirectoryManager(); | 55 ~DirectoryManager(); |
55 | 56 |
56 static const PathString GetSyncDataDatabaseFilename(); | 57 static const FilePath GetSyncDataDatabaseFilename(); |
57 const PathString GetSyncDataDatabasePath() const; | 58 const FilePath GetSyncDataDatabasePath() const; |
58 | 59 |
59 // Opens a directory. Returns false on error. | 60 // Opens a directory. Returns false on error. |
60 // Name parameter is the the user's login, | 61 // Name parameter is the the user's login, |
61 // MUST already have been converted to a common case. | 62 // MUST already have been converted to a common case. |
62 bool Open(const PathString& name); | 63 bool Open(const PathString& name); |
63 | 64 |
64 // Marks a directory as closed. It might take a while until all the | 65 // Marks a directory as closed. It might take a while until all the |
65 // file handles and resources are freed by other threads. | 66 // file handles and resources are freed by other threads. |
66 void Close(const PathString& name); | 67 void Close(const PathString& name); |
67 | 68 |
68 // Should be called at App exit. | 69 // Should be called at App exit. |
69 void FinalSaveChangesForAll(); | 70 void FinalSaveChangesForAll(); |
70 | 71 |
71 // Gets the list of currently open directory names. | 72 // Gets the list of currently open directory names. |
72 typedef std::vector<PathString> DirNames; | 73 typedef std::vector<PathString> DirNames; |
73 void GetOpenDirectories(DirNames* result); | 74 void GetOpenDirectories(DirNames* result); |
74 | 75 |
75 Channel* channel() const { return channel_; } | 76 Channel* channel() const { return channel_; } |
76 | 77 |
77 protected: | 78 protected: |
78 DirOpenResult OpenImpl(const PathString& name, const PathString& path, | 79 DirOpenResult OpenImpl(const PathString& name, const FilePath& path, |
79 bool* was_open); | 80 bool* was_open); |
80 | 81 |
81 // Helpers for friend class ScopedDirLookup: | 82 // Helpers for friend class ScopedDirLookup: |
82 friend class ScopedDirLookup; | 83 friend class ScopedDirLookup; |
83 | 84 |
84 const PathString root_path_; | 85 const FilePath root_path_; |
85 | 86 |
86 // protects managed_directory_ | 87 // protects managed_directory_ |
87 Lock lock_; | 88 Lock lock_; |
88 Directory* managed_directory_; | 89 Directory* managed_directory_; |
89 | 90 |
90 Channel* const channel_; | 91 Channel* const channel_; |
91 | 92 |
92 private: | 93 private: |
93 | 94 |
94 DISALLOW_COPY_AND_ASSIGN(DirectoryManager); | 95 DISALLOW_COPY_AND_ASSIGN(DirectoryManager); |
(...skipping 20 matching lines...) Expand all Loading... |
115 bool good_; | 116 bool good_; |
116 // Ensure that the programmer checks good before using the ScopedDirLookup. | 117 // Ensure that the programmer checks good before using the ScopedDirLookup. |
117 // This member should can be removed if it ever shows up in profiling | 118 // This member should can be removed if it ever shows up in profiling |
118 bool good_checked_; | 119 bool good_checked_; |
119 DirectoryManager* const dirman_; | 120 DirectoryManager* const dirman_; |
120 }; | 121 }; |
121 | 122 |
122 } // namespace syncable | 123 } // namespace syncable |
123 | 124 |
124 #endif // CHROME_BROWSER_SYNC_SYNCABLE_DIRECTORY_MANAGER_H_ | 125 #endif // CHROME_BROWSER_SYNC_SYNCABLE_DIRECTORY_MANAGER_H_ |
OLD | NEW |