| 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 // 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 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "chrome/browser/sync/syncable/dir_open_result.h" | 22 #include "chrome/browser/sync/syncable/dir_open_result.h" |
| 23 #include "chrome/browser/sync/syncable/syncable.h" | 23 #include "chrome/browser/sync/syncable/syncable.h" |
| 24 #include "chrome/browser/sync/util/cryptographer.h" | 24 #include "chrome/browser/sync/util/cryptographer.h" |
| 25 #include "chrome/common/deprecated/event_sys.h" | 25 #include "chrome/common/deprecated/event_sys.h" |
| 26 | 26 |
| 27 namespace sync_api { class BaseTransaction; } | 27 namespace sync_api { class BaseTransaction; } |
| 28 namespace syncable { class BaseTransaction; } | 28 namespace syncable { class BaseTransaction; } |
| 29 | 29 |
| 30 namespace syncable { | 30 namespace syncable { |
| 31 | 31 |
| 32 class DirectoryChangeDelegate; |
| 33 |
| 32 struct DirectoryManagerEvent { | 34 struct DirectoryManagerEvent { |
| 33 enum { | 35 enum { |
| 34 CLOSED, | 36 CLOSED, |
| 35 CLOSED_ALL, | 37 CLOSED_ALL, |
| 36 SHUTDOWN, | 38 SHUTDOWN, |
| 37 } what_happened; | 39 } what_happened; |
| 38 std::string dirname; | 40 std::string dirname; |
| 39 typedef DirectoryManagerEvent EventType; | 41 typedef DirectoryManagerEvent EventType; |
| 40 static inline bool IsChannelShutdownEvent(const EventType& event) { | 42 static inline bool IsChannelShutdownEvent(const EventType& event) { |
| 41 return SHUTDOWN == event.what_happened; | 43 return SHUTDOWN == event.what_happened; |
| 42 } | 44 } |
| 43 }; | 45 }; |
| 44 | 46 |
| 45 DirectoryManagerEvent DirectoryManagerShutdownEvent(); | 47 DirectoryManagerEvent DirectoryManagerShutdownEvent(); |
| 46 | 48 |
| 47 class DirectoryManager { | 49 class DirectoryManager { |
| 48 public: | 50 public: |
| 49 typedef EventChannel<DirectoryManagerEvent> Channel; | 51 typedef EventChannel<DirectoryManagerEvent> Channel; |
| 50 | 52 |
| 51 // root_path specifies where db is stored. | 53 // root_path specifies where db is stored. |
| 52 explicit DirectoryManager(const FilePath& root_path); | 54 explicit DirectoryManager(const FilePath& root_path); |
| 53 virtual ~DirectoryManager(); | 55 virtual ~DirectoryManager(); |
| 54 | 56 |
| 55 static const FilePath GetSyncDataDatabaseFilename(); | 57 static const FilePath GetSyncDataDatabaseFilename(); |
| 56 const FilePath GetSyncDataDatabasePath() const; | 58 const FilePath GetSyncDataDatabasePath() const; |
| 57 | 59 |
| 58 // Opens a directory. Returns false on error. | 60 // Opens a directory. Returns false on error. Name parameter is |
| 59 // Name parameter is the the user's login, | 61 // the the user's login, MUST already have been converted to a |
| 60 // MUST already have been converted to a common case. | 62 // common case. Does not take ownership of |delegate|, which must |
| 61 bool Open(const std::string& name); | 63 // be non-NULL. Starts sending events to |delegate| if the returned |
| 64 // result is true. Note that events to |delegate| may be sent from |
| 65 // *any* thread. |
| 66 bool Open(const std::string& name, DirectoryChangeDelegate* delegate); |
| 62 | 67 |
| 63 // Marks a directory as closed. It might take a while until all the | 68 // Marks a directory as closed and stops sending events to the |
| 64 // file handles and resources are freed by other threads. | 69 // delegate. It might take a while until all the file handles and |
| 70 // resources are freed by other threads. |
| 65 void Close(const std::string& name); | 71 void Close(const std::string& name); |
| 66 | 72 |
| 67 // Should be called at App exit. | 73 // Should be called at App exit. |
| 68 void FinalSaveChangesForAll(); | 74 void FinalSaveChangesForAll(); |
| 69 | 75 |
| 70 // Gets the list of currently open directory names. | 76 // Gets the list of currently open directory names. |
| 71 typedef std::vector<std::string> DirNames; | 77 typedef std::vector<std::string> DirNames; |
| 72 void GetOpenDirectories(DirNames* result); | 78 void GetOpenDirectories(DirNames* result); |
| 73 | 79 |
| 74 Channel* channel() const { return channel_; } | 80 Channel* channel() const { return channel_; } |
| 75 | 81 |
| 76 // Wrappers for cryptographer() that enforce holding a transaction. | 82 // Wrappers for cryptographer() that enforce holding a transaction. |
| 77 // Note: the Cryptographer is NOT thread safe. It must only be accessed while | 83 // Note: the Cryptographer is NOT thread safe. It must only be accessed while |
| 78 // the transaction is still active. The Cryptographer's pointer should not be | 84 // the transaction is still active. The Cryptographer's pointer should not be |
| 79 // stored separately. | 85 // stored separately. |
| 80 browser_sync::Cryptographer* GetCryptographer( | 86 browser_sync::Cryptographer* GetCryptographer( |
| 81 const sync_api::BaseTransaction* trans) const { return cryptographer(); } | 87 const sync_api::BaseTransaction* trans) const { return cryptographer(); } |
| 82 browser_sync::Cryptographer* GetCryptographer( | 88 browser_sync::Cryptographer* GetCryptographer( |
| 83 const syncable::BaseTransaction* trans) const { return cryptographer(); } | 89 const syncable::BaseTransaction* trans) const { return cryptographer(); } |
| 84 | 90 |
| 85 protected: | 91 protected: |
| 86 browser_sync::Cryptographer* cryptographer() const { | 92 browser_sync::Cryptographer* cryptographer() const { |
| 87 return cryptographer_.get(); | 93 return cryptographer_.get(); |
| 88 } | 94 } |
| 89 | 95 |
| 90 DirOpenResult OpenImpl(const std::string& name, const FilePath& path, | 96 DirOpenResult OpenImpl(const std::string& name, const FilePath& path, |
| 91 bool* was_open); | 97 DirectoryChangeDelegate* delegate, bool* was_open); |
| 92 | 98 |
| 93 // Helpers for friend class ScopedDirLookup: | 99 // Helpers for friend class ScopedDirLookup: |
| 94 friend class ScopedDirLookup; | 100 friend class ScopedDirLookup; |
| 95 | 101 |
| 96 const FilePath root_path_; | 102 const FilePath root_path_; |
| 97 | 103 |
| 98 // protects managed_directory_ | 104 // protects managed_directory_ |
| 99 base::Lock lock_; | 105 base::Lock lock_; |
| 100 Directory* managed_directory_; | 106 Directory* managed_directory_; |
| 101 | 107 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 128 bool good_; | 134 bool good_; |
| 129 // Ensure that the programmer checks good before using the ScopedDirLookup. | 135 // Ensure that the programmer checks good before using the ScopedDirLookup. |
| 130 // This member should can be removed if it ever shows up in profiling | 136 // This member should can be removed if it ever shows up in profiling |
| 131 bool good_checked_; | 137 bool good_checked_; |
| 132 DirectoryManager* const dirman_; | 138 DirectoryManager* const dirman_; |
| 133 }; | 139 }; |
| 134 | 140 |
| 135 } // namespace syncable | 141 } // namespace syncable |
| 136 | 142 |
| 137 #endif // CHROME_BROWSER_SYNC_SYNCABLE_DIRECTORY_MANAGER_H_ | 143 #endif // CHROME_BROWSER_SYNC_SYNCABLE_DIRECTORY_MANAGER_H_ |
| OLD | NEW |