diff options
author | nick@chromium.org <nick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-10 06:05:27 +0000 |
---|---|---|
committer | nick@chromium.org <nick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-10 06:05:27 +0000 |
commit | 5852edc1b6eab234b9e048c41dd0d664ae7fc747 (patch) | |
tree | 9e5d8eb4833b76cdb11e66fc3607689e0f5e0122 /chrome/browser/sync/syncable/directory_manager.h | |
parent | f6059e37f8b8ac335ce18a189a13e702974a1c7e (diff) | |
download | chromium_src-5852edc1b6eab234b9e048c41dd0d664ae7fc747.zip chromium_src-5852edc1b6eab234b9e048c41dd0d664ae7fc747.tar.gz chromium_src-5852edc1b6eab234b9e048c41dd0d664ae7fc747.tar.bz2 |
Initial commit of sync engine code to browser/sync.
The code is not built on any platform yet. That will arrive
as a subsequent checkin.
This is an implementation of the interface exposed earlier
through syncapi.h. It is the client side of a sync
protocol that lets users sync their browser data
(currently, just bookmarks) with their Google Account.
Table of contents:
browser/sync/
protocol - The protocol definition, and
other definitions necessary to connect to
the service.
syncable/ - defines a data model for syncable objects,
and provides a sqlite-based backing store
for this model.
engine/ - includes the core sync logic, including commiting
changes to the server, downloading changes from
the server, resolving conflicts, other parts of
the sync algorithm.
engine/net - parts of the sync engine focused on the
business of talking to the server. Some of
this is binds a generic "server connection"
interface to a concrete implementation
provided by Chromium.
notifier - the part of the syncer focused on the business
of sending and receiving xmpp notifications.
Notifications are used instead of polling to
achieve very low latency change propagation.
util - not necessarily sync specific utility code. Much
of this is scaffolding which should either be
replaced by, or merged with, the utility code
in base/.
BUG=none
TEST=this code includes its own suite of unit tests.
Review URL: http://codereview.chromium.org/194065
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25850 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/sync/syncable/directory_manager.h')
-rw-r--r-- | chrome/browser/sync/syncable/directory_manager.h | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/chrome/browser/sync/syncable/directory_manager.h b/chrome/browser/sync/syncable/directory_manager.h new file mode 100644 index 0000000..f937539 --- /dev/null +++ b/chrome/browser/sync/syncable/directory_manager.h @@ -0,0 +1,128 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +// +// This used to do a lot of TLS-based management of multiple Directory objects. +// We now can access Directory objects from any thread for general purpose +// operations and we only ever have one Directory, so this class isn't doing +// anything too fancy besides keeping calling and access conventions the same +// for now. +// TODO(timsteele): We can probably nuke this entire class and use raw +// Directory objects everywhere. +#ifndef CHROME_BROWSER_SYNC_SYNCABLE_DIRECTORY_MANAGER_H_ +#define CHROME_BROWSER_SYNC_SYNCABLE_DIRECTORY_MANAGER_H_ + +#include <pthread.h> + +#include <vector> + +#include "base/atomicops.h" +#include "base/basictypes.h" +#include "chrome/browser/sync/syncable/dir_open_result.h" +#include "chrome/browser/sync/syncable/path_name_cmp.h" +#include "chrome/browser/sync/syncable/syncable.h" +#include "chrome/browser/sync/util/event_sys.h" +#include "chrome/browser/sync/util/sync_types.h" + +namespace sync_api { class BaseTransaction; } + +namespace syncable { + +struct DirectoryManagerEvent { + enum { + OPEN_FAILED, + OPENED, + CLOSED, + CLOSED_ALL, + SHUTDOWN, + } what_happened; + PathString dirname; + DirOpenResult error; // Only for OPEN_FAILED. + typedef DirectoryManagerEvent EventType; + static inline bool IsChannelShutdownEvent(const EventType& event) { + return SHUTDOWN == event.what_happened; + } +}; + +DirectoryManagerEvent DirectoryManagerShutdownEvent(); + +class DirectoryManager { + public: + typedef EventChannel<DirectoryManagerEvent> Channel; + + // root_path specifies where db is stored. + explicit DirectoryManager(const PathString& root_path); + ~DirectoryManager(); + + static const PathString GetSyncDataDatabaseFilename(); + const PathString GetSyncDataDatabasePath() const; + + // Opens a directory. Returns false on error. + // Name parameter is the the user's login, + // MUST already have been converted to a common case. + bool Open(const PathString& name); + + // Marks a directory as closed. It might take a while until all the + // file handles and resources are freed by other threads. + void Close(const PathString& name); + + // Marks all directories as closed. It might take a while until all the + // file handles and resources are freed by other threads. + void CloseAllDirectories(); + + // Should be called at App exit. + void FinalSaveChangesForAll(); + + // Gets the list of currently open directory names. + typedef std::vector<PathString> DirNames; + void GetOpenDirectories(DirNames* result); + + Channel* channel() const { return channel_; } + + protected: + DirOpenResult OpenImpl(const PathString& name, const PathString& path, + bool* was_open); + + // Helpers for friend class ScopedDirLookup: + friend class ScopedDirLookup; + + const PathString root_path_; + // protects managed_directory_ + mutable pthread_mutex_t mutex_; + Directory* managed_directory_; + + Channel* const channel_; + + private: + + DISALLOW_COPY_AND_ASSIGN(DirectoryManager); +}; + + +class ScopedDirLookup { + public: + ScopedDirLookup(DirectoryManager* dirman, const PathString& name); + ~ScopedDirLookup(); + + inline bool good() { + good_checked_ = true; + return good_; + } + Directory* operator -> () const; + operator Directory* () const; + + protected: // Don't allow creation on heap, except by sync API wrapper. + friend class sync_api::BaseTransaction; + void* operator new(size_t size) { return (::operator new)(size); } + + Directory* dir_; + bool good_; + // Ensure that the programmer checks good before using the ScopedDirLookup + // This member should can be removed if it ever shows up in profiling + bool good_checked_; + DirectoryManager* const dirman_; +}; + +} // namespace syncable + +#endif // CHROME_BROWSER_SYNC_SYNCABLE_DIRECTORY_MANAGER_H_ |