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

Unified Diff: chrome/common/extensions/api/i18n/default_locale_handler.cc

Issue 12025010: Move default_locale out of Extension class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/common/extensions/api/i18n/default_locale_handler.cc
diff --git a/chrome/common/extensions/api/i18n/default_locale_handler.cc b/chrome/common/extensions/api/i18n/default_locale_handler.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2ae86031e705b5b7a12d70f7083738655b2c1dc2
--- /dev/null
+++ b/chrome/common/extensions/api/i18n/default_locale_handler.cc
@@ -0,0 +1,44 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/common/extensions/api/i18n/default_locale_handler.h"
+
+#include "base/memory/scoped_ptr.h"
+#include "base/string_util.h"
+#include "base/utf_string_conversions.h"
+#include "base/values.h"
+#include "chrome/common/extensions/extension_manifest_constants.h"
+#include "ui/base/l10n/l10n_util.h"
+
+namespace keys = extension_manifest_keys;
+
+namespace extensions {
+
+// static
+const std::string& LocaleInfo::GetDefaultLocale(const Extension* extension) {
+ LocaleInfo* info = static_cast<LocaleInfo*>(
+ extension->GetManifestData(keys::kDefaultLocale));
+ return info ? info->default_locale_ : EmptyString();
+}
+
+DefaultLocaleHandler::DefaultLocaleHandler() {
+}
+
+DefaultLocaleHandler::~DefaultLocaleHandler() {
+}
+
+bool DefaultLocaleHandler::Parse(const base::Value* value,
+ Extension* extension,
+ string16* error) {
+ scoped_ptr<LocaleInfo> info(new LocaleInfo);
+ if (!value->GetAsString(&info->default_locale_) ||
+ !l10n_util::IsValidLocaleSyntax(info->default_locale_)) {
+ *error = ASCIIToUTF16(extension_manifest_errors::kInvalidDefaultLocale);
+ return false;
+ }
+ extension->SetManifestData(keys::kDefaultLocale, info.release());
+ return true;
+}
+
+} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698