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

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: LGTM nits 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/image_holder.h"
8 #include "chrome/browser/notifications/sync_notifier/synced_notification_app_inf o_service.h"
9 #include "chrome/browser/profiles/profile.h"
7 #include "sync/api/sync_data.h" 10 #include "sync/api/sync_data.h"
8 #include "sync/protocol/synced_notification_app_info_specifics.pb.h" 11 #include "sync/protocol/synced_notification_app_info_specifics.pb.h"
9 12
10 namespace notifier { 13 namespace notifier {
11 14
12 SyncedNotificationAppInfo::SyncedNotificationAppInfo( 15 SyncedNotificationAppInfo::SyncedNotificationAppInfo(
13 const std::string& settings_display_name) 16 Profile* const profile,
14 : settings_display_name_(settings_display_name) {} 17 const std::string& settings_display_name,
18 SyncedNotificationAppInfoService* synced_notification_app_info_service)
19 : profile_(profile),
20 settings_display_name_(settings_display_name),
21 synced_notification_app_info_service_(
22 synced_notification_app_info_service) {}
15 23
16 SyncedNotificationAppInfo::~SyncedNotificationAppInfo() {} 24 SyncedNotificationAppInfo::~SyncedNotificationAppInfo() {}
17 25
26 GURL SyncedNotificationAppInfo::settings_icon_url() {
27 if (settings_holder_ != NULL)
28 return settings_holder_->low_dpi_url();
29 else
30 return GURL();
31 }
32
18 bool SyncedNotificationAppInfo::HasAppId(const std::string& app_id) { 33 bool SyncedNotificationAppInfo::HasAppId(const std::string& app_id) {
19 std::vector<std::string>::iterator it; 34 std::vector<std::string>::iterator it;
20 35
21 for (it = app_ids_.begin(); it != app_ids_.end(); ++it) { 36 for (it = app_ids_.begin(); it != app_ids_.end(); ++it) {
22 if (app_id == *it) 37 if (app_id == *it)
23 return true; 38 return true;
24 } 39 }
25 40
26 return false; 41 return false;
27 } 42 }
28 43
29 void SyncedNotificationAppInfo::AddAppId(const std::string& app_id) { 44 void SyncedNotificationAppInfo::AddAppId(const std::string& app_id) {
30 if (HasAppId(app_id)) 45 if (HasAppId(app_id))
31 return; 46 return;
32 47
33 app_ids_.push_back(app_id); 48 app_ids_.push_back(app_id);
34 } 49 }
35 50
36 void SyncedNotificationAppInfo::RemoveAppId(const std::string& app_id) { 51 void SyncedNotificationAppInfo::RemoveAppId(const std::string& app_id) {
37 std::vector<std::string>::iterator it; 52 std::vector<std::string>::iterator it;
38 53
39 for (it = app_ids_.begin(); it != app_ids_.end(); ++it) { 54 for (it = app_ids_.begin(); it != app_ids_.end(); ++it) {
40 if (app_id == *it) { 55 if (app_id == *it) {
41 app_ids_.erase(it); 56 app_ids_.erase(it);
42 return; 57 return;
43 } 58 }
44 } 59 }
45 } 60 }
46 61
47 void SyncedNotificationAppInfo::GetAppIdList( 62 void SyncedNotificationAppInfo::SetSettingsURLs(
48 std::vector<std::string>* app_id_list) { 63 const GURL& settings_low_dpi, const GURL& settings_high_dpi) {
49 if (app_id_list == NULL) 64 settings_holder_.reset(new ImageHolder(settings_low_dpi,
50 return; 65 settings_high_dpi,
66 profile_,
67 this));
68 }
51 69
70 void SyncedNotificationAppInfo::SetMonochromeURLs(
71 const GURL& monochrome_low_dpi, const GURL& monochrome_high_dpi) {
72 monochrome_holder_.reset(new ImageHolder(monochrome_low_dpi,
73 monochrome_high_dpi,
74 profile_,
75 this));
76 }
77
78 void SyncedNotificationAppInfo::SetWelcomeURLs(
79 const GURL& welcome_low_dpi, const GURL& welcome_high_dpi) {
80 welcome_holder_.reset(new ImageHolder(welcome_low_dpi,
81 welcome_high_dpi,
82 profile_,
83 this));
84 }
85
86 gfx::Image SyncedNotificationAppInfo::icon() {
87 if (settings_holder_ != NULL)
88 return settings_holder_->low_dpi_image();
89 else
90 return gfx::Image();
91 }
92
93 std::vector<std::string> SyncedNotificationAppInfo::GetAppIdList() {
94 std::vector<std::string> app_id_list;
52 std::vector<std::string>::iterator it; 95 std::vector<std::string>::iterator it;
53 for (it = app_ids_.begin(); it != app_ids_.end(); ++it) { 96 for (it = app_ids_.begin(); it != app_ids_.end(); ++it) {
54 app_id_list->push_back(*it); 97 app_id_list.push_back(*it);
98 }
99
100 return app_id_list;
101 }
102
103 // TODO: rename, queing now happens elsewhere.
104 // Fill up the queue of bitmaps to fetch.
105 void SyncedNotificationAppInfo::QueueBitmapFetchJobs() {
106 // If there are no bitmaps to fetch, call OnBitmapFetchesDone.
107 if (AreAllBitmapsFetched()) {
108 synced_notification_app_info_service_->OnBitmapFetchesDone(
109 added_app_ids_, removed_app_ids_);
110 DVLOG(2) << "AppInfo object with no bitmaps, we should add some. "
111 << this->settings_display_name_;
112 return;
55 } 113 }
56 } 114 }
57 115
116 // Start the bitmap fetching. When it is complete, the callback
117 // will notify the ChromeNotifierService of the new app info availablity.
118 void SyncedNotificationAppInfo::StartBitmapFetch() {
119 if (settings_holder_.get() != NULL)
120 settings_holder_->StartFetch();
121 if (monochrome_holder_.get() != NULL)
122 monochrome_holder_->StartFetch();
123 if (welcome_holder_.get() != NULL)
124 welcome_holder_->StartFetch();
125 }
126
127 // Method inherited from ImageHolderDelegate
128 void SyncedNotificationAppInfo::OnFetchComplete() {
129 if (AreAllBitmapsFetched()) {
130 if (synced_notification_app_info_service_ != NULL) {
131 synced_notification_app_info_service_->OnBitmapFetchesDone(
132 added_app_ids_, removed_app_ids_);
133 }
134 }
135 }
136
137 // Check to see if we have responses for all the bitmaps we got a URL for.
138 bool SyncedNotificationAppInfo::AreAllBitmapsFetched() {
139 bool done =
140 (settings_holder_.get() == NULL || settings_holder_->IsFetchingDone()) &&
141 (monochrome_holder_.get() == NULL ||
142 monochrome_holder_->IsFetchingDone()) &&
143 (welcome_holder_.get() == NULL || welcome_holder_->IsFetchingDone());
144
145 return done;
146 }
147
148 message_center::NotifierId SyncedNotificationAppInfo::GetNotifierId() {
149 return message_center::NotifierId(
150 message_center::NotifierId::SYNCED_NOTIFICATION_SERVICE,
151 settings_display_name_);
152 }
153
58 } // namespace notifier 154 } // namespace notifier
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698