OLD | NEW |
---|---|
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 #include "chrome/browser/extensions/app_notification.h" | 5 #include "chrome/browser/extensions/app_notification.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "chrome/common/guid.h" | 8 #include "chrome/common/guid.h" |
9 | 9 |
10 namespace { | 10 namespace { |
11 | 11 |
12 const char* kIsLocalKey = "is_local"; | 12 const char* kIsLocalKey = "is_local"; |
13 const char* kCreationKey= "creation_timestamp_ms"; | |
Munjal (Google)
2011/11/17 19:45:32
Nit: name nit. Here and in the rest of the file.
elvin
2011/11/17 22:28:17
Done.
| |
13 const char* kGuidKey = "guid"; | 14 const char* kGuidKey = "guid"; |
14 const char* kExtensionIdKey = "extension_id"; | 15 const char* kExtensionIdKey = "extension_id"; |
15 const char* kTitleKey = "title"; | 16 const char* kTitleKey = "title"; |
16 const char* kBodyKey = "body"; | 17 const char* kBodyKey = "body"; |
17 const char* kLinkUrlKey = "link_url"; | 18 const char* kLinkUrlKey = "link_url"; |
18 const char* kLinkTextKey = "link_text"; | 19 const char* kLinkTextKey = "link_text"; |
19 | 20 |
20 } // namespace | 21 } // namespace |
21 | 22 |
22 AppNotification::AppNotification(bool is_local, | 23 AppNotification::AppNotification(bool is_local, |
24 double creation_timestamp_ms, | |
23 const std::string& guid, | 25 const std::string& guid, |
24 const std::string& extension_id, | 26 const std::string& extension_id, |
25 const std::string& title, | 27 const std::string& title, |
26 const std::string& body) | 28 const std::string& body) |
27 : is_local_(is_local), | 29 : is_local_(is_local), |
30 creation_timestamp_ms_(creation_timestamp_ms), | |
28 extension_id_(extension_id), | 31 extension_id_(extension_id), |
29 title_(title), | 32 title_(title), |
30 body_(body) { | 33 body_(body) { |
31 guid_ = guid.empty() ? guid::GenerateGUID() : guid; | 34 guid_ = guid.empty() ? guid::GenerateGUID() : guid; |
32 } | 35 } |
33 | 36 |
34 AppNotification::~AppNotification() {} | 37 AppNotification::~AppNotification() {} |
35 | 38 |
36 AppNotification* AppNotification::Copy() { | 39 AppNotification* AppNotification::Copy() { |
37 AppNotification* copy = new AppNotification( | 40 AppNotification* copy = new AppNotification( |
38 this->is_local(), this->guid(), this->extension_id(), | 41 this->is_local(), this->creation_timestamp_ms(), |
42 this->guid(), this->extension_id(), | |
39 this->title(), this->body()); | 43 this->title(), this->body()); |
40 copy->set_link_url(this->link_url()); | 44 copy->set_link_url(this->link_url()); |
41 copy->set_link_text(this->link_text()); | 45 copy->set_link_text(this->link_text()); |
42 return copy; | 46 return copy; |
43 } | 47 } |
44 | 48 |
45 void AppNotification::ToDictionaryValue(DictionaryValue* result) { | 49 void AppNotification::ToDictionaryValue(DictionaryValue* result) { |
46 CHECK(result); | 50 CHECK(result); |
47 result->SetBoolean(kIsLocalKey, is_local_); | 51 result->SetBoolean(kIsLocalKey, is_local_); |
52 result->SetDouble(kCreationKey, creation_timestamp_ms_); | |
asargent_no_longer_on_chrome
2011/11/17 22:36:24
for a Time, you can serialize it as a string like
elvin
2011/11/17 22:52:58
Done
On 2011/11/17 22:36:24, Antony Sargent wrote:
| |
48 if (!guid_.empty()) | 53 if (!guid_.empty()) |
49 result->SetString(kGuidKey, guid_); | 54 result->SetString(kGuidKey, guid_); |
50 if (!extension_id_.empty()) | 55 if (!extension_id_.empty()) |
51 result->SetString(kExtensionIdKey, extension_id_); | 56 result->SetString(kExtensionIdKey, extension_id_); |
52 if (!title_.empty()) | 57 if (!title_.empty()) |
53 result->SetString(kTitleKey, title_); | 58 result->SetString(kTitleKey, title_); |
54 if (!body_.empty()) | 59 if (!body_.empty()) |
55 result->SetString(kBodyKey, body_); | 60 result->SetString(kBodyKey, body_); |
56 if (!link_url_.is_empty()) | 61 if (!link_url_.is_empty()) |
57 result->SetString(kLinkUrlKey, link_url_.possibly_invalid_spec()); | 62 result->SetString(kLinkUrlKey, link_url_.possibly_invalid_spec()); |
58 if (!link_text_.empty()) | 63 if (!link_text_.empty()) |
59 result->SetString(kLinkTextKey, link_text_); | 64 result->SetString(kLinkTextKey, link_text_); |
60 } | 65 } |
61 | 66 |
62 // static | 67 // static |
63 AppNotification* AppNotification::FromDictionaryValue( | 68 AppNotification* AppNotification::FromDictionaryValue( |
64 const DictionaryValue& value) { | 69 const DictionaryValue& value) { |
65 scoped_ptr<AppNotification> result(new AppNotification(true, "", "", "", "")); | 70 scoped_ptr<AppNotification> result( |
71 new AppNotification(true, 0, "", "", "", "")); | |
66 | 72 |
67 if (value.HasKey(kIsLocalKey) && !value.GetBoolean( | 73 if (value.HasKey(kIsLocalKey) && !value.GetBoolean( |
68 kIsLocalKey, &result->is_local_)) { | 74 kIsLocalKey, &result->is_local_)) { |
69 return NULL; | 75 return NULL; |
70 } | 76 } |
77 if (value.HasKey(kCreationKey) && !value.GetDouble( | |
Munjal (Google)
2011/11/17 19:45:32
Nit: take !value.GetDouble in the next line.
elvin
2011/11/17 22:28:17
Done.
| |
78 kCreationKey, &result->creation_timestamp_ms_)) { | |
79 return NULL; | |
80 } | |
71 if (value.HasKey(kGuidKey) && !value.GetString(kGuidKey, &result->guid_)) | 81 if (value.HasKey(kGuidKey) && !value.GetString(kGuidKey, &result->guid_)) |
72 return NULL; | 82 return NULL; |
73 if (value.HasKey(kExtensionIdKey) && | 83 if (value.HasKey(kExtensionIdKey) && |
74 !value.GetString(kExtensionIdKey, &result->extension_id_)) | 84 !value.GetString(kExtensionIdKey, &result->extension_id_)) |
75 return NULL; | 85 return NULL; |
76 if (value.HasKey(kTitleKey) && !value.GetString(kTitleKey, &result->title_)) | 86 if (value.HasKey(kTitleKey) && !value.GetString(kTitleKey, &result->title_)) |
77 return NULL; | 87 return NULL; |
78 if (value.HasKey(kBodyKey) && !value.GetString(kBodyKey, &result->body_)) | 88 if (value.HasKey(kBodyKey) && !value.GetString(kBodyKey, &result->body_)) |
79 return NULL; | 89 return NULL; |
80 if (value.HasKey(kLinkUrlKey)) { | 90 if (value.HasKey(kLinkUrlKey)) { |
81 std::string url; | 91 std::string url; |
82 if (!value.GetString(kLinkUrlKey, &url)) | 92 if (!value.GetString(kLinkUrlKey, &url)) |
83 return NULL; | 93 return NULL; |
84 GURL gurl(url); | 94 GURL gurl(url); |
85 if (!gurl.is_valid()) | 95 if (!gurl.is_valid()) |
86 return NULL; | 96 return NULL; |
87 result->set_link_url(gurl); | 97 result->set_link_url(gurl); |
88 } | 98 } |
89 if (value.HasKey(kLinkTextKey) && | 99 if (value.HasKey(kLinkTextKey) && |
90 !value.GetString(kLinkTextKey, &result->link_text_)) { | 100 !value.GetString(kLinkTextKey, &result->link_text_)) { |
91 return NULL; | 101 return NULL; |
92 } | 102 } |
93 | 103 |
94 return result.release(); | 104 return result.release(); |
95 } | 105 } |
96 | 106 |
97 bool AppNotification::Equals(const AppNotification& other) const { | 107 bool AppNotification::Equals(const AppNotification& other) const { |
98 return (is_local_ == other.is_local_ && | 108 return (is_local_ == other.is_local_ && |
109 creation_timestamp_ms_ == other.creation_timestamp_ms_ && | |
99 guid_ == other.guid_ && | 110 guid_ == other.guid_ && |
100 extension_id_ == other.extension_id_ && | 111 extension_id_ == other.extension_id_ && |
101 title_ == other.title_ && | 112 title_ == other.title_ && |
102 body_ == other.body_ && | 113 body_ == other.body_ && |
103 link_url_ == other.link_url_ && | 114 link_url_ == other.link_url_ && |
104 link_text_ == other.link_text_); | 115 link_text_ == other.link_text_); |
105 } | 116 } |
106 | 117 |
107 AppNotificationList* CopyAppNotificationList( | 118 AppNotificationList* CopyAppNotificationList( |
108 const AppNotificationList& source) { | 119 const AppNotificationList& source) { |
109 AppNotificationList* copy = new AppNotificationList(); | 120 AppNotificationList* copy = new AppNotificationList(); |
110 | 121 |
111 for (AppNotificationList::const_iterator iter = source.begin(); | 122 for (AppNotificationList::const_iterator iter = source.begin(); |
112 iter != source.end(); ++iter) { | 123 iter != source.end(); ++iter) { |
113 copy->push_back(linked_ptr<AppNotification>(iter->get()->Copy())); | 124 copy->push_back(linked_ptr<AppNotification>(iter->get()->Copy())); |
114 } | 125 } |
115 return copy; | 126 return copy; |
116 } | 127 } |
OLD | NEW |