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

Side by Side Diff: chrome/browser/sync/syncable/directory_manager.h

Issue 8586014: [Sync] Replace uses of ObserverListThreadSafe with WeakHandles (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync to head Created 9 years, 1 month 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 | Annotate | Revision Log
OLDNEW
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
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 #pragma once 14 #pragma once
15 15
16 #include <string> 16 #include <string>
17 #include <vector> 17 #include <vector>
18 18
19 #include "base/basictypes.h" 19 #include "base/basictypes.h"
20 #include "base/file_path.h" 20 #include "base/file_path.h"
21 #include "base/synchronization/lock.h" 21 #include "base/synchronization/lock.h"
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/browser/sync/util/weak_handle.h"
25 26
26 namespace sync_api { class BaseTransaction; } 27 namespace sync_api { class BaseTransaction; }
27 namespace syncable { class BaseTransaction; } 28 namespace syncable { class BaseTransaction; }
28 29
29 namespace syncable { 30 namespace syncable {
30 31
31 class DirectoryChangeDelegate; 32 class DirectoryChangeDelegate;
32 33
33 class DirectoryManager { 34 class DirectoryManager {
34 public: 35 public:
35 36
36 // root_path specifies where db is stored. 37 // root_path specifies where db is stored.
37 explicit DirectoryManager(const FilePath& root_path); 38 explicit DirectoryManager(const FilePath& root_path);
38 virtual ~DirectoryManager(); 39 virtual ~DirectoryManager();
39 40
40 static const FilePath GetSyncDataDatabaseFilename(); 41 static const FilePath GetSyncDataDatabaseFilename();
41 const FilePath GetSyncDataDatabasePath() const; 42 const FilePath GetSyncDataDatabasePath() const;
42 43
43 // Opens a directory. Returns false on error. Name parameter is 44 // Opens a directory. Returns false on error. Name parameter is
44 // the the user's login, MUST already have been converted to a 45 // the the user's login, MUST already have been converted to a
45 // common case. Does not take ownership of |delegate|, which must 46 // common case. Does not take ownership of |delegate|, which must
46 // be non-NULL. Starts sending events to |delegate| if the returned 47 // be non-NULL. Starts sending events to |delegate| if the returned
47 // result is true. Note that events to |delegate| may be sent from 48 // result is true. Note that events to |delegate| may be sent from
48 // *any* thread. 49 // *any* thread. |transaction_observer| must be initialized.
49 bool Open(const std::string& name, DirectoryChangeDelegate* delegate); 50 bool Open(const std::string& name, DirectoryChangeDelegate* delegate,
51 const browser_sync::WeakHandle<TransactionObserver>&
52 transaction_observer);
50 53
51 // Marks a directory as closed and stops sending events to the 54 // Marks a directory as closed and stops sending events to the
52 // delegate. It might take a while until all the file handles and 55 // delegate. It might take a while until all the file handles and
53 // resources are freed by other threads. 56 // resources are freed by other threads.
54 void Close(const std::string& name); 57 void Close(const std::string& name);
55 58
56 // Should be called at App exit. 59 // Should be called at App exit.
57 void FinalSaveChangesForAll(); 60 void FinalSaveChangesForAll();
58 61
59 // Gets the list of currently open directory names. 62 // Gets the list of currently open directory names.
60 typedef std::vector<std::string> DirNames; 63 typedef std::vector<std::string> DirNames;
61 void GetOpenDirectories(DirNames* result); 64 void GetOpenDirectories(DirNames* result);
62 65
63 // Wrappers for cryptographer() that enforce holding a transaction. 66 // Wrappers for cryptographer() that enforce holding a transaction.
64 // Note: the Cryptographer is NOT thread safe. It must only be accessed while 67 // Note: the Cryptographer is NOT thread safe. It must only be accessed while
65 // the transaction is still active. The Cryptographer's pointer should not be 68 // the transaction is still active. The Cryptographer's pointer should not be
66 // stored separately. 69 // stored separately.
67 browser_sync::Cryptographer* GetCryptographer( 70 browser_sync::Cryptographer* GetCryptographer(
68 const sync_api::BaseTransaction* trans) const { return cryptographer(); } 71 const sync_api::BaseTransaction* trans) const { return cryptographer(); }
69 browser_sync::Cryptographer* GetCryptographer( 72 browser_sync::Cryptographer* GetCryptographer(
70 const syncable::BaseTransaction* trans) const { return cryptographer(); } 73 const syncable::BaseTransaction* trans) const { return cryptographer(); }
71 74
72 protected: 75 protected:
73 browser_sync::Cryptographer* cryptographer() const { 76 browser_sync::Cryptographer* cryptographer() const {
74 return cryptographer_.get(); 77 return cryptographer_.get();
75 } 78 }
76 79
77 DirOpenResult OpenImpl(const std::string& name, const FilePath& path, 80 DirOpenResult OpenImpl(
78 DirectoryChangeDelegate* delegate, bool* was_open); 81 const std::string& name, const FilePath& path,
82 DirectoryChangeDelegate* delegate,
83 const browser_sync::WeakHandle<TransactionObserver>&
84 transaction_observer,
85 bool* was_open);
79 86
80 // Helpers for friend class ScopedDirLookup: 87 // Helpers for friend class ScopedDirLookup:
81 friend class ScopedDirLookup; 88 friend class ScopedDirLookup;
82 89
83 const FilePath root_path_; 90 const FilePath root_path_;
84 91
85 // protects managed_directory_ 92 // protects managed_directory_
86 base::Lock lock_; 93 base::Lock lock_;
87 Directory* managed_directory_; 94 Directory* managed_directory_;
88 95
(...skipping 24 matching lines...) Expand all
113 bool good_; 120 bool good_;
114 // Ensure that the programmer checks good before using the ScopedDirLookup. 121 // Ensure that the programmer checks good before using the ScopedDirLookup.
115 // This member should can be removed if it ever shows up in profiling 122 // This member should can be removed if it ever shows up in profiling
116 bool good_checked_; 123 bool good_checked_;
117 DirectoryManager* const dirman_; 124 DirectoryManager* const dirman_;
118 }; 125 };
119 126
120 } // namespace syncable 127 } // namespace syncable
121 128
122 #endif // CHROME_BROWSER_SYNC_SYNCABLE_DIRECTORY_MANAGER_H_ 129 #endif // CHROME_BROWSER_SYNC_SYNCABLE_DIRECTORY_MANAGER_H_
OLDNEW
« no previous file with comments | « chrome/browser/sync/sessions/sync_session_unittest.cc ('k') | chrome/browser/sync/syncable/directory_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698