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

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

Issue 850853002: Extensions: Consolidate extension id hashing / searching. (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"
11 #include "base/stl_util.h" 10 #include "base/stl_util.h"
12 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
14 #include "chrome/app/chrome_command_ids.h" 13 #include "chrome/app/chrome_command_ids.h"
15 #include "chrome/browser/background/background_contents_service.h" 14 #include "chrome/browser/background/background_contents_service.h"
16 #include "chrome/browser/background/background_contents_service_factory.h" 15 #include "chrome/browser/background/background_contents_service_factory.h"
17 #include "chrome/browser/background/background_mode_manager.h" 16 #include "chrome/browser/background/background_mode_manager.h"
18 #include "chrome/browser/browser_process.h" 17 #include "chrome/browser/browser_process.h"
19 #include "chrome/browser/chrome_notification_types.h" 18 #include "chrome/browser/chrome_notification_types.h"
20 #include "chrome/browser/extensions/extension_service.h" 19 #include "chrome/browser/extensions/extension_service.h"
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 // No PushMessaging permission - does not require the background mode. 284 // No PushMessaging permission - does not require the background mode.
286 if (!extension.permissions_data()->HasAPIPermission( 285 if (!extension.permissions_data()->HasAPIPermission(
287 APIPermission::kPushMessaging)) { 286 APIPermission::kPushMessaging)) {
288 return false; 287 return false;
289 } 288 }
290 289
291 // If in the whitelist, then does not require background mode even if 290 // If in the whitelist, then does not require background mode even if
292 // uses push messaging. 291 // uses push messaging.
293 // TODO(dimich): remove this whitelist once we have a better way to keep 292 // TODO(dimich): remove this whitelist once we have a better way to keep
294 // listening for GCM. http://crbug.com/311268 293 // listening for GCM. http://crbug.com/311268
295 std::string id_hash = base::SHA1HashString(extension.id()); 294 std::string hexencoded_id_hash = extension.HashedIdInHex();
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. 295 // The id starting from "9A04..." is a one from unit test.
299 if (hexencoded_id_hash == "C41AD9DCD670210295614257EF8C9945AD68D86E" || 296 if (hexencoded_id_hash == "C41AD9DCD670210295614257EF8C9945AD68D86E" ||
300 hexencoded_id_hash == "9A0417016F345C934A1A88F55CA17C05014EEEBA") 297 hexencoded_id_hash == "9A0417016F345C934A1A88F55CA17C05014EEEBA")
301 return false; 298 return false;
302 299
303 return true; 300 return true;
304 } 301 }
305 302
306 // static 303 // static
307 bool BackgroundApplicationListModel::IsBackgroundApp( 304 bool BackgroundApplicationListModel::IsBackgroundApp(
308 const Extension& extension, Profile* profile) { 305 const Extension& extension, Profile* profile) {
309 // An extension is a "background app" if it has the "background API" 306 // An extension is a "background app" if it has the "background API"
310 // permission, and meets one of the following criteria: 307 // permission, and meets one of the following criteria:
311 // 1) It is an extension (not a hosted app). 308 // 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 309 // 2) It is a hosted app, and has a background contents registered or in the
313 // manifest. 310 // manifest.
314 311
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 (*old_cursor)->name() == (*new_cursor)->name() && 450 (*old_cursor)->name() == (*new_cursor)->name() &&
454 (*old_cursor)->id() == (*new_cursor)->id()) { 451 (*old_cursor)->id() == (*new_cursor)->id()) {
455 ++old_cursor; 452 ++old_cursor;
456 ++new_cursor; 453 ++new_cursor;
457 } 454 }
458 if (old_cursor != extensions_.end() || new_cursor != extensions.end()) { 455 if (old_cursor != extensions_.end() || new_cursor != extensions.end()) {
459 extensions_ = extensions; 456 extensions_ = extensions;
460 FOR_EACH_OBSERVER(Observer, observers_, OnApplicationListChanged(profile_)); 457 FOR_EACH_OBSERVER(Observer, observers_, OnApplicationListChanged(profile_));
461 } 458 }
462 } 459 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698