summaryrefslogtreecommitdiff
path: root/chromium/extensions/common/extension_icon_set.cc
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2016-07-01 12:20:27 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2016-07-01 10:39:40 +0000
commit7366110654eec46f21b6824f302356426f48cd74 (patch)
treef2ff1845183f6117a692bb0c705475c8c13556d5 /chromium/extensions/common/extension_icon_set.cc
parentb92421879c003a0857b2074f7e05b3bbbb326569 (diff)
downloadqtwebengine-chromium-7366110654eec46f21b6824f302356426f48cd74.tar.gz
BASELINE: Update Chromium to 51.0.2704.106
Also add a few extra files we might need for future features. Change-Id: I517c35e43221c610976d347c966d070ad44d4c2b Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Diffstat (limited to 'chromium/extensions/common/extension_icon_set.cc')
-rw-r--r--chromium/extensions/common/extension_icon_set.cc80
1 files changed, 80 insertions, 0 deletions
diff --git a/chromium/extensions/common/extension_icon_set.cc b/chromium/extensions/common/extension_icon_set.cc
new file mode 100644
index 00000000000..421407c789d
--- /dev/null
+++ b/chromium/extensions/common/extension_icon_set.cc
@@ -0,0 +1,80 @@
+// Copyright 2014 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 "extensions/common/extension_icon_set.h"
+
+#include "base/files/file_path.h"
+#include "base/logging.h"
+#include "base/strings/string_util.h"
+
+ExtensionIconSet::ExtensionIconSet() {}
+
+ExtensionIconSet::ExtensionIconSet(const ExtensionIconSet& other) = default;
+
+ExtensionIconSet::~ExtensionIconSet() {}
+
+void ExtensionIconSet::Clear() {
+ map_.clear();
+}
+
+void ExtensionIconSet::Add(int size, const std::string& path) {
+ DCHECK(!path.empty() && path[0] != '/');
+ map_[size] = path;
+}
+
+const std::string& ExtensionIconSet::Get(int size, MatchType match_type) const {
+ // The searches for MATCH_BIGGER and MATCH_SMALLER below rely on the fact that
+ // std::map is sorted. This is per the spec, so it should be safe to rely on.
+ if (match_type == MATCH_EXACTLY) {
+ IconMap::const_iterator result = map_.find(size);
+ return result == map_.end() ? base::EmptyString() : result->second;
+ } else if (match_type == MATCH_SMALLER) {
+ IconMap::const_reverse_iterator result = map_.rend();
+ for (IconMap::const_reverse_iterator iter = map_.rbegin();
+ iter != map_.rend(); ++iter) {
+ if (iter->first <= size) {
+ result = iter;
+ break;
+ }
+ }
+ return result == map_.rend() ? base::EmptyString() : result->second;
+ } else {
+ DCHECK(match_type == MATCH_BIGGER);
+ IconMap::const_iterator result = map_.end();
+ for (IconMap::const_iterator iter = map_.begin(); iter != map_.end();
+ ++iter) {
+ if (iter->first >= size) {
+ result = iter;
+ break;
+ }
+ }
+ return result == map_.end() ? base::EmptyString() : result->second;
+ }
+}
+
+bool ExtensionIconSet::ContainsPath(const std::string& path) const {
+ return GetIconSizeFromPath(path) != 0;
+}
+
+int ExtensionIconSet::GetIconSizeFromPath(const std::string& path) const {
+ if (path.empty())
+ return 0;
+
+ DCHECK_NE(path[0], '/') <<
+ "ExtensionIconSet stores icon paths without leading slash.";
+
+ for (IconMap::const_iterator iter = map_.begin(); iter != map_.end();
+ ++iter) {
+ if (iter->second == path)
+ return iter->first;
+ }
+
+ return 0;
+}
+
+void ExtensionIconSet::GetPaths(std::set<base::FilePath>* paths) const {
+ CHECK(paths);
+ for (auto iter : map())
+ paths->insert(base::FilePath::FromUTF8Unsafe(iter.second));
+}