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

Side by Side Diff: extensions/common/file_util.cc

Issue 2686463003: [Extensions] Fix a data race in ChromeExtensionMessageFilter. (Closed)
Patch Set: [Extensions] Fix a data race in ChromeExtensionMessageFilter. Created 3 years, 10 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "extensions/common/file_util.h" 5 #include "extensions/common/file_util.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <map> 10 #include <map>
(...skipping 20 matching lines...) Expand all
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"
33 #include "extensions/common/extension_l10n_util.h" 33 #include "extensions/common/extension_l10n_util.h"
34 #include "extensions/common/extension_set.h" 34 #include "extensions/common/extension_set.h"
35 #include "extensions/common/install_warning.h" 35 #include "extensions/common/install_warning.h"
36 #include "extensions/common/manifest.h" 36 #include "extensions/common/manifest.h"
37 #include "extensions/common/manifest_constants.h" 37 #include "extensions/common/manifest_constants.h"
38 #include "extensions/common/manifest_handler.h" 38 #include "extensions/common/manifest_handler.h"
39 #include "extensions/common/manifest_handlers/default_locale_handler.h" 39 #include "extensions/common/manifest_handlers/default_locale_handler.h"
40 #include "extensions/common/manifest_handlers/icons_handler.h" 40 #include "extensions/common/manifest_handlers/icons_handler.h"
41 #include "extensions/common/manifest_handlers/shared_module_info.h"
42 #include "grit/extensions_strings.h" 41 #include "grit/extensions_strings.h"
43 #include "net/base/escape.h" 42 #include "net/base/escape.h"
44 #include "net/base/filename_util.h" 43 #include "net/base/filename_util.h"
45 #include "ui/base/l10n/l10n_util.h" 44 #include "ui/base/l10n/l10n_util.h"
46 #include "url/gurl.h" 45 #include "url/gurl.h"
47 46
48 namespace extensions { 47 namespace extensions {
49 namespace file_util { 48 namespace file_util {
50 namespace { 49 namespace {
51 50
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 } 526 }
528 527
529 // Add @@extension_id reserved message here, so it's available to 528 // Add @@extension_id reserved message here, so it's available to
530 // non-localized extensions too. 529 // non-localized extensions too.
531 return_value->insert( 530 return_value->insert(
532 std::make_pair(MessageBundle::kExtensionIdKey, extension_id)); 531 std::make_pair(MessageBundle::kExtensionIdKey, extension_id));
533 532
534 return return_value; 533 return return_value;
535 } 534 }
536 535
537 MessageBundle::SubstitutionMap* LoadMessageBundleSubstitutionMapWithImports( 536 MessageBundle::SubstitutionMap* LoadMessageBundleSubstitutionMapFromPaths(
atuchin 2017/02/08 05:51:42 In addition: What do you think about implementing
Devlin 2017/02/14 17:45:49 Sounds good to me, now that this no longer does an
atuchin 2017/02/15 08:17:29 Ok, done.
537 const std::vector<base::FilePath>& paths,
538 const std::string& extension_id, 538 const std::string& extension_id,
539 const ExtensionSet& extension_set) { 539 const std::string& default_locale) {
540 const Extension* extension = extension_set.GetByID(extension_id);
541 MessageBundle::SubstitutionMap* return_value = 540 MessageBundle::SubstitutionMap* return_value =
542 new MessageBundle::SubstitutionMap(); 541 new MessageBundle::SubstitutionMap();
543 542
544 // Add @@extension_id reserved message here, so it's available to 543 // Add @@extension_id reserved message here, so it's available to
545 // non-localized extensions too. 544 // non-localized extensions too.
546 return_value->insert( 545 return_value->insert(
547 std::make_pair(MessageBundle::kExtensionIdKey, extension_id)); 546 std::make_pair(MessageBundle::kExtensionIdKey, extension_id));
548 547
549 base::FilePath extension_path; 548 // Touch disk only if extension is localized.
550 std::string default_locale; 549 if (default_locale.empty())
551 if (!extension) {
552 NOTREACHED() << "Missing extension " << extension_id;
553 return return_value; 550 return return_value;
554 }
555
556 // Touch disk only if extension is localized.
557 default_locale = LocaleInfo::GetDefaultLocale(extension);
558 if (default_locale.empty()) {
559 return return_value;
560 }
561 551
562 std::string error; 552 std::string error;
563 std::unique_ptr<MessageBundle> bundle( 553 for (const base::FilePath& path : paths) {
564 LoadMessageBundle(extension->path(), default_locale, &error)); 554 std::unique_ptr<MessageBundle> bundle(
555 LoadMessageBundle(path, default_locale, &error));
565 556
566 if (bundle.get()) { 557 if (bundle.get()) {
Devlin 2017/02/14 17:45:49 nit: s/bundle.get()/bundle
atuchin 2017/02/15 08:17:29 Done.
567 for (auto iter : *bundle->dictionary()) { 558 for (auto iter : *bundle->dictionary()) {
568 return_value->insert(std::make_pair(iter.first, iter.second));
569 }
570 }
571
572 auto imports = extensions::SharedModuleInfo::GetImports(extension);
573 // Iterate through the imports in reverse. This will allow later imported
574 // modules to override earlier imported modules, as the list order is
575 // maintained from the definition in manifest.json of the imports.
576 for (auto it = imports.rbegin(); it != imports.rend(); ++it) {
577 const extensions::Extension* imported_extension =
578 extension_set.GetByID(it->extension_id);
579 if (!imported_extension) {
580 NOTREACHED() << "Missing shared module " << it->extension_id;
581 continue;
582 }
583 std::unique_ptr<MessageBundle> imported_bundle(
584 LoadMessageBundle(imported_extension->path(), default_locale, &error));
585
586 if (imported_bundle.get()) {
587 for (auto iter : *imported_bundle->dictionary()) {
588 // |insert| only adds new entries, and does not replace entries in 559 // |insert| only adds new entries, and does not replace entries in
589 // the main extension or previously processed imports. 560 // the main extension or previously processed imports.
590 return_value->insert(std::make_pair(iter.first, iter.second)); 561 return_value->insert(std::make_pair(iter.first, iter.second));
591 } 562 }
592 } 563 }
593 } 564 }
594 565
595 return return_value; 566 return return_value;
596 } 567 }
597 568
598 base::FilePath GetVerifiedContentsPath(const base::FilePath& extension_path) { 569 base::FilePath GetVerifiedContentsPath(const base::FilePath& extension_path) {
599 return extension_path.Append(kMetadataFolder) 570 return extension_path.Append(kMetadataFolder)
600 .Append(kVerifiedContentsFilename); 571 .Append(kVerifiedContentsFilename);
601 } 572 }
602 base::FilePath GetComputedHashesPath(const base::FilePath& extension_path) { 573 base::FilePath GetComputedHashesPath(const base::FilePath& extension_path) {
603 return extension_path.Append(kMetadataFolder).Append(kComputedHashesFilename); 574 return extension_path.Append(kMetadataFolder).Append(kComputedHashesFilename);
604 } 575 }
605 576
606 } // namespace file_util 577 } // namespace file_util
607 } // namespace extensions 578 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698