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

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: rebase 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
« no previous file with comments | « no previous file | chrome/browser/content_settings/content_settings_internal_extension_provider.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
21 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/common/extensions/extension_constants.h" 21 #include "chrome/common/extensions/extension_constants.h"
22 #include "components/crx_file/id_util.h"
23 #include "content/public/browser/notification_details.h" 23 #include "content/public/browser/notification_details.h"
24 #include "content/public/browser/notification_source.h" 24 #include "content/public/browser/notification_source.h"
25 #include "extensions/browser/extension_prefs.h" 25 #include "extensions/browser/extension_prefs.h"
26 #include "extensions/browser/extension_registry.h" 26 #include "extensions/browser/extension_registry.h"
27 #include "extensions/browser/extension_system.h" 27 #include "extensions/browser/extension_system.h"
28 #include "extensions/browser/extension_util.h" 28 #include "extensions/browser/extension_util.h"
29 #include "extensions/browser/image_loader.h" 29 #include "extensions/browser/image_loader.h"
30 #include "extensions/browser/notification_types.h" 30 #include "extensions/browser/notification_types.h"
31 #include "extensions/common/extension.h" 31 #include "extensions/common/extension.h"
32 #include "extensions/common/extension_icon_set.h" 32 #include "extensions/common/extension_icon_set.h"
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 // No PushMessaging permission - does not require the background mode. 285 // No PushMessaging permission - does not require the background mode.
286 if (!extension.permissions_data()->HasAPIPermission( 286 if (!extension.permissions_data()->HasAPIPermission(
287 APIPermission::kPushMessaging)) { 287 APIPermission::kPushMessaging)) {
288 return false; 288 return false;
289 } 289 }
290 290
291 // If in the whitelist, then does not require background mode even if 291 // If in the whitelist, then does not require background mode even if
292 // uses push messaging. 292 // uses push messaging.
293 // TODO(dimich): remove this whitelist once we have a better way to keep 293 // TODO(dimich): remove this whitelist once we have a better way to keep
294 // listening for GCM. http://crbug.com/311268 294 // listening for GCM. http://crbug.com/311268
295 std::string id_hash = base::SHA1HashString(extension.id()); 295 std::string hexencoded_id_hash =
296 std::string hexencoded_id_hash = base::HexEncode(id_hash.c_str(), 296 crx_file::id_util::HashedIdInHex(extension.id());
297 id_hash.length());
298 // The id starting from "9A04..." is a one from unit test. 297 // The id starting from "9A04..." is a one from unit test.
299 if (hexencoded_id_hash == "C41AD9DCD670210295614257EF8C9945AD68D86E" || 298 if (hexencoded_id_hash == "C41AD9DCD670210295614257EF8C9945AD68D86E" ||
300 hexencoded_id_hash == "9A0417016F345C934A1A88F55CA17C05014EEEBA") 299 hexencoded_id_hash == "9A0417016F345C934A1A88F55CA17C05014EEEBA")
301 return false; 300 return false;
302 301
303 return true; 302 return true;
304 } 303 }
305 304
306 // static 305 // static
307 bool BackgroundApplicationListModel::IsBackgroundApp( 306 bool BackgroundApplicationListModel::IsBackgroundApp(
308 const Extension& extension, Profile* profile) { 307 const Extension& extension, Profile* profile) {
309 // An extension is a "background app" if it has the "background API" 308 // An extension is a "background app" if it has the "background API"
310 // permission, and meets one of the following criteria: 309 // permission, and meets one of the following criteria:
311 // 1) It is an extension (not a hosted app). 310 // 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 311 // 2) It is a hosted app, and has a background contents registered or in the
313 // manifest. 312 // manifest.
314 313
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 (*old_cursor)->name() == (*new_cursor)->name() && 452 (*old_cursor)->name() == (*new_cursor)->name() &&
454 (*old_cursor)->id() == (*new_cursor)->id()) { 453 (*old_cursor)->id() == (*new_cursor)->id()) {
455 ++old_cursor; 454 ++old_cursor;
456 ++new_cursor; 455 ++new_cursor;
457 } 456 }
458 if (old_cursor != extensions_.end() || new_cursor != extensions.end()) { 457 if (old_cursor != extensions_.end() || new_cursor != extensions.end()) {
459 extensions_ = extensions; 458 extensions_ = extensions;
460 FOR_EACH_OBSERVER(Observer, observers_, OnApplicationListChanged(profile_)); 459 FOR_EACH_OBSERVER(Observer, observers_, OnApplicationListChanged(profile_));
461 } 460 }
462 } 461 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/content_settings/content_settings_internal_extension_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698