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

Unified Diff: chrome/browser/predictors/resource_prefetch_common.cc

Issue 10416002: Seculative resource prefetching for URLs CL. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Addressing Dominich's comments. Created 8 years, 7 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/browser/predictors/resource_prefetch_common.cc
diff --git a/chrome/browser/predictors/resource_prefetch_common.cc b/chrome/browser/predictors/resource_prefetch_common.cc
new file mode 100644
index 0000000000000000000000000000000000000000..63cf0806f7337758015cb0d03be8970b269938a1
--- /dev/null
+++ b/chrome/browser/predictors/resource_prefetch_common.cc
@@ -0,0 +1,55 @@
+// Copyright (c) 2012 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/browser/predictors/resource_prefetch_common.h"
+
+#include "content/public/browser/render_process_host.h"
+#include "content/public/browser/render_view_host.h"
+#include "content/public/browser/web_contents.h"
+
+namespace predictors {
+
+NavigationID::NavigationID() : render_process_id_(-1), render_view_id_(-1) {
+}
+
+NavigationID::NavigationID(const NavigationID& other)
+ : render_process_id_(other.render_process_id_),
+ render_view_id_(other.render_view_id_),
+ main_frame_url_(other.main_frame_url_),
+ creation_time_(other.creation_time_) {
+}
+
+NavigationID::NavigationID(const content::WebContents& web_contents)
+ : render_process_id_(web_contents.GetRenderProcessHost()->GetID()),
+ render_view_id_(web_contents.GetRenderViewHost()->GetRoutingID()),
+ main_frame_url_(web_contents.GetURL()) {
+}
+
+bool NavigationID::is_valid() const {
+ return render_process_id_ != -1 && render_view_id_ != -1 &&
+ !main_frame_url_.is_empty();
+}
+
+bool NavigationID::operator<(const NavigationID& rhs) const {
+ DCHECK(is_valid() && rhs.is_valid());
+ if (render_process_id_ != rhs.render_process_id_)
+ return render_process_id_ < rhs.render_process_id_;
+ else if (render_view_id_ != rhs.render_view_id_)
+ return render_view_id_ < rhs.render_view_id_;
+ else
+ return main_frame_url_ < rhs.main_frame_url_;
+}
+
+bool NavigationID::operator==(const NavigationID& rhs) const {
+ DCHECK(is_valid() && rhs.is_valid());
+ return IsSameRenderer(rhs) && main_frame_url_ == rhs.main_frame_url_;
+}
+
+bool NavigationID::IsSameRenderer(const NavigationID& other) const {
+ DCHECK(is_valid() && other.is_valid());
+ return render_process_id_ == other.render_process_id_ &&
+ render_view_id_ == other.render_view_id_;
+}
+
+} // namespace predictors

Powered by Google App Engine
This is Rietveld 408576698