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

Side by Side Diff: chrome/browser/extensions/app_notification.cc

Issue 8567018: Limit number of notifications that can be received by the client. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 9 years, 1 month 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
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/string_number_conversions.h"
7 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
8 #include "chrome/common/guid.h" 9 #include "chrome/common/guid.h"
9 10
10 namespace { 11 namespace {
11 12
12 const char* kIsLocalKey = "is_local"; 13 const char* kIsLocalKey = "is_local";
14 const char* kCreationTime= "creation_time";
13 const char* kGuidKey = "guid"; 15 const char* kGuidKey = "guid";
14 const char* kExtensionIdKey = "extension_id"; 16 const char* kExtensionIdKey = "extension_id";
15 const char* kTitleKey = "title"; 17 const char* kTitleKey = "title";
16 const char* kBodyKey = "body"; 18 const char* kBodyKey = "body";
17 const char* kLinkUrlKey = "link_url"; 19 const char* kLinkUrlKey = "link_url";
18 const char* kLinkTextKey = "link_text"; 20 const char* kLinkTextKey = "link_text";
19 21
20 } // namespace 22 } // namespace
21 23
22 AppNotification::AppNotification(bool is_local, 24 AppNotification::AppNotification(bool is_local,
25 const base::Time creation_time,
23 const std::string& guid, 26 const std::string& guid,
24 const std::string& extension_id, 27 const std::string& extension_id,
25 const std::string& title, 28 const std::string& title,
26 const std::string& body) 29 const std::string& body)
27 : is_local_(is_local), 30 : is_local_(is_local),
31 creation_time_(creation_time),
28 extension_id_(extension_id), 32 extension_id_(extension_id),
29 title_(title), 33 title_(title),
30 body_(body) { 34 body_(body) {
31 guid_ = guid.empty() ? guid::GenerateGUID() : guid; 35 guid_ = guid.empty() ? guid::GenerateGUID() : guid;
32 } 36 }
33 37
34 AppNotification::~AppNotification() {} 38 AppNotification::~AppNotification() {}
35 39
36 AppNotification* AppNotification::Copy() { 40 AppNotification* AppNotification::Copy() {
37 AppNotification* copy = new AppNotification( 41 AppNotification* copy = new AppNotification(
38 this->is_local(), this->guid(), this->extension_id(), 42 this->is_local(), this->creation_time(),
43 this->guid(), this->extension_id(),
39 this->title(), this->body()); 44 this->title(), this->body());
40 copy->set_link_url(this->link_url()); 45 copy->set_link_url(this->link_url());
41 copy->set_link_text(this->link_text()); 46 copy->set_link_text(this->link_text());
42 return copy; 47 return copy;
43 } 48 }
44 49
45 void AppNotification::ToDictionaryValue(DictionaryValue* result) { 50 void AppNotification::ToDictionaryValue(DictionaryValue* result) {
46 CHECK(result); 51 CHECK(result);
47 result->SetBoolean(kIsLocalKey, is_local_); 52 result->SetBoolean(kIsLocalKey, is_local_);
53 if (creation_time_.is_null())
asargent_no_longer_on_chrome 2011/11/17 23:40:14 did you mean "if (!creation_time_.is_null())" ?
elvin 2011/11/18 00:10:18 Done.
54 result->SetString(kCreationTime,
55 base::Int64ToString(creation_time_.ToInternalValue()));
48 if (!guid_.empty()) 56 if (!guid_.empty())
49 result->SetString(kGuidKey, guid_); 57 result->SetString(kGuidKey, guid_);
50 if (!extension_id_.empty()) 58 if (!extension_id_.empty())
51 result->SetString(kExtensionIdKey, extension_id_); 59 result->SetString(kExtensionIdKey, extension_id_);
52 if (!title_.empty()) 60 if (!title_.empty())
53 result->SetString(kTitleKey, title_); 61 result->SetString(kTitleKey, title_);
54 if (!body_.empty()) 62 if (!body_.empty())
55 result->SetString(kBodyKey, body_); 63 result->SetString(kBodyKey, body_);
56 if (!link_url_.is_empty()) 64 if (!link_url_.is_empty())
57 result->SetString(kLinkUrlKey, link_url_.possibly_invalid_spec()); 65 result->SetString(kLinkUrlKey, link_url_.possibly_invalid_spec());
58 if (!link_text_.empty()) 66 if (!link_text_.empty())
59 result->SetString(kLinkTextKey, link_text_); 67 result->SetString(kLinkTextKey, link_text_);
60 } 68 }
61 69
62 // static 70 // static
63 AppNotification* AppNotification::FromDictionaryValue( 71 AppNotification* AppNotification::FromDictionaryValue(
64 const DictionaryValue& value) { 72 const DictionaryValue& value) {
65 scoped_ptr<AppNotification> result(new AppNotification(true, "", "", "", "")); 73 scoped_ptr<AppNotification> result(
74 new AppNotification(true,
75 base::Time::FromInternalValue(0), "", "", "", ""));
66 76
67 if (value.HasKey(kIsLocalKey) && !value.GetBoolean( 77 if (value.HasKey(kIsLocalKey) && !value.GetBoolean(
68 kIsLocalKey, &result->is_local_)) { 78 kIsLocalKey, &result->is_local_)) {
69 return NULL; 79 return NULL;
70 } 80 }
81 if (value.HasKey(kCreationTime)) {
82 std::string time_string;
83 if (!value.GetString(kLinkUrlKey, &time_string))
84 return NULL;
85 int64 time_internal;
86 if (!base::StringToInt64(time_string, &time_internal)) {
87 return NULL;
88 }
89 base::Time time = base::Time::FromInternalValue(time_internal);
90 if (time.is_null()) {
91 return NULL;
92 }
93 result->set_creation_time(time);
94 } else {
95 return NULL;
96 }
97
71 if (value.HasKey(kGuidKey) && !value.GetString(kGuidKey, &result->guid_)) 98 if (value.HasKey(kGuidKey) && !value.GetString(kGuidKey, &result->guid_))
72 return NULL; 99 return NULL;
73 if (value.HasKey(kExtensionIdKey) && 100 if (value.HasKey(kExtensionIdKey) &&
74 !value.GetString(kExtensionIdKey, &result->extension_id_)) 101 !value.GetString(kExtensionIdKey, &result->extension_id_))
75 return NULL; 102 return NULL;
76 if (value.HasKey(kTitleKey) && !value.GetString(kTitleKey, &result->title_)) 103 if (value.HasKey(kTitleKey) && !value.GetString(kTitleKey, &result->title_))
77 return NULL; 104 return NULL;
78 if (value.HasKey(kBodyKey) && !value.GetString(kBodyKey, &result->body_)) 105 if (value.HasKey(kBodyKey) && !value.GetString(kBodyKey, &result->body_))
79 return NULL; 106 return NULL;
80 if (value.HasKey(kLinkUrlKey)) { 107 if (value.HasKey(kLinkUrlKey)) {
81 std::string url; 108 std::string url;
82 if (!value.GetString(kLinkUrlKey, &url)) 109 if (!value.GetString(kLinkUrlKey, &url))
83 return NULL; 110 return NULL;
84 GURL gurl(url); 111 GURL gurl(url);
85 if (!gurl.is_valid()) 112 if (!gurl.is_valid())
86 return NULL; 113 return NULL;
87 result->set_link_url(gurl); 114 result->set_link_url(gurl);
88 } 115 }
89 if (value.HasKey(kLinkTextKey) && 116 if (value.HasKey(kLinkTextKey) &&
90 !value.GetString(kLinkTextKey, &result->link_text_)) { 117 !value.GetString(kLinkTextKey, &result->link_text_)) {
91 return NULL; 118 return NULL;
92 } 119 }
93 120
94 return result.release(); 121 return result.release();
95 } 122 }
96 123
97 bool AppNotification::Equals(const AppNotification& other) const { 124 bool AppNotification::Equals(const AppNotification& other) const {
98 return (is_local_ == other.is_local_ && 125 return (is_local_ == other.is_local_ &&
126 creation_time_.ToInternalValue() ==
127 other.creation_time_.ToInternalValue() &&
asargent_no_longer_on_chrome 2011/11/17 23:40:14 nit: the Time class has an operator== method, so y
elvin 2011/11/18 00:10:18 Done.
99 guid_ == other.guid_ && 128 guid_ == other.guid_ &&
100 extension_id_ == other.extension_id_ && 129 extension_id_ == other.extension_id_ &&
101 title_ == other.title_ && 130 title_ == other.title_ &&
102 body_ == other.body_ && 131 body_ == other.body_ &&
103 link_url_ == other.link_url_ && 132 link_url_ == other.link_url_ &&
104 link_text_ == other.link_text_); 133 link_text_ == other.link_text_);
105 } 134 }
106 135
107 AppNotificationList* CopyAppNotificationList( 136 AppNotificationList* CopyAppNotificationList(
108 const AppNotificationList& source) { 137 const AppNotificationList& source) {
109 AppNotificationList* copy = new AppNotificationList(); 138 AppNotificationList* copy = new AppNotificationList();
110 139
111 for (AppNotificationList::const_iterator iter = source.begin(); 140 for (AppNotificationList::const_iterator iter = source.begin();
112 iter != source.end(); ++iter) { 141 iter != source.end(); ++iter) {
113 copy->push_back(linked_ptr<AppNotification>(iter->get()->Copy())); 142 copy->push_back(linked_ptr<AppNotification>(iter->get()->Copy()));
114 } 143 }
115 return copy; 144 return copy;
116 } 145 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698