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

Unified Diff: ios/chrome/browser/ui/tab_switcher/tab_model_snapshot.mm

Issue 2588733002: Upstream Chrome on iOS source code [9/11]. (Closed)
Patch Set: Created 4 years 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: ios/chrome/browser/ui/tab_switcher/tab_model_snapshot.mm
diff --git a/ios/chrome/browser/ui/tab_switcher/tab_model_snapshot.mm b/ios/chrome/browser/ui/tab_switcher/tab_model_snapshot.mm
new file mode 100644
index 0000000000000000000000000000000000000000..3296d9d8f1da2ca8ae0b48706e3d8e90fee87e78
--- /dev/null
+++ b/ios/chrome/browser/ui/tab_switcher/tab_model_snapshot.mm
@@ -0,0 +1,38 @@
+// Copyright 2016 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.
+
+#import "ios/chrome/browser/ui/tab_switcher/tab_model_snapshot.h"
+
+#include "base/strings/sys_string_conversions.h"
+#import "ios/chrome/browser/tabs/tab.h"
+
+TabModelSnapshot::TabModelSnapshot(TabModel* tabModel) {
+ for (Tab* tab in tabModel) {
+ _hashes.push_back(hashOfTheVisiblePropertiesOfATab(tab));
+ _tabs.push_back(base::WeakNSObject<Tab>(tab));
+ }
+}
+
+TabModelSnapshot::~TabModelSnapshot() {}
+
+std::vector<size_t> const& TabModelSnapshot::hashes() const {
+ DCHECK_EQ(_tabs.size(), _hashes.size());
+ return _hashes;
+}
+
+std::vector<base::WeakNSObject<Tab>> const& TabModelSnapshot::tabs() const {
+ DCHECK_EQ(_tabs.size(), _hashes.size());
+ return _tabs;
+}
+
+size_t TabModelSnapshot::hashOfTheVisiblePropertiesOfATab(Tab* tab) {
+ DCHECK(tab);
+ std::stringstream ss;
+ // lastVisitedTimestamp is used as an approximation for whether the tab's
+ // snapshot changed.
+ ss << tab.tabId << std::endl
+ << base::SysNSStringToUTF8(tab.urlDisplayString) << std::endl
+ << std::hexfloat << tab.lastVisitedTimestamp << std::endl;
+ return std::hash<std::string>()(ss.str());
+}

Powered by Google App Engine
This is Rietveld 408576698