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 // The ChromeNotifierService works together with sync to maintain the state of | 5 // The ChromeNotifierService works together with sync to maintain the state of |
6 // user notifications, which can then be presented in the notification center, | 6 // user notifications, which can then be presented in the notification center, |
7 // via the Notification UI Manager. | 7 // via the Notification UI Manager. |
8 | 8 |
9 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service.h" | 9 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service.h" |
10 | 10 |
11 #include <set> | 11 #include <set> |
12 #include <string> | 12 #include <string> |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "base/command_line.h" | 15 #include "base/command_line.h" |
16 #include "base/guid.h" | 16 #include "base/guid.h" |
17 #include "base/metrics/histogram.h" | 17 #include "base/metrics/histogram.h" |
18 #include "base/prefs/pref_service.h" | 18 #include "base/prefs/pref_service.h" |
19 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
20 #include "base/values.h" | 20 #include "base/values.h" |
21 #include "chrome/browser/notifications/desktop_notification_service.h" | 21 #include "chrome/browser/notifications/desktop_notification_service.h" |
22 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | 22 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
23 #include "chrome/browser/notifications/notification.h" | 23 #include "chrome/browser/notifications/notification.h" |
24 #include "chrome/browser/notifications/notification_ui_manager.h" | 24 #include "chrome/browser/notifications/notification_ui_manager.h" |
25 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_delegate.h" | 25 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_delegate.h" |
26 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service_fac tory.h" | 26 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service_fac tory.h" |
27 #include "chrome/browser/notifications/sync_notifier/synced_notification_app_inf o.h" | |
28 #include "chrome/browser/notifications/sync_notifier/synced_notification_app_inf o_service.h" | |
29 #include "chrome/browser/notifications/sync_notifier/synced_notification_app_inf o_service_factory.h" | |
27 #include "chrome/browser/notifications/sync_notifier/welcome_delegate.h" | 30 #include "chrome/browser/notifications/sync_notifier/welcome_delegate.h" |
28 #include "chrome/browser/profiles/profile.h" | 31 #include "chrome/browser/profiles/profile.h" |
29 #include "chrome/common/pref_names.h" | 32 #include "chrome/common/pref_names.h" |
30 #include "components/user_prefs/pref_registry_syncable.h" | 33 #include "components/user_prefs/pref_registry_syncable.h" |
31 #include "content/public/browser/browser_thread.h" | 34 #include "content/public/browser/browser_thread.h" |
32 #include "content/public/browser/user_metrics.h" | 35 #include "content/public/browser/user_metrics.h" |
33 #include "grit/generated_resources.h" | 36 #include "grit/generated_resources.h" |
34 #include "grit/theme_resources.h" | 37 #include "grit/theme_resources.h" |
35 #include "sync/api/sync_change.h" | 38 #include "sync/api/sync_change.h" |
36 #include "sync/api/sync_change_processor.h" | 39 #include "sync/api/sync_change_processor.h" |
37 #include "sync/api/sync_error_factory.h" | 40 #include "sync/api/sync_error_factory.h" |
38 #include "sync/protocol/sync.pb.h" | 41 #include "sync/protocol/sync.pb.h" |
39 #include "sync/protocol/synced_notification_specifics.pb.h" | 42 #include "sync/protocol/synced_notification_specifics.pb.h" |
40 #include "third_party/WebKit/public/web/WebTextDirection.h" | 43 #include "third_party/WebKit/public/web/WebTextDirection.h" |
41 #include "ui/base/l10n/l10n_util.h" | 44 #include "ui/base/l10n/l10n_util.h" |
42 #include "ui/base/resource/resource_bundle.h" | 45 #include "ui/base/resource/resource_bundle.h" |
43 #include "ui/message_center/notifier_settings.h" | 46 #include "ui/message_center/notifier_settings.h" |
44 #include "url/gurl.h" | 47 #include "url/gurl.h" |
45 | 48 |
46 using base::UserMetricsAction; | 49 using base::UserMetricsAction; |
47 | 50 |
48 namespace notifier { | 51 namespace notifier { |
49 const char kFirstSyncedNotificationServiceId[] = "Google+"; | 52 const char kFirstSyncedNotificationServiceId[] = "Google+"; |
50 const char kSyncedNotificationsWelcomeOrigin[] = | 53 const char kSyncedNotificationsWelcomeOrigin[] = |
51 "synced-notifications://welcome"; | 54 "synced-notifications://welcome"; |
52 | 55 |
53 // SyncedNotificationAppInfoTemp is a class that contains the information | |
54 // necessary to produce a welcome notification and the app badges for all synced | |
55 // notification. | |
56 // TODO(dewittj): Convert this into a sync protobuf-backed data structure. | |
57 class SyncedNotificationAppInfoTemp { | |
58 public: | |
59 explicit SyncedNotificationAppInfoTemp(const std::string& app_id, | |
60 const base::string16& service_name); | |
61 ~SyncedNotificationAppInfoTemp(); | |
62 | |
63 const std::string& app_id() const { return app_id_; } | |
64 const base::string16& service_name() const { return service_name_; } | |
65 const base::string16& title() const { return title_; } | |
66 | |
67 void set_icon(const gfx::Image& icon) { icon_ = icon; } | |
68 const gfx::Image& icon() const { return icon_; } | |
69 | |
70 void set_small_icon(const gfx::Image& small_icon) { | |
71 small_icon_ = small_icon; | |
72 } | |
73 const gfx::Image& small_icon() const { return small_icon_; } | |
74 | |
75 const message_center::NotifierId GetNotifierId() const; | |
76 | |
77 private: | |
78 std::string app_id_; | |
79 base::string16 service_name_; | |
80 gfx::Image icon_; | |
81 gfx::Image small_icon_; | |
82 base::string16 title_; | |
83 base::string16 message_; | |
84 }; | |
85 | |
86 SyncedNotificationAppInfoTemp::SyncedNotificationAppInfoTemp( | |
87 const std::string& app_id, | |
88 const base::string16& service_name) | |
89 : app_id_(app_id), service_name_(service_name) { | |
90 title_ = | |
91 l10n_util::GetStringFUTF16(IDS_NOTIFIER_WELCOME_TITLE, service_name_); | |
92 } | |
93 | |
94 SyncedNotificationAppInfoTemp::~SyncedNotificationAppInfoTemp() {} | |
95 | |
96 const message_center::NotifierId SyncedNotificationAppInfoTemp::GetNotifierId() | |
97 const { | |
98 return message_center::NotifierId( | |
99 message_center::NotifierId::SYNCED_NOTIFICATION_SERVICE, app_id()); | |
100 } | |
101 | |
102 bool ChromeNotifierService::avoid_bitmap_fetching_for_test_ = false; | 56 bool ChromeNotifierService::avoid_bitmap_fetching_for_test_ = false; |
103 | 57 |
104 ChromeNotifierService::ChromeNotifierService(Profile* profile, | 58 ChromeNotifierService::ChromeNotifierService(Profile* profile, |
105 NotificationUIManager* manager) | 59 NotificationUIManager* manager) |
106 : profile_(profile), | 60 : profile_(profile), |
107 notification_manager_(manager), | 61 notification_manager_(manager), |
108 synced_notification_first_run_(false) { | 62 synced_notification_first_run_(false) { |
109 SyncedNotificationAppInfoTemp* temp_app_info = | |
110 new SyncedNotificationAppInfoTemp( | |
111 kFirstSyncedNotificationServiceId, | |
112 l10n_util::GetStringUTF16(IDS_FIRST_SYNCED_NOTIFICATION_SERVICE_NAME)); | |
113 temp_app_info->set_small_icon( | |
114 ui::ResourceBundle::GetSharedInstance().GetImageNamed( | |
115 IDR_TEMPORARY_GOOGLE_PLUS_ICON)); | |
116 app_info_data_.push_back(temp_app_info); | |
117 | 63 |
118 InitializePrefs(); | 64 InitializePrefs(); |
65 | |
66 // Get a pointer to the app info service so we can get app info data. | |
67 synced_notification_app_info_service_ = | |
68 SyncedNotificationAppInfoServiceFactory::GetForProfile( | |
69 profile_, Profile::EXPLICIT_ACCESS); | |
70 | |
71 // TODO(petewil): The feature is dead if this fails, how loudly should I | |
72 // complain? Should we exit chrome? | |
73 if (NULL == synced_notification_app_info_service_) { | |
dewittj
2014/03/17 21:43:43
I think a DCHECK is appropriate here.
Pete Williamson
2014/03/21 01:22:31
Done.
| |
74 LOG(ERROR) << "No Synced Notification App Info Service available."; | |
75 } else { | |
76 synced_notification_app_info_service_->SetChromeNotifierService(this); | |
77 } | |
119 } | 78 } |
120 | 79 |
121 ChromeNotifierService::~ChromeNotifierService() {} | 80 ChromeNotifierService::~ChromeNotifierService() { |
81 if (synced_notification_app_info_service_) | |
82 synced_notification_app_info_service_->SetChromeNotifierService(NULL); | |
83 } | |
122 | 84 |
123 // Methods from BrowserContextKeyedService. | 85 // Methods from BrowserContextKeyedService. |
124 void ChromeNotifierService::Shutdown() {} | 86 void ChromeNotifierService::Shutdown() {} |
125 | 87 |
126 // syncer::SyncableService implementation. | 88 // syncer::SyncableService implementation. |
127 | 89 |
128 // This is called at startup to sync with the server. | 90 // This is called at startup to sync with the server. |
129 // This code is not thread safe. | 91 // This code is not thread safe. |
130 syncer::SyncMergeResult ChromeNotifierService::MergeDataAndStartSyncing( | 92 syncer::SyncMergeResult ChromeNotifierService::MergeDataAndStartSyncing( |
131 syncer::ModelType type, | 93 syncer::ModelType type, |
132 const syncer::SyncDataList& initial_sync_data, | 94 const syncer::SyncDataList& initial_sync_data, |
133 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, | 95 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, |
134 scoped_ptr<syncer::SyncErrorFactory> error_handler) { | 96 scoped_ptr<syncer::SyncErrorFactory> error_handler) { |
135 thread_checker_.CalledOnValidThread(); | 97 thread_checker_.CalledOnValidThread(); |
136 DCHECK_EQ(syncer::SYNCED_NOTIFICATIONS, type); | 98 DCHECK_EQ(syncer::SYNCED_NOTIFICATIONS, type); |
137 syncer::SyncMergeResult merge_result(syncer::SYNCED_NOTIFICATIONS); | 99 syncer::SyncMergeResult merge_result(syncer::SYNCED_NOTIFICATIONS); |
138 // A list of local changes to send up to the sync server. | 100 // A list of local changes to send up to the sync server. |
139 syncer::SyncChangeList new_changes; | 101 syncer::SyncChangeList new_changes; |
140 sync_processor_ = sync_processor.Pass(); | 102 sync_processor_ = sync_processor.Pass(); |
141 | 103 |
142 for (syncer::SyncDataList::const_iterator it = initial_sync_data.begin(); | 104 for (syncer::SyncDataList::const_iterator it = initial_sync_data.begin(); |
143 it != initial_sync_data.end(); ++it) { | 105 it != initial_sync_data.end(); ++it) { |
144 const syncer::SyncData& sync_data = *it; | 106 const syncer::SyncData& sync_data = *it; |
145 DCHECK_EQ(syncer::SYNCED_NOTIFICATIONS, sync_data.GetDataType()); | 107 DCHECK_EQ(syncer::SYNCED_NOTIFICATIONS, sync_data.GetDataType()); |
146 | 108 |
147 // Build a local notification object from the sync data. | 109 // Build a local notification object from the sync data. |
148 scoped_ptr<SyncedNotification> incoming(CreateNotificationFromSyncData( | 110 scoped_ptr<SyncedNotification> incoming(CreateNotificationFromSyncData( |
149 sync_data)); | 111 sync_data)); |
150 if (!incoming) { | 112 if (!incoming) { |
151 // TODO(petewil): Turn this into a NOTREACHED() call once we fix the | 113 NOTREACHED(); |
152 // underlying problem causing bad data. | |
dewittj
2014/03/17 21:43:43
What was the underlying problem?
dewittj
2014/03/25 22:31:13
Do you have an answer for this comment?
Pete Williamson
2014/03/26 18:12:55
Oops, my bad, sorry I missed it the first time. I
| |
153 LOG(WARNING) << "Badly formed sync data in incoming notification"; | |
154 continue; | 114 continue; |
155 } | 115 } |
156 | 116 |
157 // Process each incoming remote notification. | 117 // Process each incoming remote notification. |
158 const std::string& key = incoming->GetKey(); | 118 const std::string& key = incoming->GetKey(); |
159 DCHECK_GT(key.length(), 0U); | 119 DCHECK_GT(key.length(), 0U); |
160 SyncedNotification* found = FindNotificationById(key); | 120 SyncedNotification* found = FindNotificationById(key); |
161 | 121 |
162 if (NULL == found) { | 122 if (NULL == found) { |
163 // If there are no conflicts, copy in the data from remote. | 123 // If there are no conflicts, copy in the data from remote. |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
392 SyncedNotification* notification = *it; | 352 SyncedNotification* notification = *it; |
393 if (notification_id == notification->GetKey()) { | 353 if (notification_id == notification->GetKey()) { |
394 notification_data_.erase(it); | 354 notification_data_.erase(it); |
395 return; | 355 return; |
396 } | 356 } |
397 } | 357 } |
398 } | 358 } |
399 | 359 |
400 void ChromeNotifierService::GetSyncedNotificationServices( | 360 void ChromeNotifierService::GetSyncedNotificationServices( |
401 std::vector<message_center::Notifier*>* notifiers) { | 361 std::vector<message_center::Notifier*>* notifiers) { |
402 // TODO(mukai|petewil): Check the profile's eligibility before adding the | 362 // TODO(mukai|petewil): Check the profile's eligibility before adding the |
dewittj
2014/03/17 21:43:43
Does this TODO still apply?
Pete Williamson
2014/03/21 01:22:31
Yes. We have a bug tracking this. For instance,
| |
403 // sample app. | 363 // sample app. |
404 ScopedVector<SyncedNotificationAppInfoTemp>::iterator it = | 364 std::vector<std::string> sending_service_names; |
405 app_info_data_.begin(); | |
406 for (; it != app_info_data_.end(); ++it) { | |
407 SyncedNotificationAppInfoTemp* app_info = *it; | |
408 message_center::NotifierId notifier_id = app_info->GetNotifierId(); | |
409 | 365 |
410 // Enable or disable the sending service per saved settings. | 366 if (synced_notification_app_info_service_ == NULL) |
367 return; | |
368 | |
369 sending_service_names = | |
370 synced_notification_app_info_service_->GetAllSendingServiceNames(); | |
371 | |
372 for (size_t ii = 0; ii < sending_service_names.size(); ++ii) { | |
373 // Make a notifier ID corresponding to this sending service name. | |
374 message_center::NotifierId notifier_id = message_center::NotifierId( | |
375 message_center::NotifierId::SYNCED_NOTIFICATION_SERVICE, | |
376 sending_service_names[ii]); | |
377 | |
378 SyncedNotificationAppInfo* synced_notification_app_info = | |
379 synced_notification_app_info_service_-> | |
380 FindSyncedNotificationAppInfoByName(sending_service_names[ii]); | |
381 | |
382 // Enable or disable the sending service per saved preferences. | |
411 bool app_enabled = false; | 383 bool app_enabled = false; |
412 std::set<std::string>::iterator iter; | 384 std::set<std::string>::iterator iter; |
413 iter = find(enabled_sending_services_.begin(), | 385 iter = find(enabled_sending_services_.begin(), |
dewittj
2014/03/17 21:43:43
n^2 search in this array. Probably do better with
Pete Williamson
2014/03/21 01:22:31
Today the set is small, and it should be for the f
| |
414 enabled_sending_services_.end(), | 386 enabled_sending_services_.end(), |
415 notifier_id.id); | 387 notifier_id.id); |
416 app_enabled = iter != enabled_sending_services_.end(); | 388 app_enabled = iter != enabled_sending_services_.end(); |
417 | 389 |
418 message_center::Notifier* app_info_notifier = new message_center::Notifier( | 390 message_center::Notifier* app_info_notifier = new message_center::Notifier( |
419 notifier_id, app_info->service_name(), app_enabled); | 391 notifier_id, |
392 base::UTF8ToUTF16( | |
393 synced_notification_app_info->settings_display_name()), | |
394 app_enabled); | |
420 | 395 |
421 app_info_notifier->icon = app_info->small_icon(); | 396 app_info_notifier->icon = synced_notification_app_info->icon(); |
422 | 397 |
423 // |notifiers| takes ownership of |app_info_notifier|. | 398 // |notifiers| takes ownership of |app_info_notifier|. |
424 notifiers->push_back(app_info_notifier); | 399 notifiers->push_back(app_info_notifier); |
425 } | 400 } |
426 } | 401 } |
427 | 402 |
403 void ChromeNotifierService::SetAddedAppIds( | |
404 std::vector<std::string> added_app_ids) { | |
405 | |
406 std::vector<std::string>::const_iterator app_id_iter; | |
407 for (app_id_iter = added_app_ids.begin(); app_id_iter != added_app_ids.end(); | |
408 ++app_id_iter) { | |
409 // Make sure this is not a dup, if it is, do nothing. | |
410 // TODO(petewil): consider a case insensitive compare. | |
411 std::set<std::string>::iterator sending_service_iter; | |
412 sending_service_iter = enabled_sending_services_.find(*app_id_iter); | |
413 if (sending_service_iter != enabled_sending_services_.end()) | |
414 continue; | |
415 | |
416 // Find any newly enabled notifications and call display on them. | |
417 // Show the welcome toast if required. | |
418 ScopedVector<SyncedNotification>::iterator notification_iter; | |
419 for (notification_iter = notification_data_.begin(); | |
420 notification_iter != notification_data_.end(); | |
421 ++notification_iter) { | |
422 (*notification_iter)->ShowIfNewlyEnabled( | |
423 notification_manager_, this, profile_, *app_id_iter); | |
424 } | |
425 } | |
426 } | |
427 | |
428 void ChromeNotifierService::SetRemovedAppIds( | |
429 std::vector<std::string> removed_app_ids) { | |
430 // Remove from enabled sending services. | |
431 // Don't remove from initialized sending services. If it gets re-added later, | |
432 // we want to remember the user's decision, so we also leave prefs intact. | |
433 | |
434 // Find any displayed notifications and remove them from the notification | |
435 // center. | |
436 std::vector<std::string>::const_iterator app_id_iter; | |
437 for (app_id_iter = removed_app_ids.begin(); | |
438 app_id_iter != removed_app_ids.end(); | |
439 ++app_id_iter) { | |
440 // Find any newly disabled notifications and remove them. | |
441 ScopedVector<SyncedNotification>::iterator notification_iter; | |
442 for (notification_iter = notification_data_.begin(); | |
443 notification_iter != notification_data_.end(); | |
444 ++notification_iter) { | |
445 (*notification_iter)->HideIfNewlyRemoved( | |
446 notification_manager_, this, profile_, *app_id_iter); | |
447 } | |
448 } | |
449 } | |
450 | |
428 void ChromeNotifierService::MarkNotificationAsRead( | 451 void ChromeNotifierService::MarkNotificationAsRead( |
429 const std::string& key) { | 452 const std::string& key) { |
430 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 453 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
431 SyncedNotification* notification = FindNotificationById(key); | 454 SyncedNotification* notification = FindNotificationById(key); |
432 CHECK(notification != NULL); | 455 CHECK(notification != NULL); |
433 | 456 |
434 notification->NotificationHasBeenRead(); | 457 notification->NotificationHasBeenRead(); |
435 syncer::SyncChangeList new_changes; | 458 syncer::SyncChangeList new_changes; |
436 | 459 |
437 syncer::SyncData sync_data = CreateSyncDataFromNotification(*notification); | 460 syncer::SyncData sync_data = CreateSyncDataFromNotification(*notification); |
438 new_changes.push_back( | 461 new_changes.push_back( |
439 syncer::SyncChange(FROM_HERE, | 462 syncer::SyncChange(FROM_HERE, |
440 syncer::SyncChange::ACTION_UPDATE, | 463 syncer::SyncChange::ACTION_UPDATE, |
441 sync_data)); | 464 sync_data)); |
442 | 465 |
443 // Send up the changes that were made locally. | 466 // Send up the changes that were made locally. |
444 sync_processor_->ProcessSyncChanges(FROM_HERE, new_changes); | 467 sync_processor_->ProcessSyncChanges(FROM_HERE, new_changes); |
445 } | 468 } |
446 | 469 |
447 // Add a new notification to our data structure. This takes ownership | 470 // Add a new notification to our data structure. This takes ownership |
448 // of the passed in pointer. | 471 // of the passed in pointer. |
449 void ChromeNotifierService::Add(scoped_ptr<SyncedNotification> notification) { | 472 void ChromeNotifierService::Add(scoped_ptr<SyncedNotification> notification) { |
450 SyncedNotification* notification_copy = notification.get(); | 473 SyncedNotification* notification_copy = notification.get(); |
451 // Take ownership of the object and put it into our local storage. | 474 // Take ownership of the object and put it into our local storage. |
452 notification_data_.push_back(notification.release()); | 475 notification_data_.push_back(notification.release()); |
453 | 476 |
454 // If the user is not interested in this type of notification, ignore it. | 477 // If the user is not interested in this type of notification, ignore it. |
455 std::set<std::string>::iterator iter = | 478 std::string sending_service_id = GetSendingServiceId(notification_copy); |
456 find(enabled_sending_services_.begin(), | 479 std::set<std::string>::iterator iter = find(enabled_sending_services_.begin(), |
457 enabled_sending_services_.end(), | 480 enabled_sending_services_.end(), |
458 notification_copy->GetSendingServiceId()); | 481 sending_service_id); |
459 if (iter == enabled_sending_services_.end()) { | 482 if (iter == enabled_sending_services_.end()) { |
460 iter = find(initialized_sending_services_.begin(), | 483 iter = find(initialized_sending_services_.begin(), |
461 initialized_sending_services_.end(), | 484 initialized_sending_services_.end(), |
462 notification_copy->GetSendingServiceId()); | 485 sending_service_id); |
463 if (iter != initialized_sending_services_.end()) | 486 if (iter != initialized_sending_services_.end()) |
464 return; | 487 return; |
465 } | 488 } |
466 | 489 |
467 UpdateInMessageCenter(notification_copy); | 490 UpdateInMessageCenter(notification_copy); |
468 } | 491 } |
469 | 492 |
493 std::string ChromeNotifierService::GetSendingServiceId( | |
494 const SyncedNotification* synced_notification) { | |
495 // Get the App Id from the notification, and look it up in the synced | |
496 // notification app info service. | |
497 std::string app_id = synced_notification->GetAppId(); | |
498 | |
499 if (synced_notification_app_info_service_ == NULL) | |
500 return std::string(); | |
dewittj
2014/03/17 21:43:43
Is this ever expected to happen? Please document
Pete Williamson
2014/03/21 01:22:31
It should never be able to happen. I replaced the
| |
501 | |
502 return synced_notification_app_info_service_->FindSendingServiceNameFromAppId( | |
503 app_id); | |
504 } | |
505 | |
470 void ChromeNotifierService::AddForTest( | 506 void ChromeNotifierService::AddForTest( |
471 scoped_ptr<notifier::SyncedNotification> notification) { | 507 scoped_ptr<notifier::SyncedNotification> notification) { |
472 notification_data_.push_back(notification.release()); | 508 notification_data_.push_back(notification.release()); |
473 } | 509 } |
474 | 510 |
475 void ChromeNotifierService::UpdateInMessageCenter( | 511 void ChromeNotifierService::UpdateInMessageCenter( |
476 SyncedNotification* notification) { | 512 SyncedNotification* notification) { |
477 // If the feature is disabled, exit now. | 513 // If the feature is disabled, exit now. |
478 if (!notifier::ChromeNotifierServiceFactory::UseSyncedNotifications( | 514 if (!notifier::ChromeNotifierServiceFactory::UseSyncedNotifications( |
479 CommandLine::ForCurrentProcess())) | 515 CommandLine::ForCurrentProcess())) |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
601 list_value->Append(string_value); | 637 list_value->Append(string_value); |
602 } | 638 } |
603 } | 639 } |
604 | 640 |
605 void ChromeNotifierService::DisplayUnreadNotificationsFromSource( | 641 void ChromeNotifierService::DisplayUnreadNotificationsFromSource( |
606 const std::string& notifier_id) { | 642 const std::string& notifier_id) { |
607 for (std::vector<SyncedNotification*>::const_iterator iter = | 643 for (std::vector<SyncedNotification*>::const_iterator iter = |
608 notification_data_.begin(); | 644 notification_data_.begin(); |
609 iter != notification_data_.end(); | 645 iter != notification_data_.end(); |
610 ++iter) { | 646 ++iter) { |
611 if ((*iter)->GetSendingServiceId() == notifier_id && | 647 if (GetSendingServiceId(*iter) == notifier_id && |
612 (*iter)->GetReadState() == SyncedNotification::kUnread) | 648 (*iter)->GetReadState() == SyncedNotification::kUnread) |
613 Display(*iter); | 649 Display(*iter); |
614 } | 650 } |
615 } | 651 } |
616 | 652 |
617 void ChromeNotifierService::RemoveUnreadNotificationsFromSource( | 653 void ChromeNotifierService::RemoveUnreadNotificationsFromSource( |
618 const std::string& notifier_id) { | 654 const std::string& notifier_id) { |
619 for (std::vector<SyncedNotification*>::const_iterator iter = | 655 for (std::vector<SyncedNotification*>::const_iterator iter = |
620 notification_data_.begin(); | 656 notification_data_.begin(); |
621 iter != notification_data_.end(); | 657 iter != notification_data_.end(); |
622 ++iter) { | 658 ++iter) { |
623 if ((*iter)->GetSendingServiceId() == notifier_id && | 659 if (GetSendingServiceId(*iter) == notifier_id && |
624 (*iter)->GetReadState() == SyncedNotification::kUnread) { | 660 (*iter)->GetReadState() == SyncedNotification::kUnread) { |
625 notification_manager_->CancelById((*iter)->GetKey()); | 661 notification_manager_->CancelById((*iter)->GetKey()); |
626 } | 662 } |
627 } | 663 } |
628 } | 664 } |
629 | 665 |
630 void ChromeNotifierService::OnEnabledSendingServiceListPrefChanged( | 666 void ChromeNotifierService::OnEnabledSendingServiceListPrefChanged( |
631 std::set<std::string>* ids_field) { | 667 std::set<std::string>* ids_field) { |
632 ids_field->clear(); | 668 ids_field->clear(); |
633 const std::vector<std::string> pref_list = | 669 const std::vector<std::string> pref_list = |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
709 OnInitializedSendingServiceListPrefChanged(&initialized_sending_services_); | 745 OnInitializedSendingServiceListPrefChanged(&initialized_sending_services_); |
710 | 746 |
711 synced_notification_first_run_ = | 747 synced_notification_first_run_ = |
712 profile_->GetPrefs()->GetBoolean(prefs::kSyncedNotificationFirstRun); | 748 profile_->GetPrefs()->GetBoolean(prefs::kSyncedNotificationFirstRun); |
713 } | 749 } |
714 | 750 |
715 void ChromeNotifierService::ShowWelcomeToastIfNecessary( | 751 void ChromeNotifierService::ShowWelcomeToastIfNecessary( |
716 const SyncedNotification* synced_notification, | 752 const SyncedNotification* synced_notification, |
717 NotificationUIManager* notification_ui_manager) { | 753 NotificationUIManager* notification_ui_manager) { |
718 const std::string& sending_service_id = | 754 const std::string& sending_service_id = |
719 synced_notification->GetSendingServiceId(); | 755 GetSendingServiceId(synced_notification); |
720 | 756 |
721 std::set<std::string>::iterator iter; | 757 std::set<std::string>::iterator iter; |
722 iter = find(initialized_sending_services_.begin(), | 758 iter = find(initialized_sending_services_.begin(), |
723 initialized_sending_services_.end(), | 759 initialized_sending_services_.end(), |
724 sending_service_id); | 760 sending_service_id); |
725 | 761 |
726 // If we already initialized the sending service, then return early since no | 762 // If we already initialized the sending service, then return early since no |
727 // welcome toast is necessary. | 763 // welcome toast is necessary. |
728 if (iter != initialized_sending_services_.end()) | 764 if (iter != initialized_sending_services_.end()) |
729 return; | 765 return; |
730 | 766 |
731 // If there is no app info, we can't show a welcome toast. Ideally all synced | 767 // If there is no app info, we can't show a welcome toast. Ideally all synced |
732 // notifications will be delayed until an app_info data structure can be | 768 // notifications will be delayed until an app_info data structure can be |
733 // constructed for them. | 769 // constructed for them. |
734 // TODO(dewittj): Refactor when app_info is populated asynchronously. | 770 notifier::SyncedNotificationAppInfo* app_info = |
dewittj
2014/03/17 21:43:43
Does the comment still need addressing? Is there
Pete Williamson
2014/03/21 01:22:31
Changed the comment to clarify that we have addres
| |
735 SyncedNotificationAppInfoTemp* app_info = FindAppInfo(sending_service_id); | 771 FindAppInfoByAppId(synced_notification->GetAppId()); |
736 if (!app_info) | 772 if (!app_info) |
737 return; | 773 return; |
738 | 774 |
739 // TODO(dewittj): Ensure that the app info icon is set before this point. | 775 if (app_info->settings_icon_url().is_empty()) { |
740 if (app_info->icon().IsEmpty()) { | |
741 gfx::Image notification_app_icon = synced_notification->GetAppIcon(); | 776 gfx::Image notification_app_icon = synced_notification->GetAppIcon(); |
742 if (!notification_app_icon.IsEmpty()) { | 777 if (notification_app_icon.IsEmpty()) { |
743 app_info->set_icon(notification_app_icon); | |
744 } else { | |
745 // This block should only be reached in tests since the downloads are | 778 // This block should only be reached in tests since the downloads are |
746 // already finished for |synced_notification|. | 779 // already finished for |synced_notification|. |
747 DVLOG(1) << "Unable to find the app icon for the welcome notification. " | 780 DVLOG(1) << "Unable to find the app icon for the welcome notification. " |
748 << "Service ID: " << sending_service_id; | 781 << "Service ID: " << sending_service_id; |
749 } | 782 } |
750 } | 783 } |
751 | 784 |
752 message_center::NotifierId notifier_id( | 785 message_center::NotifierId notifier_id( |
753 message_center::NotifierId::SYNCED_NOTIFICATION_SERVICE, | 786 message_center::NotifierId::SYNCED_NOTIFICATION_SERVICE, |
754 sending_service_id); | 787 sending_service_id); |
(...skipping 14 matching lines...) Expand all Loading... | |
769 profile_->GetPrefs()->Set(prefs::kEnabledSyncedNotificationSendingServices, | 802 profile_->GetPrefs()->Set(prefs::kEnabledSyncedNotificationSendingServices, |
770 enabled_sending_services); | 803 enabled_sending_services); |
771 // Mark any new services as initialized in preferences. | 804 // Mark any new services as initialized in preferences. |
772 BuildServiceListValueInplace(initialized_sending_services_, | 805 BuildServiceListValueInplace(initialized_sending_services_, |
773 &initialized_sending_services); | 806 &initialized_sending_services); |
774 profile_->GetPrefs()->Set( | 807 profile_->GetPrefs()->Set( |
775 prefs::kInitializedSyncedNotificationSendingServices, | 808 prefs::kInitializedSyncedNotificationSendingServices, |
776 initialized_sending_services); | 809 initialized_sending_services); |
777 } | 810 } |
778 | 811 |
779 SyncedNotificationAppInfoTemp* ChromeNotifierService::FindAppInfo( | 812 notifier::SyncedNotificationAppInfo* ChromeNotifierService::FindAppInfoByAppId( |
780 const std::string& app_id) const { | 813 const std::string& app_id) const { |
781 ScopedVector<SyncedNotificationAppInfoTemp>::const_iterator iter = | 814 if (NULL == synced_notification_app_info_service_) |
782 app_info_data_.begin(); | 815 return NULL; |
783 while (iter != app_info_data_.end()) { | |
784 if ((*iter)->app_id() == app_id) | |
785 return (*iter); | |
786 | 816 |
787 ++iter; | 817 return synced_notification_app_info_service_-> |
788 } | 818 FindSyncedNotificationAppInfoByAppId(app_id); |
789 | |
790 return NULL; | |
791 } | 819 } |
792 | 820 |
793 const Notification ChromeNotifierService::CreateWelcomeNotificationForService( | 821 const Notification ChromeNotifierService::CreateWelcomeNotificationForService( |
794 SyncedNotificationAppInfoTemp* app_info) { | 822 SyncedNotificationAppInfo* app_info) { |
795 std::string welcome_notification_id = base::GenerateGUID(); | 823 std::string welcome_notification_id = base::GenerateGUID(); |
796 scoped_refptr<WelcomeDelegate> delegate(new WelcomeDelegate( | 824 message_center::NotifierId notifier_id = message_center::NotifierId( |
dewittj
2014/03/17 21:43:43
Probably should make a SyncedNotificationAppInfo::
Pete Williamson
2014/03/21 01:22:31
Done.
| |
797 welcome_notification_id, profile_, app_info->GetNotifierId())); | 825 message_center::NotifierId::SYNCED_NOTIFICATION_SERVICE, |
826 app_info->settings_display_name()); | |
827 scoped_refptr<WelcomeDelegate> delegate( | |
828 new WelcomeDelegate(welcome_notification_id, profile_, notifier_id)); | |
798 | 829 |
799 message_center::ButtonInfo button_info( | 830 message_center::ButtonInfo button_info( |
800 l10n_util::GetStringUTF16(IDS_NOTIFIER_WELCOME_BUTTON)); | 831 l10n_util::GetStringUTF16(IDS_NOTIFIER_WELCOME_BUTTON)); |
801 button_info.icon = ui::ResourceBundle::GetSharedInstance().GetImageNamed( | 832 button_info.icon = ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
802 IDR_NOTIFIER_BLOCK_BUTTON); | 833 IDR_NOTIFIER_BLOCK_BUTTON); |
803 | 834 |
804 message_center::RichNotificationData rich_notification_data; | 835 message_center::RichNotificationData rich_notification_data; |
805 rich_notification_data.buttons.push_back(button_info); | 836 rich_notification_data.buttons.push_back(button_info); |
806 return Notification( | 837 return Notification( |
807 message_center::NOTIFICATION_TYPE_BASE_FORMAT, | 838 message_center::NOTIFICATION_TYPE_BASE_FORMAT, |
808 GURL(kSyncedNotificationsWelcomeOrigin), | 839 GURL(kSyncedNotificationsWelcomeOrigin), |
809 app_info->title(), | 840 base::UTF8ToUTF16(app_info->settings_display_name()), |
dewittj
2014/03/17 21:43:43
Has the encoding of this string been set before ha
Pete Williamson
2014/03/21 01:22:31
I'm not sure I understand the first question. The
dewittj
2014/03/25 22:31:13
I was just wondering if the expected encoding is e
Pete Williamson
2014/03/26 18:12:55
No, it is not defined in the protobuf, but IIRC, U
| |
810 l10n_util::GetStringUTF16(IDS_NOTIFIER_WELCOME_BODY), | 841 l10n_util::GetStringUTF16(IDS_NOTIFIER_WELCOME_BODY), |
811 app_info->icon(), | 842 app_info->icon(), |
812 blink::WebTextDirectionDefault, | 843 blink::WebTextDirectionDefault, |
813 app_info->GetNotifierId(), | 844 notifier_id, |
814 l10n_util::GetStringUTF16(IDS_NOTIFICATION_WELCOME_DISPLAY_SOURCE), | 845 l10n_util::GetStringUTF16(IDS_NOTIFICATION_WELCOME_DISPLAY_SOURCE), |
815 base::UTF8ToUTF16(welcome_notification_id), | 846 base::UTF8ToUTF16(welcome_notification_id), |
816 rich_notification_data, | 847 rich_notification_data, |
817 delegate.get()); | 848 delegate.get()); |
818 } | 849 } |
819 | 850 |
820 } // namespace notifier | 851 } // namespace notifier |
OLD | NEW |