1 // Copyright 2013 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.
5 #ifndef CHROME_BROWSER_NETWORK_TIME_NAVIGATION_TIME_HELPER_H_
6 #define CHROME_BROWSER_NETWORK_TIME_NAVIGATION_TIME_HELPER_H_
10 #include "base/time/time.h"
11 #include "content/public/browser/notification_observer.h"
12 #include "content/public/browser/notification_registrar.h"
13 #include "content/public/browser/web_contents_user_data.h"
19 // NavigationTimeHelper returns the navigation time in network time for
20 // given navigation entry.
21 class NavigationTimeHelper
22 : public content::NotificationObserver
,
23 public content::WebContentsUserData
<NavigationTimeHelper
> {
25 virtual ~NavigationTimeHelper();
27 base::Time
GetNavigationTime(const content::NavigationEntry
* entry
);
31 NavigationTimeHelper();
33 // Return network time for given |local_time|.
34 virtual base::Time
GetNetworkTime(base::Time local_time
);
37 explicit NavigationTimeHelper(content::WebContents
* web_contents
);
38 friend class content::WebContentsUserData
<NavigationTimeHelper
>;
40 // content::NotificationObserver implementation.
41 virtual void Observe(int type
,
42 const content::NotificationSource
& source
,
43 const content::NotificationDetails
& details
) OVERRIDE
;
45 content::NotificationRegistrar registrar_
;
47 content::WebContents
* web_contents_
;
49 // Map from navigation entries to the navigation times calculated for them.
50 struct NavigationTimeInfo
{
51 NavigationTimeInfo(base::Time local_time
, base::Time network_time
)
52 : local_time(local_time
), network_time(network_time
) {}
53 base::Time local_time
;
54 base::Time network_time
;
56 typedef std::map
<const void*, NavigationTimeInfo
> NavigationTimeCache
;
57 NavigationTimeCache time_cache_
;
59 DISALLOW_COPY_AND_ASSIGN(NavigationTimeHelper
);
62 #endif // CHROME_BROWSER_NETWORK_TIME_NAVIGATION_TIME_HELPER_H_