| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/extension.h" | 5 #include "extensions/common/extension.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/base64.h" | 12 #include "base/base64.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 15 #include "base/i18n/rtl.h" | 15 #include "base/i18n/rtl.h" |
| 16 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "base/memory/singleton.h" | 17 #include "base/memory/singleton.h" |
| 18 #include "base/metrics/histogram_macros.h" |
| 18 #include "base/stl_util.h" | 19 #include "base/stl_util.h" |
| 19 #include "base/strings/string16.h" | 20 #include "base/strings/string16.h" |
| 20 #include "base/strings/string_number_conversions.h" | 21 #include "base/strings/string_number_conversions.h" |
| 21 #include "base/strings/string_piece.h" | 22 #include "base/strings/string_piece.h" |
| 22 #include "base/strings/string_util.h" | 23 #include "base/strings/string_util.h" |
| 23 #include "base/strings/stringprintf.h" | 24 #include "base/strings/stringprintf.h" |
| 24 #include "base/strings/utf_string_conversions.h" | 25 #include "base/strings/utf_string_conversions.h" |
| 26 #include "base/timer/elapsed_timer.h" |
| 25 #include "base/values.h" | 27 #include "base/values.h" |
| 26 #include "base/version.h" | 28 #include "base/version.h" |
| 27 #include "components/crx_file/id_util.h" | 29 #include "components/crx_file/id_util.h" |
| 30 #include "content/public/common/content_switches.h" |
| 28 #include "content/public/common/url_constants.h" | 31 #include "content/public/common/url_constants.h" |
| 29 #include "extensions/common/constants.h" | 32 #include "extensions/common/constants.h" |
| 30 #include "extensions/common/error_utils.h" | 33 #include "extensions/common/error_utils.h" |
| 31 #include "extensions/common/feature_switch.h" | 34 #include "extensions/common/feature_switch.h" |
| 32 #include "extensions/common/manifest.h" | 35 #include "extensions/common/manifest.h" |
| 33 #include "extensions/common/manifest_constants.h" | 36 #include "extensions/common/manifest_constants.h" |
| 34 #include "extensions/common/manifest_handler.h" | 37 #include "extensions/common/manifest_handler.h" |
| 35 #include "extensions/common/manifest_handlers/incognito_info.h" | 38 #include "extensions/common/manifest_handlers/incognito_info.h" |
| 36 #include "extensions/common/manifest_handlers/permissions_parser.h" | 39 #include "extensions/common/manifest_handlers/permissions_parser.h" |
| 37 #include "extensions/common/permissions/permission_set.h" | 40 #include "extensions/common/permissions/permission_set.h" |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 } | 112 } |
| 110 | 113 |
| 111 // TODO(sungguk): Continue removing std::string errors and replacing | 114 // TODO(sungguk): Continue removing std::string errors and replacing |
| 112 // with base::string16. See http://crbug.com/71980. | 115 // with base::string16. See http://crbug.com/71980. |
| 113 scoped_refptr<Extension> Extension::Create(const base::FilePath& path, | 116 scoped_refptr<Extension> Extension::Create(const base::FilePath& path, |
| 114 Manifest::Location location, | 117 Manifest::Location location, |
| 115 const base::DictionaryValue& value, | 118 const base::DictionaryValue& value, |
| 116 int flags, | 119 int flags, |
| 117 const std::string& explicit_id, | 120 const std::string& explicit_id, |
| 118 std::string* utf8_error) { | 121 std::string* utf8_error) { |
| 122 base::ElapsedTimer timer; |
| 119 DCHECK(utf8_error); | 123 DCHECK(utf8_error); |
| 120 base::string16 error; | 124 base::string16 error; |
| 121 std::unique_ptr<extensions::Manifest> manifest(new extensions::Manifest( | 125 std::unique_ptr<extensions::Manifest> manifest(new extensions::Manifest( |
| 122 location, std::unique_ptr<base::DictionaryValue>(value.DeepCopy()))); | 126 location, std::unique_ptr<base::DictionaryValue>(value.DeepCopy()))); |
| 123 | 127 |
| 124 if (!InitExtensionID(manifest.get(), path, explicit_id, flags, &error)) { | 128 if (!InitExtensionID(manifest.get(), path, explicit_id, flags, &error)) { |
| 125 *utf8_error = base::UTF16ToUTF8(error); | 129 *utf8_error = base::UTF16ToUTF8(error); |
| 126 return NULL; | 130 return NULL; |
| 127 } | 131 } |
| 128 | 132 |
| 129 std::vector<InstallWarning> install_warnings; | 133 std::vector<InstallWarning> install_warnings; |
| 130 if (!manifest->ValidateManifest(utf8_error, &install_warnings)) { | 134 if (!manifest->ValidateManifest(utf8_error, &install_warnings)) { |
| 131 return NULL; | 135 return NULL; |
| 132 } | 136 } |
| 133 | 137 |
| 134 scoped_refptr<Extension> extension = new Extension(path, std::move(manifest)); | 138 scoped_refptr<Extension> extension = new Extension(path, std::move(manifest)); |
| 135 extension->install_warnings_.swap(install_warnings); | 139 extension->install_warnings_.swap(install_warnings); |
| 136 | 140 |
| 137 if (!extension->InitFromValue(flags, &error)) { | 141 if (!extension->InitFromValue(flags, &error)) { |
| 138 *utf8_error = base::UTF16ToUTF8(error); | 142 *utf8_error = base::UTF16ToUTF8(error); |
| 139 return NULL; | 143 return NULL; |
| 140 } | 144 } |
| 141 | 145 |
| 146 const base::CommandLine& command_line = |
| 147 *base::CommandLine::ForCurrentProcess(); |
| 148 std::string process_type = |
| 149 command_line.GetSwitchValueASCII(::switches::kProcessType); |
| 150 // Use microsecond accuracy for increased granularity. Max at 10 seconds. |
| 151 base::TimeDelta elapsed_time = timer.Elapsed(); |
| 152 const int kMaxTimeInMicroseconds = 10000000; |
| 153 if (process_type.empty()) { |
| 154 UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 155 "Extensions.ExtensionCreationTime.BrowserProcess", |
| 156 elapsed_time.InMicroseconds(), 1, kMaxTimeInMicroseconds, 100); |
| 157 } else if (command_line.HasSwitch(switches::kExtensionProcess)) { |
| 158 UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 159 "Extensions.ExtensionCreationTime.ExtensionProcess", |
| 160 elapsed_time.InMicroseconds(), 1, kMaxTimeInMicroseconds, 100); |
| 161 } else if (process_type == ::switches::kRendererProcess) { |
| 162 UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 163 "Extensions.ExtensionCreationTime.RendererProcess", |
| 164 elapsed_time.InMicroseconds(), 1, kMaxTimeInMicroseconds, 100); |
| 165 } |
| 166 |
| 142 return extension; | 167 return extension; |
| 143 } | 168 } |
| 144 | 169 |
| 145 Manifest::Type Extension::GetType() const { | 170 Manifest::Type Extension::GetType() const { |
| 146 return converted_from_user_script() ? | 171 return converted_from_user_script() ? |
| 147 Manifest::TYPE_USER_SCRIPT : manifest_->type(); | 172 Manifest::TYPE_USER_SCRIPT : manifest_->type(); |
| 148 } | 173 } |
| 149 | 174 |
| 150 // static | 175 // static |
| 151 GURL Extension::GetResourceURL(const GURL& extension_url, | 176 GURL Extension::GetResourceURL(const GURL& extension_url, |
| (...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 776 : reason(reason), | 801 : reason(reason), |
| 777 extension(extension) {} | 802 extension(extension) {} |
| 778 | 803 |
| 779 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( | 804 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( |
| 780 const Extension* extension, | 805 const Extension* extension, |
| 781 const PermissionSet& permissions, | 806 const PermissionSet& permissions, |
| 782 Reason reason) | 807 Reason reason) |
| 783 : reason(reason), extension(extension), permissions(permissions) {} | 808 : reason(reason), extension(extension), permissions(permissions) {} |
| 784 | 809 |
| 785 } // namespace extensions | 810 } // namespace extensions |
| OLD | NEW |