blob: 5e87d43f1754f530a6ab4555b3b7ea3da005878d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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
|