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

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

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

Powered by Google App Engine
This is Rietveld 408576698