OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_SYNC_NOTIFIER_COMMUNICATOR_MAILBOX_H_ |
| 6 #define CHROME_BROWSER_SYNC_NOTIFIER_COMMUNICATOR_MAILBOX_H_ |
| 7 |
| 8 #include <set> |
| 9 #include <string> |
| 10 #include <vector> |
| 11 |
| 12 #include "talk/base/basictypes.h" |
| 13 #include "talk/base/linked_ptr.h" |
| 14 |
| 15 namespace buzz { |
| 16 class XmlElement; |
| 17 } |
| 18 |
| 19 namespace notifier { |
| 20 // ----------------------------------------------------------------------------- |
| 21 class MailAddress { |
| 22 public: |
| 23 MailAddress(const std::string& name, const std::string& address) |
| 24 : name_(name), |
| 25 address_(address) { |
| 26 } |
| 27 const std::string& name() const { return name_; } |
| 28 const std::string& address() const { return address_; } |
| 29 std::string safe_name() const; // will return *something* |
| 30 private: |
| 31 std::string name_; |
| 32 std::string address_; |
| 33 }; |
| 34 |
| 35 // ----------------------------------------------------------------------------- |
| 36 class MailSender : public MailAddress { |
| 37 public: |
| 38 MailSender(const std::string& name, const std::string& address, bool unread, |
| 39 bool originator) |
| 40 : MailAddress(name, address), |
| 41 unread_(unread), |
| 42 originator_(originator) { |
| 43 } |
| 44 |
| 45 MailSender(const MailSender& r) |
| 46 : MailAddress(r.name(), r.address()) { |
| 47 unread_ = r.unread_; |
| 48 originator_ = r.originator_; |
| 49 } |
| 50 |
| 51 bool unread() const { return unread_; } |
| 52 bool originator() const { return originator_; } |
| 53 |
| 54 private: |
| 55 bool unread_; |
| 56 bool originator_; |
| 57 }; |
| 58 |
| 59 typedef std::vector<MailSender> MailSenderList; |
| 60 |
| 61 // ----------------------------------------------------------------------------- |
| 62 // MessageThread: everything there is to know about a mail thread. |
| 63 class MessageThread { |
| 64 public: |
| 65 MessageThread(const MessageThread& r) { |
| 66 labels_ = NULL; |
| 67 senders_ = NULL; |
| 68 *this = r; |
| 69 } |
| 70 |
| 71 ~MessageThread(); |
| 72 |
| 73 // Try to parse the XML to create a MessageThreadInfo. If NULL is returned |
| 74 // then we either ran out of memory or there was an error in parsing the |
| 75 // XML |
| 76 static MessageThread* CreateFromXML(const buzz::XmlElement* src); |
| 77 |
| 78 MessageThread& operator=(const MessageThread& r); |
| 79 |
| 80 // SameThreadAs : name is self evident |
| 81 bool SameThreadAs(const MessageThread& r) { |
| 82 AssertValid(); |
| 83 r.AssertValid(); |
| 84 return (thread_id_ == r.thread_id_); |
| 85 } |
| 86 |
| 87 // SameAs : true if thread has same id and messages |
| 88 // Assumes that messages don't disappear from threads. |
| 89 bool SameAs(const MessageThread& r) { |
| 90 AssertValid(); |
| 91 r.AssertValid(); |
| 92 return SameThreadAs(r) && |
| 93 message_count_ == r.message_count_; |
| 94 } |
| 95 |
| 96 typedef std::set<std::string> StringSet; |
| 97 |
| 98 int64 thread_id() const { return thread_id_; } |
| 99 const StringSet* labels() const { return labels_; } |
| 100 int64 date64() const { return date64_; } |
| 101 MailSenderList* senders() const { return senders_; } |
| 102 int personal_level() const { return personal_level_; } |
| 103 int message_count() const { return message_count_; } |
| 104 const std::string& subject() const { return subject_; } |
| 105 const std::string& snippet() const { return snippet_; } |
| 106 bool starred() const; |
| 107 bool unread() const; |
| 108 |
| 109 #ifdef _DEBUG |
| 110 void AssertValid() const; |
| 111 #else |
| 112 inline void AssertValid() const {} |
| 113 #endif |
| 114 |
| 115 private: |
| 116 void Clear(); |
| 117 |
| 118 private: |
| 119 MessageThread() : senders_(NULL), labels_(NULL) {} |
| 120 bool InitFromXml(const buzz::XmlElement* src); |
| 121 |
| 122 int64 thread_id_; |
| 123 int64 date64_; |
| 124 int message_count_; |
| 125 int personal_level_; |
| 126 std::string subject_; |
| 127 std::string snippet_; |
| 128 MailSenderList* senders_; |
| 129 StringSet* labels_; |
| 130 }; |
| 131 |
| 132 typedef talk_base::linked_ptr<MessageThread> MessageThreadPointer; |
| 133 typedef std::vector<MessageThreadPointer> MessageThreadVector; |
| 134 |
| 135 // ----------------------------------------------------------------------------- |
| 136 class MailBox { |
| 137 public: |
| 138 static MailBox* CreateFromXML(const buzz::XmlElement* src); |
| 139 |
| 140 const MessageThreadVector& threads() const { return threads_; } |
| 141 int mailbox_size() const { return mailbox_size_; } |
| 142 int first_index() const { return first_index_; } |
| 143 bool estimate() const { return estimate_; } |
| 144 int64 result_time() const { return result_time_; } |
| 145 int64 highest_thread_id() const { return highest_thread_id_; } |
| 146 |
| 147 private: |
| 148 MailBox() {} |
| 149 bool InitFromXml(const buzz::XmlElement* src); |
| 150 |
| 151 MessageThreadVector threads_; |
| 152 |
| 153 int mailbox_size_; |
| 154 int first_index_; |
| 155 bool estimate_; |
| 156 int64 result_time_; |
| 157 int64 highest_thread_id_; |
| 158 }; |
| 159 |
| 160 std::string GetSenderHtml(const MailSenderList& sender_list, |
| 161 int message_count, |
| 162 const std::string& me_address, |
| 163 int space); |
| 164 } // namespace notifier |
| 165 |
| 166 #endif // CHROME_BROWSER_SYNC_NOTIFIER_COMMUNICATOR_MAILBOX_H_ |
OLD | NEW |