diff options
author | asargent@chromium.org <asargent@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-05 05:13:15 +0000 |
---|---|---|
committer | asargent@chromium.org <asargent@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-05 05:13:15 +0000 |
commit | af9db5fc79084fe986cf51ccc8b3475a5a4ef76f (patch) | |
tree | 119a36be14a106056ddf2e03e4c68c8baddd8977 /chrome/browser/extensions/app_notification.cc | |
parent | 38476438089c4ddba8b698a29e1ea57cea61f90c (diff) | |
download | chromium_src-af9db5fc79084fe986cf51ccc8b3475a5a4ef76f.zip chromium_src-af9db5fc79084fe986cf51ccc8b3475a5a4ef76f.tar.gz chromium_src-af9db5fc79084fe986cf51ccc8b3475a5a4ef76f.tar.bz2 |
Persist App Notifications to disk
BUG=98138
TEST=Install a packaged app with the experimental permission, and have it call
chrome.experimental.app.notify({title:"foo", bodyText:"bar"}) from one of its
pages. That should make a notification appear on its icon on the NTP. After
restarting chrome, that same notification should still be there.
Review URL: http://codereview.chromium.org/8038040
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@104066 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/app_notification.cc')
-rw-r--r-- | chrome/browser/extensions/app_notification.cc | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/chrome/browser/extensions/app_notification.cc b/chrome/browser/extensions/app_notification.cc index b54568b..f8e60e3 100644 --- a/chrome/browser/extensions/app_notification.cc +++ b/chrome/browser/extensions/app_notification.cc @@ -4,8 +4,64 @@ #include "chrome/browser/extensions/app_notification.h" +#include "base/memory/scoped_ptr.h" + AppNotification::AppNotification(const std::string& title, const std::string& body) : title_(title), body_(body) {} AppNotification::~AppNotification() {} + +namespace { + +const char* kTitleKey = "title"; +const char* kBodyKey = "body"; +const char* kLinkUrlKey = "link_url"; +const char* kLinkTextKey = "link_text"; + +} // namespace + +void AppNotification::ToDictionaryValue(DictionaryValue* result) { + CHECK(result); + if (!title_.empty()) + result->SetString(kTitleKey, title_); + if (!body_.empty()) + result->SetString(kBodyKey, body_); + if (!link_url_.is_empty()) { + result->SetString(kLinkUrlKey, link_url_.possibly_invalid_spec()); + result->SetString(kLinkTextKey, link_text_); + } +} + +// static +AppNotification* AppNotification::FromDictionaryValue( + const DictionaryValue& value) { + + scoped_ptr<AppNotification> result(new AppNotification("", "")); + + if (value.HasKey(kTitleKey) && !value.GetString(kTitleKey, &result->title_)) + return NULL; + if (value.HasKey(kBodyKey) && !value.GetString(kBodyKey, &result->body_)) + return NULL; + if (value.HasKey(kLinkUrlKey)) { + if (!value.HasKey(kLinkTextKey)) + return NULL; + std::string url; + if (!value.GetString(kLinkUrlKey, &url) || + !value.GetString(kLinkTextKey, &result->link_text_)) + return NULL; + GURL gurl(url); + if (!gurl.is_valid()) + return NULL; + result->set_link_url(gurl); + } + + return result.release(); +} + +bool AppNotification::Equals(const AppNotification& other) const { + return (title_ == other.title_ && + body_ == other.body_ && + link_url_ == other.link_url_ && + link_text_ == other.link_text_); +} |