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

Side by Side Diff: chrome/browser/prerender/prerender_tracker.h

Issue 11348357: Add observer interface to PrerenderContents. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: final review remediation, clear to land version Created 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_PRERENDER_PRERENDER_TRACKER_H_ 5 #ifndef CHROME_BROWSER_PRERENDER_PRERENDER_TRACKER_H_
6 #define CHROME_BROWSER_PRERENDER_PRERENDER_TRACKER_H_ 6 #define CHROME_BROWSER_PRERENDER_PRERENDER_TRACKER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <utility>
10 #include <vector> 11 #include <vector>
11 12
12 #include "base/gtest_prod_util.h" 13 #include "base/gtest_prod_util.h"
13 #include "base/synchronization/lock.h" 14 #include "base/synchronization/lock.h"
14 #include "base/threading/non_thread_safe.h" 15 #include "base/threading/non_thread_safe.h"
16 #include "chrome/browser/prerender/prerender_contents.h"
15 #include "chrome/browser/prerender/prerender_final_status.h" 17 #include "chrome/browser/prerender/prerender_final_status.h"
16 #include "googleurl/src/gurl.h" 18 #include "googleurl/src/gurl.h"
17 19
18 namespace prerender { 20 namespace prerender {
19 21
20 class PrerenderManager; 22 class PrerenderManager;
21 struct RenderViewInfo; 23 struct RenderViewInfo;
22 24
23 // PrerenderTracker is responsible for keeping track of all prerendering 25 // PrerenderTracker is responsible for keeping track of all prerendering
24 // RenderViews and their statuses. Its list is guaranteed to be up to date 26 // RenderViews and their statuses. Its list is guaranteed to be up to date
25 // and can be modified on any thread. 27 // and can be modified on any thread.
26 class PrerenderTracker { 28 class PrerenderTracker : public base::NonThreadSafe,
29 public PrerenderContents::Observer {
27 public: 30 public:
28 PrerenderTracker(); 31 PrerenderTracker();
29 ~PrerenderTracker(); 32 virtual ~PrerenderTracker();
30 33
31 // Attempts to set the status of the specified RenderViewHost to 34 // Attempts to set the status of the specified RenderViewHost to
32 // FINAL_STATUS_USED. Returns true on success. Returns false if it has 35 // FINAL_STATUS_USED. Returns true on success. Returns false if it has
33 // already been cancelled for any reason or is no longer prerendering. 36 // already been cancelled for any reason or is no longer prerendering.
34 // Can only be called only on the IO thread. This method will not call 37 // Can only be called only on the IO thread. This method will not call
35 // PrerenderContents::set_final_status() on the corresponding 38 // PrerenderContents::SetFinalStatus() on the corresponding PrerenderContents.
36 // PrerenderContents.
37 // 39 //
38 // If it returns true, all subsequent calls to TryCancel and TryUse for the 40 // If it returns true, all subsequent calls to TryCancel and TryUse for the
39 // RenderView will return false. 41 // RenderView will return false.
40 bool TryUse(int child_id, int route_id); 42 bool TryUse(int child_id, int route_id);
41 43
42 // Attempts to cancel prerendering by the specified RenderView, setting the 44 // Attempts to cancel prerendering by the specified RenderView, setting the
43 // FinalStatus to |final_status|. Returns true if the specified prerender has 45 // FinalStatus to |final_status|. Returns true if the specified prerender has
44 // been cancelled, either as a result of this call or for any other reason. 46 // been cancelled, either as a result of this call or for any other reason.
45 // If the call results in cancelling a PrerenderContents, a task to destroy 47 // If the call results in cancelling a PrerenderContents, a task to destroy
46 // it is also posted to the UI thread. 48 // it is also posted to the UI thread.
(...skipping 27 matching lines...) Expand all
74 FRIEND_TEST_ALL_PREFIXES(PrerenderTrackerTest, PrerenderTrackerCancelledOnIO); 76 FRIEND_TEST_ALL_PREFIXES(PrerenderTrackerTest, PrerenderTrackerCancelledOnIO);
75 FRIEND_TEST_ALL_PREFIXES(PrerenderTrackerTest, PrerenderTrackerCancelledFast); 77 FRIEND_TEST_ALL_PREFIXES(PrerenderTrackerTest, PrerenderTrackerCancelledFast);
76 FRIEND_TEST_ALL_PREFIXES(PrerenderTrackerTest, PrerenderTrackerMultiple); 78 FRIEND_TEST_ALL_PREFIXES(PrerenderTrackerTest, PrerenderTrackerMultiple);
77 79
78 typedef std::pair<int, int> ChildRouteIdPair; 80 typedef std::pair<int, int> ChildRouteIdPair;
79 // Map of child/route id pairs to final statuses. 81 // Map of child/route id pairs to final statuses.
80 typedef std::map<ChildRouteIdPair, RenderViewInfo> FinalStatusMap; 82 typedef std::map<ChildRouteIdPair, RenderViewInfo> FinalStatusMap;
81 // Set of child/route id pairs that may be prerendering. 83 // Set of child/route id pairs that may be prerendering.
82 typedef std::set<ChildRouteIdPair> PossiblyPrerenderingChildRouteIdPairs; 84 typedef std::set<ChildRouteIdPair> PossiblyPrerenderingChildRouteIdPairs;
83 85
84 // Must be called when a RenderView starts prerendering, before the first 86 // From PrerenderContents::Observer:
85 // navigation starts to avoid any races. 87 virtual void OnPrerenderStart(PrerenderContents* prerender_contents) OVERRIDE;
86 void OnPrerenderingStarted(int child_id, int route_id, 88 virtual void OnPrerenderStop(PrerenderContents* prerender_contents) OVERRIDE;
87 PrerenderManager* prerender_manager);
88
89 // Must be called when a RenderView stops prerendering, either because the
90 // RenderView was used or prerendering was cancelled and it is being
91 // destroyed.
92 void OnPrerenderingFinished(int child_id, int route_id);
93 89
94 // Attempts to set the FinalStatus of the specified RenderView to 90 // Attempts to set the FinalStatus of the specified RenderView to
95 // |desired_final_status|. If non-NULL, |actual_final_status| is set to the 91 // |desired_final_status|. If non-NULL, |actual_final_status| is set to the
96 // FinalStatus of the RenderView. 92 // FinalStatus of the RenderView.
97 // 93 //
98 // If the FinalStatus of the RenderView is successfully set, returns true and 94 // If the FinalStatus of the RenderView is successfully set, returns true and
99 // sets |actual_final_status| to |desired_final_status|. 95 // sets |actual_final_status| to |desired_final_status|.
100 // 96 //
101 // If the FinalStatus of the RenderView was already set, returns false and 97 // If the FinalStatus of the RenderView was already set, returns false and
102 // sets |actual_final_status| to the actual FinalStatus of the RenderView. 98 // sets |actual_final_status| to the actual FinalStatus of the RenderView.
(...skipping 28 matching lines...) Expand all
131 // the IO thread. May contain entries that have since been displayed. Only 127 // the IO thread. May contain entries that have since been displayed. Only
132 // used to prevent locking when not needed. 128 // used to prevent locking when not needed.
133 PossiblyPrerenderingChildRouteIdPairs possibly_prerendering_io_thread_set_; 129 PossiblyPrerenderingChildRouteIdPairs possibly_prerendering_io_thread_set_;
134 130
135 DISALLOW_COPY_AND_ASSIGN(PrerenderTracker); 131 DISALLOW_COPY_AND_ASSIGN(PrerenderTracker);
136 }; 132 };
137 133
138 } // namespace prerender 134 } // namespace prerender
139 135
140 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_TRACKER_H_ 136 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_TRACKER_H_
OLDNEW
« no previous file with comments | « chrome/browser/prerender/prerender_manager.cc ('k') | chrome/browser/prerender/prerender_tracker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698