summaryrefslogtreecommitdiffstats
path: root/chrome/browser/sync/notifier/communicator/mailbox.h
diff options
context:
space:
mode:
authornick@chromium.org <nick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-10 06:05:27 +0000
committernick@chromium.org <nick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-10 06:05:27 +0000
commit5852edc1b6eab234b9e048c41dd0d664ae7fc747 (patch)
tree9e5d8eb4833b76cdb11e66fc3607689e0f5e0122 /chrome/browser/sync/notifier/communicator/mailbox.h
parentf6059e37f8b8ac335ce18a189a13e702974a1c7e (diff)
downloadchromium_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/notifier/communicator/mailbox.h')
-rw-r--r--chrome/browser/sync/notifier/communicator/mailbox.h166
1 files changed, 166 insertions, 0 deletions
diff --git a/chrome/browser/sync/notifier/communicator/mailbox.h b/chrome/browser/sync/notifier/communicator/mailbox.h
new file mode 100644
index 0000000..009de73
--- /dev/null
+++ b/chrome/browser/sync/notifier/communicator/mailbox.h
@@ -0,0 +1,166 @@
+// 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.
+
+#ifndef CHROME_BROWSER_SYNC_NOTIFIER_COMMUNICATOR_MAILBOX_H_
+#define CHROME_BROWSER_SYNC_NOTIFIER_COMMUNICATOR_MAILBOX_H_
+
+#include <set>
+#include <string>
+#include <vector>
+
+#include "talk/base/basictypes.h"
+#include "talk/base/linked_ptr.h"
+
+namespace buzz {
+class XmlElement;
+}
+
+namespace notifier {
+// -----------------------------------------------------------------------------
+class MailAddress {
+ public:
+ MailAddress(const std::string& name, const std::string& address)
+ : name_(name),
+ address_(address) {
+ }
+ const std::string& name() const { return name_; }
+ const std::string& address() const { return address_; }
+ std::string safe_name() const; // will return *something*
+ private:
+ std::string name_;
+ std::string address_;
+};
+
+// -----------------------------------------------------------------------------
+class MailSender : public MailAddress {
+ public:
+ MailSender(const std::string& name, const std::string& address, bool unread,
+ bool originator)
+ : MailAddress(name, address),
+ unread_(unread),
+ originator_(originator) {
+ }
+
+ MailSender(const MailSender& r)
+ : MailAddress(r.name(), r.address()) {
+ unread_ = r.unread_;
+ originator_ = r.originator_;
+ }
+
+ bool unread() const { return unread_; }
+ bool originator() const { return originator_; }
+
+ private:
+ bool unread_;
+ bool originator_;
+};
+
+typedef std::vector<MailSender> MailSenderList;
+
+// -----------------------------------------------------------------------------
+// MessageThread: everything there is to know about a mail thread.
+class MessageThread {
+ public:
+ MessageThread(const MessageThread& r) {
+ labels_ = NULL;
+ senders_ = NULL;
+ *this = r;
+ }
+
+ ~MessageThread();
+
+ // Try to parse the XML to create a MessageThreadInfo. If NULL is returned
+ // then we either ran out of memory or there was an error in parsing the
+ // XML
+ static MessageThread* CreateFromXML(const buzz::XmlElement* src);
+
+ MessageThread& operator=(const MessageThread& r);
+
+ // SameThreadAs : name is self evident
+ bool SameThreadAs(const MessageThread& r) {
+ AssertValid();
+ r.AssertValid();
+ return (thread_id_ == r.thread_id_);
+ }
+
+ // SameAs : true if thread has same id and messages
+ // Assumes that messages don't disappear from threads.
+ bool SameAs(const MessageThread& r) {
+ AssertValid();
+ r.AssertValid();
+ return SameThreadAs(r) &&
+ message_count_ == r.message_count_;
+ }
+
+ typedef std::set<std::string> StringSet;
+
+ int64 thread_id() const { return thread_id_; }
+ const StringSet* labels() const { return labels_; }
+ int64 date64() const { return date64_; }
+ MailSenderList* senders() const { return senders_; }
+ int personal_level() const { return personal_level_; }
+ int message_count() const { return message_count_; }
+ const std::string& subject() const { return subject_; }
+ const std::string& snippet() const { return snippet_; }
+ bool starred() const;
+ bool unread() const;
+
+#ifdef _DEBUG
+ void AssertValid() const;
+#else
+ inline void AssertValid() const {}
+#endif
+
+ private:
+ void Clear();
+
+ private:
+ MessageThread() : senders_(NULL), labels_(NULL) {}
+ bool InitFromXml(const buzz::XmlElement* src);
+
+ int64 thread_id_;
+ int64 date64_;
+ int message_count_;
+ int personal_level_;
+ std::string subject_;
+ std::string snippet_;
+ MailSenderList* senders_;
+ StringSet* labels_;
+};
+
+typedef talk_base::linked_ptr<MessageThread> MessageThreadPointer;
+typedef std::vector<MessageThreadPointer> MessageThreadVector;
+
+// -----------------------------------------------------------------------------
+class MailBox {
+ public:
+ static MailBox* CreateFromXML(const buzz::XmlElement* src);
+
+ const MessageThreadVector& threads() const { return threads_; }
+ int mailbox_size() const { return mailbox_size_; }
+ int first_index() const { return first_index_; }
+ bool estimate() const { return estimate_; }
+ int64 result_time() const { return result_time_; }
+ int64 highest_thread_id() const { return highest_thread_id_; }
+
+ private:
+ MailBox() {}
+ bool InitFromXml(const buzz::XmlElement* src);
+
+ MessageThreadVector threads_;
+
+ int mailbox_size_;
+ int first_index_;
+ bool estimate_;
+ int64 result_time_;
+ int64 highest_thread_id_;
+};
+
+std::string GetSenderHtml(const MailSenderList& sender_list,
+ int message_count,
+ const std::string& me_address,
+ int space);
+} // namespace notifier
+
+#endif // CHROME_BROWSER_SYNC_NOTIFIER_COMMUNICATOR_MAILBOX_H_