OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_manager.h" | 5 #include "chrome/browser/extensions/app_notification_manager.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
12 #include "base/perftimer.h" | 12 #include "base/perftimer.h" |
13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
14 #include "base/time.h" | 14 #include "base/time.h" |
15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/sync/protocol/app_notification_specifics.pb.h" | 16 #include "chrome/browser/sync/protocol/app_notification_specifics.pb.h" |
| 17 #include "chrome/browser/sync/protocol/sync.pb.h" |
17 #include "chrome/common/chrome_notification_types.h" | 18 #include "chrome/common/chrome_notification_types.h" |
18 #include "chrome/common/extensions/extension.h" | 19 #include "chrome/common/extensions/extension.h" |
19 #include "content/public/browser/notification_service.h" | 20 #include "content/public/browser/notification_service.h" |
20 | 21 |
21 using content::BrowserThread; | 22 using content::BrowserThread; |
22 | 23 |
23 typedef std::map<std::string, SyncData> SyncDataMap; | 24 typedef std::map<std::string, SyncData> SyncDataMap; |
24 | 25 |
25 namespace { | 26 namespace { |
26 | 27 |
(...skipping 22 matching lines...) Expand all Loading... |
49 AppNotificationList::iterator iter = std::find_if( | 50 AppNotificationList::iterator iter = std::find_if( |
50 list->begin(), list->end(), std::bind2nd(GuidComparator(), guid)); | 51 list->begin(), list->end(), std::bind2nd(GuidComparator(), guid)); |
51 if (iter != list->end()) | 52 if (iter != list->end()) |
52 list->erase(iter); | 53 list->erase(iter); |
53 } | 54 } |
54 | 55 |
55 void PopulateGuidToSyncDataMap(const SyncDataList& sync_data, | 56 void PopulateGuidToSyncDataMap(const SyncDataList& sync_data, |
56 SyncDataMap* data_map) { | 57 SyncDataMap* data_map) { |
57 for (SyncDataList::const_iterator iter = sync_data.begin(); | 58 for (SyncDataList::const_iterator iter = sync_data.begin(); |
58 iter != sync_data.end(); ++iter) { | 59 iter != sync_data.end(); ++iter) { |
59 (*data_map)[iter->GetSpecifics().GetExtension( | 60 (*data_map)[iter->GetSpecifics().app_notification().guid()] = *iter; |
60 sync_pb::app_notification).guid()] = *iter; | |
61 } | 61 } |
62 } | 62 } |
63 } // namespace | 63 } // namespace |
64 | 64 |
65 const unsigned int AppNotificationManager::kMaxNotificationPerApp = 5; | 65 const unsigned int AppNotificationManager::kMaxNotificationPerApp = 5; |
66 | 66 |
67 AppNotificationManager::AppNotificationManager(Profile* profile) | 67 AppNotificationManager::AppNotificationManager(Profile* profile) |
68 : profile_(profile), | 68 : profile_(profile), |
69 sync_processor_(NULL), | 69 sync_processor_(NULL), |
70 models_associated_(false), | 70 models_associated_(false), |
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
508 content::Source<Profile>(profile_), | 508 content::Source<Profile>(profile_), |
509 content::Details<const std::string>(&extension_id)); | 509 content::Details<const std::string>(&extension_id)); |
510 } | 510 } |
511 | 511 |
512 // static | 512 // static |
513 SyncData AppNotificationManager::CreateSyncDataFromNotification( | 513 SyncData AppNotificationManager::CreateSyncDataFromNotification( |
514 const AppNotification& notification) { | 514 const AppNotification& notification) { |
515 DCHECK(!notification.is_local()); | 515 DCHECK(!notification.is_local()); |
516 sync_pb::EntitySpecifics specifics; | 516 sync_pb::EntitySpecifics specifics; |
517 sync_pb::AppNotification* notif_specifics = | 517 sync_pb::AppNotification* notif_specifics = |
518 specifics.MutableExtension(sync_pb::app_notification); | 518 specifics.mutable_app_notification(); |
519 notif_specifics->set_app_id(notification.extension_id()); | 519 notif_specifics->set_app_id(notification.extension_id()); |
520 notif_specifics->set_creation_timestamp_ms( | 520 notif_specifics->set_creation_timestamp_ms( |
521 notification.creation_time().ToInternalValue()); | 521 notification.creation_time().ToInternalValue()); |
522 notif_specifics->set_body_text(notification.body()); | 522 notif_specifics->set_body_text(notification.body()); |
523 notif_specifics->set_guid(notification.guid()); | 523 notif_specifics->set_guid(notification.guid()); |
524 notif_specifics->set_link_text(notification.link_text()); | 524 notif_specifics->set_link_text(notification.link_text()); |
525 notif_specifics->set_link_url(notification.link_url().spec()); | 525 notif_specifics->set_link_url(notification.link_url().spec()); |
526 notif_specifics->set_title(notification.title()); | 526 notif_specifics->set_title(notification.title()); |
527 return SyncData::CreateLocalData( | 527 return SyncData::CreateLocalData( |
528 notif_specifics->guid(), notif_specifics->app_id(), specifics); | 528 notif_specifics->guid(), notif_specifics->app_id(), specifics); |
529 } | 529 } |
530 | 530 |
531 // static | 531 // static |
532 AppNotification* AppNotificationManager::CreateNotificationFromSyncData( | 532 AppNotification* AppNotificationManager::CreateNotificationFromSyncData( |
533 const SyncData& sync_data) { | 533 const SyncData& sync_data) { |
534 sync_pb::AppNotification specifics = | 534 sync_pb::AppNotification specifics = |
535 sync_data.GetSpecifics().GetExtension(sync_pb::app_notification); | 535 sync_data.GetSpecifics().app_notification(); |
536 | 536 |
537 // Check for mandatory fields. | 537 // Check for mandatory fields. |
538 if (!specifics.has_app_id() || !specifics.has_guid() || | 538 if (!specifics.has_app_id() || !specifics.has_guid() || |
539 !specifics.has_title() || !specifics.has_body_text() || | 539 !specifics.has_title() || !specifics.has_body_text() || |
540 !specifics.has_creation_timestamp_ms()) { | 540 !specifics.has_creation_timestamp_ms()) { |
541 return NULL; | 541 return NULL; |
542 } | 542 } |
543 | 543 |
544 AppNotification* notification = new AppNotification( | 544 AppNotification* notification = new AppNotification( |
545 false, base::Time::FromInternalValue(specifics.creation_timestamp_ms()), | 545 false, base::Time::FromInternalValue(specifics.creation_timestamp_ms()), |
546 specifics.guid(), specifics.app_id(), | 546 specifics.guid(), specifics.app_id(), |
547 specifics.title(), specifics.body_text()); | 547 specifics.title(), specifics.body_text()); |
548 if (specifics.has_link_text()) | 548 if (specifics.has_link_text()) |
549 notification->set_link_text(specifics.link_text()); | 549 notification->set_link_text(specifics.link_text()); |
550 if (specifics.has_link_url()) | 550 if (specifics.has_link_url()) |
551 notification->set_link_url(GURL(specifics.link_url())); | 551 notification->set_link_url(GURL(specifics.link_url())); |
552 return notification; | 552 return notification; |
553 } | 553 } |
OLD | NEW |