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

Side by Side Diff: chrome/browser/notifications/sync_notifier/synced_notification_app_info.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: CR fixes per DewittJ 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/notifications/sync_notifier/synced_notification_app_inf o.h" 5 #include "chrome/browser/notifications/sync_notifier/synced_notification_app_inf o.h"
6 6
7 #include "chrome/browser/notifications/sync_notifier/synced_notification_app_inf o_service.h"
8 #include "chrome/browser/profiles/profile.h"
7 #include "sync/api/sync_data.h" 9 #include "sync/api/sync_data.h"
8 #include "sync/protocol/synced_notification_app_info_specifics.pb.h" 10 #include "sync/protocol/synced_notification_app_info_specifics.pb.h"
9 11
10 namespace notifier { 12 namespace notifier {
11 13
12 SyncedNotificationAppInfo::SyncedNotificationAppInfo( 14 SyncedNotificationAppInfo::SyncedNotificationAppInfo(
13 const std::string& settings_display_name) 15 Profile* const profile,
14 : settings_display_name_(settings_display_name) {} 16 const std::string& settings_display_name,
17 SyncedNotificationAppInfoService* synced_notification_app_info_service)
18 : profile_(profile),
19 settings_display_name_(settings_display_name),
20 settings_low_dpi_icon_fetched_(false),
21 settings_high_dpi_icon_fetched_(false),
22 monochrome_low_dpi_icon_fetched_(false),
23 monochrome_high_dpi_icon_fetched_(false),
24 welcome_low_dpi_icon_fetched_(false),
25 welcome_high_dpi_icon_fetched_(false),
26 synced_notification_app_info_service_(
27 synced_notification_app_info_service) {}
15 28
16 SyncedNotificationAppInfo::~SyncedNotificationAppInfo() {} 29 SyncedNotificationAppInfo::~SyncedNotificationAppInfo() {}
17 30
18 bool SyncedNotificationAppInfo::HasAppId(const std::string& app_id) { 31 bool SyncedNotificationAppInfo::HasAppId(const std::string& app_id) {
19 std::vector<std::string>::iterator it; 32 std::vector<std::string>::iterator it;
20 33
21 for (it = app_ids_.begin(); it != app_ids_.end(); ++it) { 34 for (it = app_ids_.begin(); it != app_ids_.end(); ++it) {
22 if (app_id == *it) 35 if (app_id == *it)
23 return true; 36 return true;
24 } 37 }
(...skipping 12 matching lines...) Expand all
37 std::vector<std::string>::iterator it; 50 std::vector<std::string>::iterator it;
38 51
39 for (it = app_ids_.begin(); it != app_ids_.end(); ++it) { 52 for (it = app_ids_.begin(); it != app_ids_.end(); ++it) {
40 if (app_id == *it) { 53 if (app_id == *it) {
41 app_ids_.erase(it); 54 app_ids_.erase(it);
42 return; 55 return;
43 } 56 }
44 } 57 }
45 } 58 }
46 59
47 void SyncedNotificationAppInfo::GetAppIdList( 60 std::vector<std::string> SyncedNotificationAppInfo::GetAppIdList() {
48 std::vector<std::string>* app_id_list) { 61 std::vector<std::string> app_id_list;
49 if (app_id_list == NULL)
50 return;
51
52 std::vector<std::string>::iterator it; 62 std::vector<std::string>::iterator it;
53 for (it = app_ids_.begin(); it != app_ids_.end(); ++it) { 63 for (it = app_ids_.begin(); it != app_ids_.end(); ++it) {
54 app_id_list->push_back(*it); 64 app_id_list.push_back(*it);
65 }
66
67 return app_id_list;
68 }
69
70 // Fill up the queue of bitmaps to fetch.
71 void SyncedNotificationAppInfo::QueueBitmapFetchJobs() {
72 // If there are no bitmaps to fetch, call OnBitmapFetchesDone.
73 if (settings_low_dpi_icon_url_.is_empty() &&
74 settings_high_dpi_icon_url_.is_empty() &&
75 monochrome_low_dpi_icon_url_.is_empty() &&
76 monochrome_high_dpi_icon_url_.is_empty() &&
77 welcome_low_dpi_icon_url_.is_empty() &&
78 welcome_high_dpi_icon_url_.is_empty()) {
79 if (synced_notification_app_info_service_ != NULL) {
80 synced_notification_app_info_service_->OnBitmapFetchesDone(
81 added_app_ids_, removed_app_ids_);
82 }
83 DVLOG(2) << "AppInfo object with no bitmaps, we should add some. "
84 << this->settings_display_name_;
85 return;
86 }
87
88 CreateBitmapFetcher(settings_low_dpi_icon_url_);
89 CreateBitmapFetcher(settings_high_dpi_icon_url_);
90 CreateBitmapFetcher(monochrome_low_dpi_icon_url_);
91 CreateBitmapFetcher(monochrome_high_dpi_icon_url_);
92 CreateBitmapFetcher(welcome_low_dpi_icon_url_);
93 CreateBitmapFetcher(welcome_high_dpi_icon_url_);
94 }
95
96 // If this bitmap has a valid GURL, create a fetcher for it.
97 void SyncedNotificationAppInfo::CreateBitmapFetcher(const GURL& url) {
98 // Check for dups, ignore any request for a dup.
99 ScopedVector<chrome::BitmapFetcher>::iterator iter;
100 for (iter = fetchers_.begin(); iter != fetchers_.end(); ++iter) {
101 if ((*iter)->url() == url)
102 return;
103 }
104
105 if (url.is_valid()) {
dewittj 2014/03/20 18:00:28 hm, possibly push this check above the loop to avo
Pete Williamson 2014/03/25 00:08:37 Instead, I pushed up the check into the calling fu
106 fetchers_.push_back(new chrome::BitmapFetcher(url, this));
107 DVLOG(2) << __FUNCTION__ << "Pushing bitmap " << url;
55 } 108 }
dewittj 2014/03/20 18:00:28 Should there be some sort of handler for bad URL?
Pete Williamson 2014/03/25 00:08:37 Fixed by pushing up the check into the caller.
Pete Williamson 2014/03/25 00:08:37 handler added in ImageHandler::ImageHandler()
56 } 109 }
57 110
111 // Start the bitmap fetching. When it is complete, the callback
112 // will notify the ChromeNotifierService of the new app info availablity.
113 void SyncedNotificationAppInfo::StartBitmapFetch() {
114 // Now that we have queued them all, start the fetching.
115 ScopedVector<chrome::BitmapFetcher>::iterator iter;
116 for (iter = fetchers_.begin(); iter != fetchers_.end(); ++iter) {
117 (*iter)->Start(profile_);
118 }
119 }
120
121 // Method inherited from BitmapFetcher delegate.
122 void SyncedNotificationAppInfo::OnFetchComplete(const GURL url,
123 const SkBitmap* bitmap) {
124 // TODO(petewil): Should I retry if a fetch fails?
125
126 // TODO(petewil):
127 // Use the ImageSkia functions instead and use 2.0 as scale for the hi dpi
128 // versions, then combine into one gfx::Image, which I pass to the
129 // Notification Center.
dewittj 2014/03/20 18:00:28 Let's actually do that here. CreateFrom1xBitmap i
Pete Williamson 2014/03/25 00:08:37 Done.
130
131 // Match the bitmap to the URL to put it into the right variable.
132 if (url == settings_low_dpi_icon_url_) {
133 settings_low_dpi_icon_fetched_ = true;
134 if (bitmap != NULL)
135 settings_low_dpi_icon_ = gfx::Image::CreateFrom1xBitmap(*bitmap);
136 } else if (url == settings_high_dpi_icon_url_) {
137 settings_high_dpi_icon_fetched_ = true;
138 if (bitmap != NULL)
139 settings_high_dpi_icon_ = gfx::Image::CreateFrom1xBitmap(*bitmap);
140 } else if (url == monochrome_low_dpi_icon_url_) {
141 monochrome_low_dpi_icon_fetched_ = true;
142 if (bitmap != NULL)
143 monochrome_low_dpi_icon_ = gfx::Image::CreateFrom1xBitmap(*bitmap);
144 } else if (url == monochrome_high_dpi_icon_url_) {
145 monochrome_high_dpi_icon_fetched_ = true;
146 if (bitmap != NULL)
147 monochrome_high_dpi_icon_ = gfx::Image::CreateFrom1xBitmap(*bitmap);
148 } else if (url == welcome_low_dpi_icon_url_) {
149 welcome_low_dpi_icon_fetched_ = true;
150 if (bitmap != NULL)
151 welcome_low_dpi_icon_ = gfx::Image::CreateFrom1xBitmap(*bitmap);
152 } else if (url == welcome_high_dpi_icon_url_) {
153 welcome_high_dpi_icon_fetched_ = true;
154 if (bitmap != NULL)
155 welcome_high_dpi_icon_ = gfx::Image::CreateFrom1xBitmap(*bitmap);
156 } else {
157 DVLOG(2) << __FUNCTION__ << "Unmatched bitmap arrived " << url;
158 }
159
160 // If all bitmaps are accounted for, time to notify the ChromeNotifierService,
161 // via the SyncedNotificationAppInfoService.
162 if (AreAllBitmapsFetched()) {
163 if (synced_notification_app_info_service_ != NULL) {
164 synced_notification_app_info_service_->OnBitmapFetchesDone(
165 added_app_ids_, removed_app_ids_);
166 }
167 }
168 }
169
170 // Check to see if we have responses for all the bitmaps we got a URL for.
171 bool SyncedNotificationAppInfo::AreAllBitmapsFetched() {
172 return ((settings_low_dpi_icon_url_.is_empty() ||
173 settings_low_dpi_icon_fetched_) &&
174 (settings_high_dpi_icon_url_.is_empty() ||
175 settings_high_dpi_icon_fetched_) &&
176 (monochrome_low_dpi_icon_url_.is_empty() ||
177 monochrome_low_dpi_icon_fetched_) &&
178 (monochrome_high_dpi_icon_url_.is_empty() ||
179 monochrome_high_dpi_icon_fetched_) &&
180 (welcome_low_dpi_icon_url_.is_empty() ||
181 welcome_low_dpi_icon_fetched_) &&
182 (welcome_high_dpi_icon_url_.is_empty() ||
183 welcome_high_dpi_icon_fetched_));
184 }
185
186 message_center::NotifierId SyncedNotificationAppInfo::GetNotifierId() {
187 return message_center::NotifierId(
188 message_center::NotifierId::SYNCED_NOTIFICATION_SERVICE,
189 settings_display_name_);
190 }
191
58 } // namespace notifier 192 } // namespace notifier
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698