Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(34)

Side by Side Diff: chrome/browser/sync/syncable/syncable.cc

Issue 2075012: Replace changes_channel with an observer list. (Closed)
Patch Set: Ready for checkin Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/sync/syncable/syncable.h ('k') | chrome/browser/sync/util/channel.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/syncable.h" 5 #include "chrome/browser/sync/syncable/syncable.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 8
9 #include <sys/stat.h> 9 #include <sys/stat.h>
10 #if defined(OS_POSIX) 10 #if defined(OS_POSIX)
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 name(name), 165 name(name),
166 metahandles_index(new Directory::MetahandlesIndex), 166 metahandles_index(new Directory::MetahandlesIndex),
167 ids_index(new Directory::IdsIndex), 167 ids_index(new Directory::IdsIndex),
168 parent_id_child_index(new Directory::ParentIdChildIndex), 168 parent_id_child_index(new Directory::ParentIdChildIndex),
169 client_tag_index(new Directory::ClientTagIndex), 169 client_tag_index(new Directory::ClientTagIndex),
170 extended_attributes(new ExtendedAttributes), 170 extended_attributes(new ExtendedAttributes),
171 unapplied_update_metahandles(new MetahandleSet), 171 unapplied_update_metahandles(new MetahandleSet),
172 unsynced_metahandles(new MetahandleSet), 172 unsynced_metahandles(new MetahandleSet),
173 dirty_metahandles(new MetahandleSet), 173 dirty_metahandles(new MetahandleSet),
174 channel(new Directory::Channel(syncable::DIRECTORY_DESTROYED)), 174 channel(new Directory::Channel(syncable::DIRECTORY_DESTROYED)),
175 changes_channel(new Directory::ChangesChannel(kShutdownChangesEvent)),
176 info_status(Directory::KERNEL_SHARE_INFO_VALID), 175 info_status(Directory::KERNEL_SHARE_INFO_VALID),
177 persisted_info(info.kernel_info), 176 persisted_info(info.kernel_info),
178 cache_guid(info.cache_guid), 177 cache_guid(info.cache_guid),
179 next_metahandle(info.max_metahandle + 1) { 178 next_metahandle(info.max_metahandle + 1) {
180 } 179 }
181 180
182 inline void DeleteEntry(EntryKernel* kernel) { 181 inline void DeleteEntry(EntryKernel* kernel) {
183 delete kernel; 182 delete kernel;
184 } 183 }
185 184
186 void Directory::Kernel::AddRef() { 185 void Directory::Kernel::AddRef() {
187 base::subtle::NoBarrier_AtomicIncrement(&refcount, 1); 186 base::subtle::NoBarrier_AtomicIncrement(&refcount, 1);
188 } 187 }
189 188
190 void Directory::Kernel::Release() { 189 void Directory::Kernel::Release() {
191 if (!base::subtle::NoBarrier_AtomicIncrement(&refcount, -1)) 190 if (!base::subtle::NoBarrier_AtomicIncrement(&refcount, -1))
192 delete this; 191 delete this;
193 } 192 }
194 193
195 Directory::Kernel::~Kernel() { 194 Directory::Kernel::~Kernel() {
196 CHECK(0 == refcount); 195 CHECK(0 == refcount);
197 delete channel; 196 delete channel;
198 delete changes_channel; 197 changes_channel.Notify(kShutdownChangesEvent);
199 delete unsynced_metahandles; 198 delete unsynced_metahandles;
200 delete unapplied_update_metahandles; 199 delete unapplied_update_metahandles;
201 delete dirty_metahandles; 200 delete dirty_metahandles;
202 delete extended_attributes; 201 delete extended_attributes;
203 delete parent_id_child_index; 202 delete parent_id_child_index;
204 delete client_tag_index; 203 delete client_tag_index;
205 delete ids_index; 204 delete ids_index;
206 for_each(metahandles_index->begin(), metahandles_index->end(), DeleteEntry); 205 for_each(metahandles_index->begin(), metahandles_index->end(), DeleteEntry);
207 delete metahandles_index; 206 delete metahandles_index;
208 } 207 }
(...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after
891 LOG(INFO) << "Cutting Invariant check short after " << elapsed_ms << "ms." 890 LOG(INFO) << "Cutting Invariant check short after " << elapsed_ms << "ms."
892 " Processed " << entries_done << "/" << handles.size() << " entries"; 891 " Processed " << entries_done << "/" << handles.size() << " entries";
893 return; 892 return;
894 } 893 }
895 } 894 }
896 // I did intend to add a check here to ensure no entries had been pulled into 895 // I did intend to add a check here to ensure no entries had been pulled into
897 // memory by this function, but we can't guard against another ReadTransaction 896 // memory by this function, but we can't guard against another ReadTransaction
898 // pulling entries into RAM 897 // pulling entries into RAM
899 } 898 }
900 899
900 browser_sync::ChannelHookup<DirectoryChangeEvent>* Directory::AddChangeObserver(
901 browser_sync::ChannelEventHandler<DirectoryChangeEvent>* observer) {
902 return kernel_->changes_channel.AddObserver(observer);
903 }
904
901 /////////////////////////////////////////////////////////////////////////////// 905 ///////////////////////////////////////////////////////////////////////////////
902 // ScopedKernelLocks 906 // ScopedKernelLocks
903 907
904 ScopedKernelLock::ScopedKernelLock(const Directory* dir) 908 ScopedKernelLock::ScopedKernelLock(const Directory* dir)
905 : scoped_lock_(dir->kernel_->mutex), dir_(const_cast<Directory*>(dir)) { 909 : scoped_lock_(dir->kernel_->mutex), dir_(const_cast<Directory*>(dir)) {
906 } 910 }
907 911
908 /////////////////////////////////////////////////////////////////////////// 912 ///////////////////////////////////////////////////////////////////////////
909 // Transactions 913 // Transactions
910 #if defined LOG_ALL || !defined NDEBUG 914 #if defined LOG_ALL || !defined NDEBUG
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
947 951
948 if (NULL == originals.get() || originals->empty()) { 952 if (NULL == originals.get() || originals->empty()) {
949 dirkernel_->transaction_mutex.Release(); 953 dirkernel_->transaction_mutex.Release();
950 return; 954 return;
951 } 955 }
952 956
953 AutoLock scoped_lock(dirkernel_->changes_channel_mutex); 957 AutoLock scoped_lock(dirkernel_->changes_channel_mutex);
954 // Tell listeners to calculate changes while we still have the mutex. 958 // Tell listeners to calculate changes while we still have the mutex.
955 DirectoryChangeEvent event = { DirectoryChangeEvent::CALCULATE_CHANGES, 959 DirectoryChangeEvent event = { DirectoryChangeEvent::CALCULATE_CHANGES,
956 originals.get(), this, writer_ }; 960 originals.get(), this, writer_ };
957 dirkernel_->changes_channel->NotifyListeners(event); 961 dirkernel_->changes_channel.Notify(event);
958 962
959 dirkernel_->transaction_mutex.Release(); 963 dirkernel_->transaction_mutex.Release();
960 964
961 DirectoryChangeEvent complete_event = 965 DirectoryChangeEvent complete_event =
962 { DirectoryChangeEvent::TRANSACTION_COMPLETE, 966 { DirectoryChangeEvent::TRANSACTION_COMPLETE,
963 NULL, NULL, INVALID }; 967 NULL, NULL, INVALID };
964 dirkernel_->changes_channel->NotifyListeners(complete_event); 968 dirkernel_->changes_channel.Notify(complete_event);
965 } 969 }
966 970
967 ReadTransaction::ReadTransaction(Directory* directory, const char* file, 971 ReadTransaction::ReadTransaction(Directory* directory, const char* file,
968 int line) 972 int line)
969 : BaseTransaction(directory, "Read", file, line, INVALID) { 973 : BaseTransaction(directory, "Read", file, line, INVALID) {
970 } 974 }
971 975
972 ReadTransaction::ReadTransaction(const ScopedDirLookup& scoped_dir, 976 ReadTransaction::ReadTransaction(const ScopedDirLookup& scoped_dir,
973 const char* file, int line) 977 const char* file, int line)
974 : BaseTransaction(scoped_dir.operator -> (), "Read", file, line, INVALID) { 978 : BaseTransaction(scoped_dir.operator -> (), "Read", file, line, INVALID) {
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after
1582 return s << std::dec; 1586 return s << std::dec;
1583 } 1587 }
1584 1588
1585 FastDump& operator<<(FastDump& dump, const syncable::Blob& blob) { 1589 FastDump& operator<<(FastDump& dump, const syncable::Blob& blob) {
1586 if (blob.empty()) 1590 if (blob.empty())
1587 return dump; 1591 return dump;
1588 string buffer(HexEncode(&blob[0], blob.size())); 1592 string buffer(HexEncode(&blob[0], blob.size()));
1589 dump.out_->sputn(buffer.c_str(), buffer.size()); 1593 dump.out_->sputn(buffer.c_str(), buffer.size());
1590 return dump; 1594 return dump;
1591 } 1595 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/syncable/syncable.h ('k') | chrome/browser/sync/util/channel.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698