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

Side by Side Diff: chrome/browser/background/background_application_list_model.cc

Issue 846023004: Removal of chrome.pushMessaging API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 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
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 #include "chrome/browser/background/background_application_list_model.h" 5 #include "chrome/browser/background/background_application_list_model.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 9
10 #include "base/sha1.h" 10 #include "base/sha1.h"
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 cursor != extensions_.end(); 273 cursor != extensions_.end();
274 ++cursor, ++position) { 274 ++cursor, ++position) {
275 if (id == cursor->get()->id()) 275 if (id == cursor->get()->id())
276 return position; 276 return position;
277 } 277 }
278 NOTREACHED(); 278 NOTREACHED();
279 return -1; 279 return -1;
280 } 280 }
281 281
282 // static 282 // static
283 bool BackgroundApplicationListModel::RequiresBackgroundModeForPushMessaging(
284 const Extension& extension) {
285 // No PushMessaging permission - does not require the background mode.
286 if (!extension.permissions_data()->HasAPIPermission(
287 APIPermission::kPushMessaging)) {
288 return false;
289 }
290
291 // If in the whitelist, then does not require background mode even if
292 // uses push messaging.
293 // TODO(dimich): remove this whitelist once we have a better way to keep
294 // listening for GCM. http://crbug.com/311268
295 std::string id_hash = base::SHA1HashString(extension.id());
296 std::string hexencoded_id_hash = base::HexEncode(id_hash.c_str(),
297 id_hash.length());
298 // The id starting from "9A04..." is a one from unit test.
299 if (hexencoded_id_hash == "C41AD9DCD670210295614257EF8C9945AD68D86E" ||
300 hexencoded_id_hash == "9A0417016F345C934A1A88F55CA17C05014EEEBA")
301 return false;
302
303 return true;
304 }
305
306 // static
307 bool BackgroundApplicationListModel::IsBackgroundApp( 283 bool BackgroundApplicationListModel::IsBackgroundApp(
308 const Extension& extension, Profile* profile) { 284 const Extension& extension, Profile* profile) {
309 // An extension is a "background app" if it has the "background API" 285 // An extension is a "background app" if it has the "background API"
310 // permission, and meets one of the following criteria: 286 // permission, and meets one of the following criteria:
311 // 1) It is an extension (not a hosted app). 287 // 1) It is an extension (not a hosted app).
312 // 2) It is a hosted app, and has a background contents registered or in the 288 // 2) It is a hosted app, and has a background contents registered or in the
313 // manifest. 289 // manifest.
314 290
315 // Ephemeral apps are denied any background activity after their event page 291 // Ephemeral apps are denied any background activity after their event page
316 // has been destroyed, thus they cannot be background apps. 292 // has been destroyed, thus they cannot be background apps.
317 if (extensions::util::IsEphemeralApp(extension.id(), profile)) 293 if (extensions::util::IsEphemeralApp(extension.id(), profile))
318 return false; 294 return false;
319 295
320 // Not a background app if we don't have the background permission or 296 // Not a background app if we don't have the background permission.
321 // the push messaging permission
322 if (!extension.permissions_data()->HasAPIPermission( 297 if (!extension.permissions_data()->HasAPIPermission(
323 APIPermission::kBackground) && 298 APIPermission::kBackground)) {
324 !RequiresBackgroundModeForPushMessaging(extension))
325 return false; 299 return false;
300 }
326 301
327 // Extensions and packaged apps with background permission are always treated 302 // Extensions and packaged apps with background permission are always treated
328 // as background apps. 303 // as background apps.
329 if (!extension.is_hosted_app()) 304 if (!extension.is_hosted_app())
330 return true; 305 return true;
331 306
332 // Hosted apps with manifest-provided background pages are background apps. 307 // Hosted apps with manifest-provided background pages are background apps.
333 if (extensions::BackgroundInfo::HasBackgroundPage(&extension)) 308 if (extensions::BackgroundInfo::HasBackgroundPage(&extension))
334 return true; 309 return true;
335 310
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 (*old_cursor)->name() == (*new_cursor)->name() && 428 (*old_cursor)->name() == (*new_cursor)->name() &&
454 (*old_cursor)->id() == (*new_cursor)->id()) { 429 (*old_cursor)->id() == (*new_cursor)->id()) {
455 ++old_cursor; 430 ++old_cursor;
456 ++new_cursor; 431 ++new_cursor;
457 } 432 }
458 if (old_cursor != extensions_.end() || new_cursor != extensions.end()) { 433 if (old_cursor != extensions_.end() || new_cursor != extensions.end()) {
459 extensions_ = extensions; 434 extensions_ = extensions;
460 FOR_EACH_OBSERVER(Observer, observers_, OnApplicationListChanged(profile_)); 435 FOR_EACH_OBSERVER(Observer, observers_, OnApplicationListChanged(profile_));
461 } 436 }
462 } 437 }
OLDNEW
« no previous file with comments | « chrome/browser/background/background_application_list_model.h ('k') | chrome/browser/extensions/api/push_messaging/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698