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 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/port.h" | 13 #include "base/port.h" |
14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
15 #include "chrome/browser/sync/syncable/syncable.h" | 15 #include "chrome/browser/sync/syncable/syncable.h" |
16 #include "chrome/common/deprecated/event_sys-inl.h" | |
17 | 16 |
18 using browser_sync::Cryptographer; | 17 using browser_sync::Cryptographer; |
19 | 18 |
20 namespace syncable { | 19 namespace syncable { |
21 | 20 |
22 static const FilePath::CharType kSyncDataDatabaseFilename[] = | 21 static const FilePath::CharType kSyncDataDatabaseFilename[] = |
23 FILE_PATH_LITERAL("SyncData.sqlite3"); | 22 FILE_PATH_LITERAL("SyncData.sqlite3"); |
24 | 23 |
25 DirectoryManagerEvent DirectoryManagerShutdownEvent() { | |
26 DirectoryManagerEvent event; | |
27 event.what_happened = DirectoryManagerEvent::SHUTDOWN; | |
28 return event; | |
29 } | |
30 | |
31 // static | 24 // static |
32 const FilePath DirectoryManager::GetSyncDataDatabaseFilename() { | 25 const FilePath DirectoryManager::GetSyncDataDatabaseFilename() { |
33 return FilePath(kSyncDataDatabaseFilename); | 26 return FilePath(kSyncDataDatabaseFilename); |
34 } | 27 } |
35 | 28 |
36 const FilePath DirectoryManager::GetSyncDataDatabasePath() const { | 29 const FilePath DirectoryManager::GetSyncDataDatabasePath() const { |
37 return root_path_.Append(GetSyncDataDatabaseFilename()); | 30 return root_path_.Append(GetSyncDataDatabaseFilename()); |
38 } | 31 } |
39 | 32 |
40 DirectoryManager::DirectoryManager(const FilePath& path) | 33 DirectoryManager::DirectoryManager(const FilePath& path) |
41 : root_path_(path), | 34 : root_path_(path), |
42 managed_directory_(NULL), | 35 managed_directory_(NULL), |
43 channel_(new Channel(DirectoryManagerShutdownEvent())), | |
44 cryptographer_(new Cryptographer) { | 36 cryptographer_(new Cryptographer) { |
45 } | 37 } |
46 | 38 |
47 DirectoryManager::~DirectoryManager() { | 39 DirectoryManager::~DirectoryManager() { |
48 base::AutoLock lock(lock_); | 40 base::AutoLock lock(lock_); |
49 DCHECK_EQ(managed_directory_, static_cast<Directory*>(NULL)) | 41 DCHECK_EQ(managed_directory_, static_cast<Directory*>(NULL)) |
50 << "Dir " << managed_directory_->name() << " not closed!"; | 42 << "Dir " << managed_directory_->name() << " not closed!"; |
51 delete channel_; | |
52 } | 43 } |
53 | 44 |
54 bool DirectoryManager::Open(const std::string& name, | 45 bool DirectoryManager::Open(const std::string& name, |
55 DirectoryChangeDelegate* delegate) { | 46 DirectoryChangeDelegate* delegate) { |
56 bool was_open = false; | 47 bool was_open = false; |
57 const DirOpenResult result = | 48 const DirOpenResult result = |
58 OpenImpl(name, GetSyncDataDatabasePath(), delegate, &was_open); | 49 OpenImpl(name, GetSyncDataDatabasePath(), delegate, &was_open); |
59 return syncable::OPENED == result; | 50 return syncable::OPENED == result; |
60 } | 51 } |
61 | 52 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 { | 87 { |
97 base::AutoLock lock(lock_); | 88 base::AutoLock lock(lock_); |
98 if (!managed_directory_ || | 89 if (!managed_directory_ || |
99 base::strcasecmp(name.c_str(), | 90 base::strcasecmp(name.c_str(), |
100 managed_directory_->name().c_str()) != 0) { | 91 managed_directory_->name().c_str()) != 0) { |
101 // It wasn't open. | 92 // It wasn't open. |
102 return; | 93 return; |
103 } | 94 } |
104 } | 95 } |
105 | 96 |
106 // TODO(timsteele): No lock?! | |
107 // Notify listeners. | |
108 managed_directory_->channel()->NotifyListeners(DIRECTORY_CLOSED); | |
109 DirectoryManagerEvent event = { DirectoryManagerEvent::CLOSED, name }; | |
110 channel_->NotifyListeners(event); | |
111 | |
112 delete managed_directory_; | 97 delete managed_directory_; |
113 managed_directory_ = NULL; | 98 managed_directory_ = NULL; |
114 } | 99 } |
115 | 100 |
116 void DirectoryManager::FinalSaveChangesForAll() { | 101 void DirectoryManager::FinalSaveChangesForAll() { |
117 base::AutoLock lock(lock_); | 102 base::AutoLock lock(lock_); |
118 if (managed_directory_) | 103 if (managed_directory_) |
119 managed_directory_->SaveChanges(); | 104 managed_directory_->SaveChanges(); |
120 } | 105 } |
121 | 106 |
(...skipping 22 matching lines...) Expand all Loading... |
144 return dir_; | 129 return dir_; |
145 } | 130 } |
146 | 131 |
147 ScopedDirLookup::operator Directory* () const { | 132 ScopedDirLookup::operator Directory* () const { |
148 CHECK(good_checked_); | 133 CHECK(good_checked_); |
149 DCHECK(good_); | 134 DCHECK(good_); |
150 return dir_; | 135 return dir_; |
151 } | 136 } |
152 | 137 |
153 } // namespace syncable | 138 } // namespace syncable |
OLD | NEW |