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

Side by Side Diff: chrome/browser/sync/notifier/communicator/mailbox.h

Issue 1956001: Moved XMPP notifier library from chrome/browser/sync to chrome/common.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 7 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
OLDNEW
(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 XML.
75 static MessageThread* CreateFromXML(const buzz::XmlElement* src);
76
77 MessageThread& operator=(const MessageThread& r);
78
79 // SameThreadAs : name is self evident.
80 bool SameThreadAs(const MessageThread& r) {
81 AssertValid();
82 r.AssertValid();
83 return (thread_id_ == r.thread_id_);
84 }
85
86 // SameAs : true if thread has same id and messages.
87 // Assumes that messages don't disappear from threads.
88 bool SameAs(const MessageThread& r) {
89 AssertValid();
90 r.AssertValid();
91 return SameThreadAs(r) &&
92 message_count_ == r.message_count_;
93 }
94
95 typedef std::set<std::string> StringSet;
96
97 int64 thread_id() const { return thread_id_; }
98 const StringSet* labels() const { return labels_; }
99 int64 date64() const { return date64_; }
100 MailSenderList* senders() const { return senders_; }
101 int personal_level() const { return personal_level_; }
102 int message_count() const { return message_count_; }
103 const std::string& subject() const { return subject_; }
104 const std::string& snippet() const { return snippet_; }
105 bool starred() const;
106 bool unread() const;
107
108 #if defined(DEBUG)
109 void AssertValid() const;
110 #else
111 inline void AssertValid() const {}
112 #endif
113
114 private:
115 void Clear();
116
117 private:
118 MessageThread() : senders_(NULL), labels_(NULL) {}
119 bool InitFromXml(const buzz::XmlElement* src);
120
121 int64 thread_id_;
122 int64 date64_;
123 int message_count_;
124 int personal_level_;
125 std::string subject_;
126 std::string snippet_;
127 MailSenderList* senders_;
128 StringSet* labels_;
129 };
130
131 typedef talk_base::linked_ptr<MessageThread> MessageThreadPointer;
132 typedef std::vector<MessageThreadPointer> MessageThreadVector;
133
134 // -----------------------------------------------------------------------------
135 class MailBox {
136 public:
137 static MailBox* CreateFromXML(const buzz::XmlElement* src);
138
139 const MessageThreadVector& threads() const { return threads_; }
140 int mailbox_size() const { return mailbox_size_; }
141 int first_index() const { return first_index_; }
142 bool estimate() const { return estimate_; }
143 int64 result_time() const { return result_time_; }
144 int64 highest_thread_id() const { return highest_thread_id_; }
145
146 private:
147 MailBox() {}
148 bool InitFromXml(const buzz::XmlElement* src);
149
150 MessageThreadVector threads_;
151
152 int mailbox_size_;
153 int first_index_;
154 bool estimate_;
155 int64 result_time_;
156 int64 highest_thread_id_;
157 };
158
159 std::string GetSenderHtml(const MailSenderList& sender_list,
160 int message_count,
161 const std::string& me_address,
162 int space);
163
164 } // namespace notifier
165
166 #endif // CHROME_BROWSER_SYNC_NOTIFIER_COMMUNICATOR_MAILBOX_H_
OLDNEW
« no previous file with comments | « chrome/browser/sync/notifier/communicator/login_settings.cc ('k') | chrome/browser/sync/notifier/communicator/mailbox.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698