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

Side by Side Diff: chrome/browser/notifications/sync_notifier/chrome_notifier_service.cc

Issue 193773003: Turn on and use the AppInfo data. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Turn on app info: another windows fix Created 6 years, 9 months 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) 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);
dewittj 2014/03/25 22:31:14 Based on the comments in Profile, I would expect y
Pete Williamson 2014/03/26 18:12:55 Done.
70
71 DCHECK(synced_notification_app_info_service_ != NULL);
72
73 synced_notification_app_info_service_->set_chrome_notifier_service(this);
74
119 } 75 }
120 76
121 ChromeNotifierService::~ChromeNotifierService() {} 77 ChromeNotifierService::~ChromeNotifierService() {
78 if (synced_notification_app_info_service_)
79 synced_notification_app_info_service_->set_chrome_notifier_service(NULL);
80 }
122 81
123 // Methods from BrowserContextKeyedService. 82 // Methods from BrowserContextKeyedService.
124 void ChromeNotifierService::Shutdown() {} 83 void ChromeNotifierService::Shutdown() {}
125 84
126 // syncer::SyncableService implementation. 85 // syncer::SyncableService implementation.
127 86
128 // This is called at startup to sync with the server. 87 // This is called at startup to sync with the server.
129 // This code is not thread safe. 88 // This code is not thread safe.
130 syncer::SyncMergeResult ChromeNotifierService::MergeDataAndStartSyncing( 89 syncer::SyncMergeResult ChromeNotifierService::MergeDataAndStartSyncing(
131 syncer::ModelType type, 90 syncer::ModelType type,
132 const syncer::SyncDataList& initial_sync_data, 91 const syncer::SyncDataList& initial_sync_data,
133 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, 92 scoped_ptr<syncer::SyncChangeProcessor> sync_processor,
134 scoped_ptr<syncer::SyncErrorFactory> error_handler) { 93 scoped_ptr<syncer::SyncErrorFactory> error_handler) {
135 thread_checker_.CalledOnValidThread(); 94 thread_checker_.CalledOnValidThread();
136 DCHECK_EQ(syncer::SYNCED_NOTIFICATIONS, type); 95 DCHECK_EQ(syncer::SYNCED_NOTIFICATIONS, type);
137 syncer::SyncMergeResult merge_result(syncer::SYNCED_NOTIFICATIONS); 96 syncer::SyncMergeResult merge_result(syncer::SYNCED_NOTIFICATIONS);
138 // A list of local changes to send up to the sync server. 97 // A list of local changes to send up to the sync server.
139 syncer::SyncChangeList new_changes; 98 syncer::SyncChangeList new_changes;
140 sync_processor_ = sync_processor.Pass(); 99 sync_processor_ = sync_processor.Pass();
141 100
142 for (syncer::SyncDataList::const_iterator it = initial_sync_data.begin(); 101 for (syncer::SyncDataList::const_iterator it = initial_sync_data.begin();
143 it != initial_sync_data.end(); ++it) { 102 it != initial_sync_data.end(); ++it) {
144 const syncer::SyncData& sync_data = *it; 103 const syncer::SyncData& sync_data = *it;
145 DCHECK_EQ(syncer::SYNCED_NOTIFICATIONS, sync_data.GetDataType()); 104 DCHECK_EQ(syncer::SYNCED_NOTIFICATIONS, sync_data.GetDataType());
146 105
147 // Build a local notification object from the sync data. 106 // Build a local notification object from the sync data.
148 scoped_ptr<SyncedNotification> incoming(CreateNotificationFromSyncData( 107 scoped_ptr<SyncedNotification> incoming(CreateNotificationFromSyncData(
149 sync_data)); 108 sync_data));
150 if (!incoming) { 109 if (!incoming) {
151 // TODO(petewil): Turn this into a NOTREACHED() call once we fix the 110 NOTREACHED();
152 // underlying problem causing bad data.
153 LOG(WARNING) << "Badly formed sync data in incoming notification";
154 continue; 111 continue;
155 } 112 }
156 113
157 // Process each incoming remote notification. 114 // Process each incoming remote notification.
158 const std::string& key = incoming->GetKey(); 115 const std::string& key = incoming->GetKey();
159 DCHECK_GT(key.length(), 0U); 116 DCHECK_GT(key.length(), 0U);
160 SyncedNotification* found = FindNotificationById(key); 117 SyncedNotification* found = FindNotificationById(key);
161 118
162 if (NULL == found) { 119 if (NULL == found) {
163 // If there are no conflicts, copy in the data from remote. 120 // If there are no conflicts, copy in the data from remote.
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 notification_data_.erase(it); 351 notification_data_.erase(it);
395 return; 352 return;
396 } 353 }
397 } 354 }
398 } 355 }
399 356
400 void ChromeNotifierService::GetSyncedNotificationServices( 357 void ChromeNotifierService::GetSyncedNotificationServices(
401 std::vector<message_center::Notifier*>* notifiers) { 358 std::vector<message_center::Notifier*>* notifiers) {
402 // TODO(mukai|petewil): Check the profile's eligibility before adding the 359 // TODO(mukai|petewil): Check the profile's eligibility before adding the
403 // sample app. 360 // sample app.
404 ScopedVector<SyncedNotificationAppInfoTemp>::iterator it = 361 std::vector<SyncedNotificationSendingServiceSettingsData>
405 app_info_data_.begin(); 362 sending_service_settings_data;
406 for (; it != app_info_data_.end(); ++it) {
407 SyncedNotificationAppInfoTemp* app_info = *it;
408 message_center::NotifierId notifier_id = app_info->GetNotifierId();
409 363
410 // Enable or disable the sending service per saved settings. 364 if (synced_notification_app_info_service_ == NULL)
365 return;
366
367 sending_service_settings_data =
368 synced_notification_app_info_service_->GetAllSendingServiceSettingsData();
369
370 for (size_t ii = 0; ii < sending_service_settings_data.size(); ++ii) {
371
372 // Enable or disable the sending service per saved preferences.
411 bool app_enabled = false; 373 bool app_enabled = false;
412 std::set<std::string>::iterator iter; 374 std::set<std::string>::iterator iter;
413 iter = find(enabled_sending_services_.begin(), 375 iter = find(enabled_sending_services_.begin(),
414 enabled_sending_services_.end(), 376 enabled_sending_services_.end(),
415 notifier_id.id); 377 sending_service_settings_data[ii].notifier_id.id);
416 app_enabled = iter != enabled_sending_services_.end(); 378 app_enabled = iter != enabled_sending_services_.end();
417 379
418 message_center::Notifier* app_info_notifier = new message_center::Notifier( 380 message_center::Notifier* app_info_notifier = new message_center::Notifier(
419 notifier_id, app_info->service_name(), app_enabled); 381 sending_service_settings_data[ii].notifier_id,
382 base::UTF8ToUTF16(
383 sending_service_settings_data[ii].settings_display_name),
384 app_enabled);
420 385
421 app_info_notifier->icon = app_info->small_icon(); 386 app_info_notifier->icon = sending_service_settings_data[ii].settings_icon;
422 387
423 // |notifiers| takes ownership of |app_info_notifier|. 388 // |notifiers| takes ownership of |app_info_notifier|.
424 notifiers->push_back(app_info_notifier); 389 notifiers->push_back(app_info_notifier);
425 } 390 }
426 } 391 }
427 392
393 void ChromeNotifierService::SetAddedAppIds(
394 std::vector<std::string> added_app_ids) {
395
396 std::vector<std::string>::const_iterator app_id_iter;
397 for (app_id_iter = added_app_ids.begin(); app_id_iter != added_app_ids.end();
398 ++app_id_iter) {
399 // Make sure this is not a dup, if it is, do nothing.
400 // TODO(petewil): consider a case insensitive compare.
401 std::set<std::string>::iterator sending_service_iter;
402 sending_service_iter = enabled_sending_services_.find(*app_id_iter);
403 if (sending_service_iter != enabled_sending_services_.end())
404 continue;
405
406 // Find any newly enabled notifications and call display on them.
407 // Show the welcome toast if required.
408 ScopedVector<SyncedNotification>::iterator notification_iter;
409 for (notification_iter = notification_data_.begin();
410 notification_iter != notification_data_.end();
411 ++notification_iter) {
412 (*notification_iter)->set_notifier_service(this);
dewittj 2014/03/25 22:31:14 The way you changed the call to ShowAllForAppId do
Pete Williamson 2014/03/26 18:12:55 Done.
413 (*notification_iter)->set_notification_manager(notification_manager_);
414 (*notification_iter)->ShowAllForAppId(profile_, *app_id_iter);
415 }
416 }
417 }
418
419 void ChromeNotifierService::SetRemovedAppIds(
420 std::vector<std::string> removed_app_ids) {
421 // Remove from enabled sending services.
422 // Don't remove from initialized sending services. If it gets re-added later,
423 // we want to remember the user's decision, so we also leave prefs intact.
424
425 // Find any displayed notifications and remove them from the notification
426 // center.
427 std::vector<std::string>::const_iterator app_id_iter;
428 for (app_id_iter = removed_app_ids.begin();
429 app_id_iter != removed_app_ids.end();
430 ++app_id_iter) {
431 // Find any newly disabled notifications and remove them.
432 ScopedVector<SyncedNotification>::iterator notification_iter;
433 for (notification_iter = notification_data_.begin();
434 notification_iter != notification_data_.end();
435 ++notification_iter) {
436 (*notification_iter)->set_notification_manager(notification_manager_);
437 (*notification_iter)->HideAllForAppId(*app_id_iter);
438 }
439 }
440 }
441
428 void ChromeNotifierService::MarkNotificationAsRead( 442 void ChromeNotifierService::MarkNotificationAsRead(
429 const std::string& key) { 443 const std::string& key) {
430 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 444 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
431 SyncedNotification* notification = FindNotificationById(key); 445 SyncedNotification* notification = FindNotificationById(key);
432 CHECK(notification != NULL); 446 CHECK(notification != NULL);
433 447
434 notification->NotificationHasBeenRead(); 448 notification->NotificationHasBeenRead();
435 syncer::SyncChangeList new_changes; 449 syncer::SyncChangeList new_changes;
436 450
437 syncer::SyncData sync_data = CreateSyncDataFromNotification(*notification); 451 syncer::SyncData sync_data = CreateSyncDataFromNotification(*notification);
438 new_changes.push_back( 452 new_changes.push_back(
439 syncer::SyncChange(FROM_HERE, 453 syncer::SyncChange(FROM_HERE,
440 syncer::SyncChange::ACTION_UPDATE, 454 syncer::SyncChange::ACTION_UPDATE,
441 sync_data)); 455 sync_data));
442 456
443 // Send up the changes that were made locally. 457 // Send up the changes that were made locally.
444 sync_processor_->ProcessSyncChanges(FROM_HERE, new_changes); 458 sync_processor_->ProcessSyncChanges(FROM_HERE, new_changes);
445 } 459 }
446 460
447 // Add a new notification to our data structure. This takes ownership 461 // Add a new notification to our data structure. This takes ownership
448 // of the passed in pointer. 462 // of the passed in pointer.
449 void ChromeNotifierService::Add(scoped_ptr<SyncedNotification> notification) { 463 void ChromeNotifierService::Add(scoped_ptr<SyncedNotification> notification) {
450 SyncedNotification* notification_copy = notification.get(); 464 SyncedNotification* notification_copy = notification.get();
451 // Take ownership of the object and put it into our local storage. 465 // Take ownership of the object and put it into our local storage.
452 notification_data_.push_back(notification.release()); 466 notification_data_.push_back(notification.release());
453 467
454 // If the user is not interested in this type of notification, ignore it. 468 // If the user is not interested in this type of notification, ignore it.
455 std::set<std::string>::iterator iter = 469 std::string sending_service_id = GetSendingServiceId(notification_copy);
456 find(enabled_sending_services_.begin(), 470 std::set<std::string>::iterator iter = find(enabled_sending_services_.begin(),
457 enabled_sending_services_.end(), 471 enabled_sending_services_.end(),
458 notification_copy->GetSendingServiceId()); 472 sending_service_id);
459 if (iter == enabled_sending_services_.end()) { 473 if (iter == enabled_sending_services_.end()) {
460 iter = find(initialized_sending_services_.begin(), 474 iter = find(initialized_sending_services_.begin(),
461 initialized_sending_services_.end(), 475 initialized_sending_services_.end(),
462 notification_copy->GetSendingServiceId()); 476 sending_service_id);
463 if (iter != initialized_sending_services_.end()) 477 if (iter != initialized_sending_services_.end())
464 return; 478 return;
465 } 479 }
466 480
467 UpdateInMessageCenter(notification_copy); 481 UpdateInMessageCenter(notification_copy);
468 } 482 }
469 483
484 std::string ChromeNotifierService::GetSendingServiceId(
485 const SyncedNotification* synced_notification) {
486 // Get the App Id from the notification, and look it up in the synced
487 // notification app info service.
488 std::string app_id = synced_notification->GetAppId();
489
490 DCHECK(synced_notification_app_info_service_ != NULL);
491
492 return synced_notification_app_info_service_->FindSendingServiceNameFromAppId(
493 app_id);
494 }
495
470 void ChromeNotifierService::AddForTest( 496 void ChromeNotifierService::AddForTest(
471 scoped_ptr<notifier::SyncedNotification> notification) { 497 scoped_ptr<notifier::SyncedNotification> notification) {
472 notification_data_.push_back(notification.release()); 498 notification_data_.push_back(notification.release());
473 } 499 }
474 500
501 void ChromeNotifierService::SetSyncedNotificationAppInfoServiceForTest(
502 SyncedNotificationAppInfoService* synced_notification_app_info_service) {
503 // If there already is a service attached, clear their reference to us.
504 if (synced_notification_app_info_service_)
505 synced_notification_app_info_service_->set_chrome_notifier_service(NULL);
506
507 synced_notification_app_info_service_ = synced_notification_app_info_service;
508 synced_notification_app_info_service_->set_chrome_notifier_service(this);
509 }
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()))
480 return; 516 return;
481 517
482 notification->LogNotification(); 518 notification->LogNotification();
483 519
484 if (notification->GetReadState() == SyncedNotification::kUnread) { 520 if (notification->GetReadState() == SyncedNotification::kUnread) {
(...skipping 10 matching lines...) Expand all
495 // If this is the first run for the feature, don't surprise the user. 531 // If this is the first run for the feature, don't surprise the user.
496 // Instead, place all backlogged notifications into the notification 532 // Instead, place all backlogged notifications into the notification
497 // center. 533 // center.
498 if (synced_notification_first_run_) { 534 if (synced_notification_first_run_) {
499 // Setting the toast state to false will prevent toasting the notification. 535 // Setting the toast state to false will prevent toasting the notification.
500 notification->SetToastState(false); 536 notification->SetToastState(false);
501 } 537 }
502 538
503 // Our tests cannot use the network for reliability reasons. 539 // Our tests cannot use the network for reliability reasons.
504 if (avoid_bitmap_fetching_for_test_) { 540 if (avoid_bitmap_fetching_for_test_) {
505 notification->Show(notification_manager_, this, profile_); 541 notification->set_notifier_service(this);
542 notification->set_notification_manager(notification_manager_);
543 notification->Show(profile_);
506 return; 544 return;
507 } 545 }
508 546
509 // Set up to fetch the bitmaps. 547 // Set up to fetch the bitmaps.
510 notification->QueueBitmapFetchJobs(notification_manager_, this, profile_); 548 notification->set_notification_manager(notification_manager_);
549 notification->QueueBitmapFetchJobs(this, profile_);
511 550
512 // Start the bitmap fetching, Show() will be called when the last bitmap 551 // Start the bitmap fetching, Show() will be called when the last bitmap
513 // either arrives or times out. 552 // either arrives or times out.
514 notification->StartBitmapFetch(); 553 notification->StartBitmapFetch();
515 } 554 }
516 555
517 void ChromeNotifierService::OnSyncedNotificationServiceEnabled( 556 void ChromeNotifierService::OnSyncedNotificationServiceEnabled(
518 const std::string& notifier_id, bool enabled) { 557 const std::string& notifier_id, bool enabled) {
519 std::set<std::string>::iterator iter; 558 std::set<std::string>::iterator iter;
520 559
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 list_value->Append(string_value); 640 list_value->Append(string_value);
602 } 641 }
603 } 642 }
604 643
605 void ChromeNotifierService::DisplayUnreadNotificationsFromSource( 644 void ChromeNotifierService::DisplayUnreadNotificationsFromSource(
606 const std::string& notifier_id) { 645 const std::string& notifier_id) {
607 for (std::vector<SyncedNotification*>::const_iterator iter = 646 for (std::vector<SyncedNotification*>::const_iterator iter =
608 notification_data_.begin(); 647 notification_data_.begin();
609 iter != notification_data_.end(); 648 iter != notification_data_.end();
610 ++iter) { 649 ++iter) {
611 if ((*iter)->GetSendingServiceId() == notifier_id && 650 if (GetSendingServiceId(*iter) == notifier_id &&
612 (*iter)->GetReadState() == SyncedNotification::kUnread) 651 (*iter)->GetReadState() == SyncedNotification::kUnread)
613 Display(*iter); 652 Display(*iter);
614 } 653 }
615 } 654 }
616 655
617 void ChromeNotifierService::RemoveUnreadNotificationsFromSource( 656 void ChromeNotifierService::RemoveUnreadNotificationsFromSource(
618 const std::string& notifier_id) { 657 const std::string& notifier_id) {
619 for (std::vector<SyncedNotification*>::const_iterator iter = 658 for (std::vector<SyncedNotification*>::const_iterator iter =
620 notification_data_.begin(); 659 notification_data_.begin();
621 iter != notification_data_.end(); 660 iter != notification_data_.end();
622 ++iter) { 661 ++iter) {
623 if ((*iter)->GetSendingServiceId() == notifier_id && 662 if (GetSendingServiceId(*iter) == notifier_id &&
624 (*iter)->GetReadState() == SyncedNotification::kUnread) { 663 (*iter)->GetReadState() == SyncedNotification::kUnread) {
625 notification_manager_->CancelById((*iter)->GetKey()); 664 notification_manager_->CancelById((*iter)->GetKey());
626 } 665 }
627 } 666 }
628 } 667 }
629 668
630 void ChromeNotifierService::OnEnabledSendingServiceListPrefChanged( 669 void ChromeNotifierService::OnEnabledSendingServiceListPrefChanged(
631 std::set<std::string>* ids_field) { 670 std::set<std::string>* ids_field) {
632 ids_field->clear(); 671 ids_field->clear();
633 const std::vector<std::string> pref_list = 672 const std::vector<std::string> pref_list =
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 OnInitializedSendingServiceListPrefChanged(&initialized_sending_services_); 748 OnInitializedSendingServiceListPrefChanged(&initialized_sending_services_);
710 749
711 synced_notification_first_run_ = 750 synced_notification_first_run_ =
712 profile_->GetPrefs()->GetBoolean(prefs::kSyncedNotificationFirstRun); 751 profile_->GetPrefs()->GetBoolean(prefs::kSyncedNotificationFirstRun);
713 } 752 }
714 753
715 void ChromeNotifierService::ShowWelcomeToastIfNecessary( 754 void ChromeNotifierService::ShowWelcomeToastIfNecessary(
716 const SyncedNotification* synced_notification, 755 const SyncedNotification* synced_notification,
717 NotificationUIManager* notification_ui_manager) { 756 NotificationUIManager* notification_ui_manager) {
718 const std::string& sending_service_id = 757 const std::string& sending_service_id =
719 synced_notification->GetSendingServiceId(); 758 GetSendingServiceId(synced_notification);
720 759
721 std::set<std::string>::iterator iter; 760 std::set<std::string>::iterator iter;
722 iter = find(initialized_sending_services_.begin(), 761 iter = find(initialized_sending_services_.begin(),
723 initialized_sending_services_.end(), 762 initialized_sending_services_.end(),
724 sending_service_id); 763 sending_service_id);
725 764
726 // If we already initialized the sending service, then return early since no 765 // If we already initialized the sending service, then return early since no
727 // welcome toast is necessary. 766 // welcome toast is necessary.
728 if (iter != initialized_sending_services_.end()) 767 if (iter != initialized_sending_services_.end())
729 return; 768 return;
730 769
731 // If there is no app info, we can't show a welcome toast. Ideally all synced 770 // If there is no app info, we can't show a welcome toast. All synced
732 // notifications will be delayed until an app_info data structure can be 771 // notifications will be delayed until an app_info data structure can be
733 // constructed for them. 772 // constructed for them.
734 // TODO(dewittj): Refactor when app_info is populated asynchronously. 773 notifier::SyncedNotificationAppInfo* app_info =
735 SyncedNotificationAppInfoTemp* app_info = FindAppInfo(sending_service_id); 774 FindAppInfoByAppId(synced_notification->GetAppId());
736 if (!app_info) 775 if (!app_info)
737 return; 776 return;
738 777
739 // TODO(dewittj): Ensure that the app info icon is set before this point. 778 if (app_info->settings_icon_url().is_empty()) {
740 if (app_info->icon().IsEmpty()) {
741 gfx::Image notification_app_icon = synced_notification->GetAppIcon(); 779 gfx::Image notification_app_icon = synced_notification->GetAppIcon();
742 if (!notification_app_icon.IsEmpty()) { 780 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 781 // This block should only be reached in tests since the downloads are
746 // already finished for |synced_notification|. 782 // already finished for |synced_notification|.
747 DVLOG(1) << "Unable to find the app icon for the welcome notification. " 783 DVLOG(1) << "Unable to find the app icon for the welcome notification. "
748 << "Service ID: " << sending_service_id; 784 << "Service ID: " << sending_service_id;
749 } 785 }
750 } 786 }
751 787
752 message_center::NotifierId notifier_id( 788 message_center::NotifierId notifier_id(
753 message_center::NotifierId::SYNCED_NOTIFICATION_SERVICE, 789 message_center::NotifierId::SYNCED_NOTIFICATION_SERVICE,
754 sending_service_id); 790 sending_service_id);
(...skipping 14 matching lines...) Expand all
769 profile_->GetPrefs()->Set(prefs::kEnabledSyncedNotificationSendingServices, 805 profile_->GetPrefs()->Set(prefs::kEnabledSyncedNotificationSendingServices,
770 enabled_sending_services); 806 enabled_sending_services);
771 // Mark any new services as initialized in preferences. 807 // Mark any new services as initialized in preferences.
772 BuildServiceListValueInplace(initialized_sending_services_, 808 BuildServiceListValueInplace(initialized_sending_services_,
773 &initialized_sending_services); 809 &initialized_sending_services);
774 profile_->GetPrefs()->Set( 810 profile_->GetPrefs()->Set(
775 prefs::kInitializedSyncedNotificationSendingServices, 811 prefs::kInitializedSyncedNotificationSendingServices,
776 initialized_sending_services); 812 initialized_sending_services);
777 } 813 }
778 814
779 SyncedNotificationAppInfoTemp* ChromeNotifierService::FindAppInfo( 815 notifier::SyncedNotificationAppInfo* ChromeNotifierService::FindAppInfoByAppId(
780 const std::string& app_id) const { 816 const std::string& app_id) const {
781 ScopedVector<SyncedNotificationAppInfoTemp>::const_iterator iter = 817 if (NULL == synced_notification_app_info_service_)
782 app_info_data_.begin(); 818 return NULL;
783 while (iter != app_info_data_.end()) {
784 if ((*iter)->app_id() == app_id)
785 return (*iter);
786 819
787 ++iter; 820 return synced_notification_app_info_service_->
788 } 821 FindSyncedNotificationAppInfoByAppId(app_id);
789
790 return NULL;
791 } 822 }
792 823
793 const Notification ChromeNotifierService::CreateWelcomeNotificationForService( 824 const Notification ChromeNotifierService::CreateWelcomeNotificationForService(
794 SyncedNotificationAppInfoTemp* app_info) { 825 SyncedNotificationAppInfo* app_info) {
795 std::string welcome_notification_id = base::GenerateGUID(); 826 std::string welcome_notification_id = base::GenerateGUID();
796 scoped_refptr<WelcomeDelegate> delegate(new WelcomeDelegate( 827 message_center::NotifierId notifier_id = app_info->GetNotifierId();
797 welcome_notification_id, profile_, app_info->GetNotifierId())); 828 scoped_refptr<WelcomeDelegate> delegate(
829 new WelcomeDelegate(welcome_notification_id, profile_, notifier_id));
798 830
799 message_center::ButtonInfo button_info( 831 message_center::ButtonInfo button_info(
800 l10n_util::GetStringUTF16(IDS_NOTIFIER_WELCOME_BUTTON)); 832 l10n_util::GetStringUTF16(IDS_NOTIFIER_WELCOME_BUTTON));
801 button_info.icon = ui::ResourceBundle::GetSharedInstance().GetImageNamed( 833 button_info.icon = ui::ResourceBundle::GetSharedInstance().GetImageNamed(
802 IDR_NOTIFIER_BLOCK_BUTTON); 834 IDR_NOTIFIER_BLOCK_BUTTON);
803 835
804 message_center::RichNotificationData rich_notification_data; 836 message_center::RichNotificationData rich_notification_data;
805 rich_notification_data.buttons.push_back(button_info); 837 rich_notification_data.buttons.push_back(button_info);
806 return Notification( 838 return Notification(
807 message_center::NOTIFICATION_TYPE_BASE_FORMAT, 839 message_center::NOTIFICATION_TYPE_BASE_FORMAT,
808 GURL(kSyncedNotificationsWelcomeOrigin), 840 GURL(kSyncedNotificationsWelcomeOrigin),
809 app_info->title(), 841 base::UTF8ToUTF16(app_info->settings_display_name()),
810 l10n_util::GetStringUTF16(IDS_NOTIFIER_WELCOME_BODY), 842 l10n_util::GetStringUTF16(IDS_NOTIFIER_WELCOME_BODY),
811 app_info->icon(), 843 app_info->icon(),
812 blink::WebTextDirectionDefault, 844 blink::WebTextDirectionDefault,
813 app_info->GetNotifierId(), 845 notifier_id,
814 l10n_util::GetStringUTF16(IDS_NOTIFICATION_WELCOME_DISPLAY_SOURCE), 846 l10n_util::GetStringUTF16(IDS_NOTIFICATION_WELCOME_DISPLAY_SOURCE),
815 base::UTF8ToUTF16(welcome_notification_id), 847 base::UTF8ToUTF16(welcome_notification_id),
816 rich_notification_data, 848 rich_notification_data,
817 delegate.get()); 849 delegate.get());
818 } 850 }
819 851
820 } // namespace notifier 852 } // namespace notifier
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698