OLD | NEW |
---|---|
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 23 matching lines...) Expand all Loading... | |
48 std::vector<std::string>* app_id_list) { | 61 std::vector<std::string>* app_id_list) { |
49 if (app_id_list == NULL) | 62 if (app_id_list == NULL) |
50 return; | 63 return; |
51 | 64 |
52 std::vector<std::string>::iterator it; | 65 std::vector<std::string>::iterator it; |
53 for (it = app_ids_.begin(); it != app_ids_.end(); ++it) { | 66 for (it = app_ids_.begin(); it != app_ids_.end(); ++it) { |
54 app_id_list->push_back(*it); | 67 app_id_list->push_back(*it); |
55 } | 68 } |
56 } | 69 } |
57 | 70 |
71 // Fill up the queue of bitmaps to fetch. | |
72 void SyncedNotificationAppInfo::QueueBitmapFetchJobs() { | |
73 // If there are no bitmaps to fetch, call OnBitmapFetchesDone. | |
74 if (settings_low_dpi_icon_url_.is_empty() && | |
75 settings_high_dpi_icon_url_.is_empty() && | |
76 monochrome_low_dpi_icon_url_.is_empty() && | |
77 monochrome_high_dpi_icon_url_.is_empty() && | |
78 welcome_low_dpi_icon_url_.is_empty() && | |
79 welcome_high_dpi_icon_url_.is_empty()) { | |
80 if (synced_notification_app_info_service_ != NULL) { | |
81 synced_notification_app_info_service_->OnBitmapFetchesDone( | |
82 added_app_ids_, removed_app_ids_); | |
83 } | |
84 DVLOG(2) << "AppInfo object with no bitmaps, we should add some. " | |
85 << this->settings_display_name_; | |
86 return; | |
87 } | |
88 | |
89 AddBitmapToFetchQueue(settings_low_dpi_icon_url_); | |
90 AddBitmapToFetchQueue(settings_high_dpi_icon_url_); | |
91 AddBitmapToFetchQueue(monochrome_low_dpi_icon_url_); | |
92 AddBitmapToFetchQueue(monochrome_high_dpi_icon_url_); | |
93 AddBitmapToFetchQueue(welcome_low_dpi_icon_url_); | |
94 AddBitmapToFetchQueue(welcome_high_dpi_icon_url_); | |
95 } | |
96 | |
97 // If this bitmap has a valid GURL, create a fetcher for it. | |
98 void SyncedNotificationAppInfo::AddBitmapToFetchQueue(const GURL& url) { | |
dewittj
2014/03/17 21:43:43
This is improperly named since there is not a queu
Pete Williamson
2014/03/21 01:22:31
Renamed to CreateBitmapFetcher everywhere.
| |
99 // Check for dups, ignore any request for a dup. | |
100 ScopedVector<chrome::BitmapFetcher>::iterator iter; | |
101 for (iter = fetchers_.begin(); iter != fetchers_.end(); ++iter) { | |
102 if ((*iter)->url() == url) | |
103 return; | |
104 } | |
105 | |
106 if (url.is_valid()) { | |
107 fetchers_.push_back(new chrome::BitmapFetcher(url, this)); | |
108 DVLOG(2) << __FUNCTION__ << "Pushing bitmap " << url; | |
109 } | |
110 } | |
111 | |
112 // Start the bitmap fetching. When it is complete, the callback | |
113 // will notify the ChromeNotifierService of the new app info availablity. | |
114 void SyncedNotificationAppInfo::StartBitmapFetch() { | |
115 // Now that we have queued them all, start the fetching. | |
116 ScopedVector<chrome::BitmapFetcher>::iterator iter; | |
117 for (iter = fetchers_.begin(); iter != fetchers_.end(); ++iter) { | |
118 (*iter)->Start(profile_); | |
119 } | |
120 } | |
121 | |
122 // Method inherited from BitmapFetcher delegate. | |
123 void SyncedNotificationAppInfo::OnFetchComplete(const GURL url, | |
124 const SkBitmap* bitmap) { | |
125 // TODO(petewil): Should I retry if a fetch fails? | |
126 | |
127 // TODO(petewil): | |
128 // Use the ImageSkia functions instead and use 2.0 as scale for the hi dpi | |
129 // versions, then combine into one gfx::Image, which I pass to the | |
130 // Notification Center. | |
131 | |
132 // Match the bitmap to the URL to put it into the right variable. | |
133 if (url == settings_low_dpi_icon_url_) { | |
134 settings_low_dpi_icon_fetched_ = true; | |
135 if (bitmap != NULL) | |
136 settings_low_dpi_icon_ = gfx::Image::CreateFrom1xBitmap(*bitmap); | |
137 } else if (url == settings_high_dpi_icon_url_) { | |
138 settings_high_dpi_icon_fetched_ = true; | |
139 if (bitmap != NULL) | |
140 settings_high_dpi_icon_ = gfx::Image::CreateFrom1xBitmap(*bitmap); | |
141 } else if (url == monochrome_low_dpi_icon_url_) { | |
142 monochrome_low_dpi_icon_fetched_ = true; | |
143 if (bitmap != NULL) | |
144 monochrome_low_dpi_icon_ = gfx::Image::CreateFrom1xBitmap(*bitmap); | |
145 } else if (url == monochrome_high_dpi_icon_url_) { | |
146 monochrome_high_dpi_icon_fetched_ = true; | |
147 if (bitmap != NULL) | |
148 monochrome_high_dpi_icon_ = gfx::Image::CreateFrom1xBitmap(*bitmap); | |
149 } else if (url == welcome_low_dpi_icon_url_) { | |
150 welcome_low_dpi_icon_fetched_ = true; | |
151 if (bitmap != NULL) | |
152 welcome_low_dpi_icon_ = gfx::Image::CreateFrom1xBitmap(*bitmap); | |
153 } else if (url == welcome_high_dpi_icon_url_) { | |
154 welcome_high_dpi_icon_fetched_ = true; | |
155 if (bitmap != NULL) | |
156 welcome_high_dpi_icon_ = gfx::Image::CreateFrom1xBitmap(*bitmap); | |
157 } else { | |
158 DVLOG(2) << __FUNCTION__ << "Unmatched bitmap arrived " << url; | |
159 } | |
160 | |
161 // If all bitmaps are accounted for, time to notify the ChromeNotifierService, | |
162 // via the SyncedNotificationAppInfoService. | |
163 if (AreAllBitmapsFetched()) { | |
164 if (synced_notification_app_info_service_ != NULL) { | |
165 synced_notification_app_info_service_->OnBitmapFetchesDone( | |
166 added_app_ids_, removed_app_ids_); | |
167 } | |
168 } | |
169 } | |
170 | |
171 // Check to see if we have responses for all the bitmaps we got a URL for. | |
172 bool SyncedNotificationAppInfo::AreAllBitmapsFetched() { | |
173 return ((settings_low_dpi_icon_url_.is_empty() || | |
174 settings_low_dpi_icon_fetched_) && | |
175 (settings_high_dpi_icon_url_.is_empty() || | |
176 settings_high_dpi_icon_fetched_) && | |
177 (monochrome_low_dpi_icon_url_.is_empty() || | |
178 monochrome_low_dpi_icon_fetched_) && | |
179 (monochrome_high_dpi_icon_url_.is_empty() || | |
180 monochrome_high_dpi_icon_fetched_) && | |
181 (welcome_low_dpi_icon_url_.is_empty() || | |
182 welcome_low_dpi_icon_fetched_) && | |
183 (welcome_high_dpi_icon_url_.is_empty() || | |
184 welcome_high_dpi_icon_fetched_)); | |
185 } | |
186 | |
58 } // namespace notifier | 187 } // namespace notifier |
OLD | NEW |