OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/predictors/resource_prefetch_common.h" |
| 6 |
| 7 #include "content/public/browser/render_process_host.h" |
| 8 #include "content/public/browser/render_view_host.h" |
| 9 #include "content/public/browser/web_contents.h" |
| 10 |
| 11 namespace predictors { |
| 12 |
| 13 NavigationID::NavigationID() : render_process_id_(-1), render_view_id_(-1) { |
| 14 } |
| 15 |
| 16 NavigationID::NavigationID(const NavigationID& other) |
| 17 : render_process_id_(other.render_process_id_), |
| 18 render_view_id_(other.render_view_id_), |
| 19 main_frame_url_(other.main_frame_url_), |
| 20 creation_time_(other.creation_time_) { |
| 21 } |
| 22 |
| 23 NavigationID::NavigationID(const content::WebContents& web_contents) |
| 24 : render_process_id_(web_contents.GetRenderProcessHost()->GetID()), |
| 25 render_view_id_(web_contents.GetRenderViewHost()->GetRoutingID()), |
| 26 main_frame_url_(web_contents.GetURL()) { |
| 27 } |
| 28 |
| 29 bool NavigationID::is_valid() const { |
| 30 return render_process_id_ != -1 && render_view_id_ != -1 && |
| 31 !main_frame_url_.is_empty(); |
| 32 } |
| 33 |
| 34 bool NavigationID::operator<(const NavigationID& rhs) const { |
| 35 DCHECK(is_valid() && rhs.is_valid()); |
| 36 if (render_process_id_ != rhs.render_process_id_) |
| 37 return render_process_id_ < rhs.render_process_id_; |
| 38 else if (render_view_id_ != rhs.render_view_id_) |
| 39 return render_view_id_ < rhs.render_view_id_; |
| 40 else |
| 41 return main_frame_url_ < rhs.main_frame_url_; |
| 42 } |
| 43 |
| 44 bool NavigationID::operator==(const NavigationID& rhs) const { |
| 45 DCHECK(is_valid() && rhs.is_valid()); |
| 46 return IsSameRenderer(rhs) && main_frame_url_ == rhs.main_frame_url_; |
| 47 } |
| 48 |
| 49 bool NavigationID::IsSameRenderer(const NavigationID& other) const { |
| 50 DCHECK(is_valid() && other.is_valid()); |
| 51 return render_process_id_ == other.render_process_id_ && |
| 52 render_view_id_ == other.render_view_id_; |
| 53 } |
| 54 |
| 55 } // namespace predictors |
OLD | NEW |