Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <set> | 10 #include <set> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/callback_forward.h" | 13 #include "base/callback_forward.h" |
|
mmenke
2012/04/06 19:40:04
We don't need this anymore.
| |
| 14 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
| 15 #include "base/synchronization/lock.h" | 15 #include "base/synchronization/lock.h" |
| 16 #include "base/threading/non_thread_safe.h" | 16 #include "base/threading/non_thread_safe.h" |
| 17 #include "chrome/browser/prerender/prerender_final_status.h" | 17 #include "chrome/browser/prerender/prerender_final_status.h" |
| 18 #include "googleurl/src/gurl.h" | 18 #include "googleurl/src/gurl.h" |
| 19 | 19 |
| 20 namespace prerender { | 20 namespace prerender { |
| 21 | 21 |
| 22 class PrerenderManager; | 22 class PrerenderManager; |
| 23 struct RenderViewInfo; | 23 struct RenderViewInfo; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 40 private: | 40 private: |
| 41 typedef std::map<GURL, int> URLCountMap; | 41 typedef std::map<GURL, int> URLCountMap; |
| 42 URLCountMap url_count_map_; | 42 URLCountMap url_count_map_; |
| 43 }; | 43 }; |
| 44 | 44 |
| 45 // PrerenderTracker is responsible for keeping track of all prerendering | 45 // PrerenderTracker is responsible for keeping track of all prerendering |
| 46 // RenderViews and their statuses. Its list is guaranteed to be up to date | 46 // RenderViews and their statuses. Its list is guaranteed to be up to date |
| 47 // and can be modified on any thread. | 47 // and can be modified on any thread. |
| 48 class PrerenderTracker { | 48 class PrerenderTracker { |
| 49 public: | 49 public: |
| 50 typedef base::Callback<void(bool /* proceed */)> CheckURLCallback; | 50 typedef base::Callback<void(bool /* proceed */)> CheckURLCallback; |
|
mmenke
2012/04/06 19:40:04
Or this.
| |
| 51 | 51 |
| 52 PrerenderTracker(); | 52 PrerenderTracker(); |
| 53 ~PrerenderTracker(); | 53 ~PrerenderTracker(); |
| 54 | 54 |
| 55 // Attempts to set the status of the specified RenderViewHost to | 55 // Attempts to set the status of the specified RenderViewHost to |
| 56 // FINAL_STATUS_USED. Returns true on success. Returns false if it has | 56 // FINAL_STATUS_USED. Returns true on success. Returns false if it has |
| 57 // already been cancelled for any reason or is no longer prerendering. | 57 // already been cancelled for any reason or is no longer prerendering. |
| 58 // Can only be called only on the IO thread. This method will not call | 58 // Can only be called only on the IO thread. This method will not call |
| 59 // PrerenderContents::set_final_status() on the corresponding | 59 // PrerenderContents::set_final_status() on the corresponding |
| 60 // PrerenderContents. | 60 // PrerenderContents. |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 72 // When true is returned, it is guaranteed that the RenderView will never | 72 // When true is returned, it is guaranteed that the RenderView will never |
| 73 // be displayed. When false is returned, the RenderView has either been | 73 // be displayed. When false is returned, the RenderView has either been |
| 74 // swapped into a tab or has already been destroyed. | 74 // swapped into a tab or has already been destroyed. |
| 75 bool TryCancel(int child_id, int route_id, FinalStatus final_status); | 75 bool TryCancel(int child_id, int route_id, FinalStatus final_status); |
| 76 | 76 |
| 77 // Same as above, but can only called on the IO Thread. Does not acquire a | 77 // Same as above, but can only called on the IO Thread. Does not acquire a |
| 78 // lock when the RenderView is not being prerendered. | 78 // lock when the RenderView is not being prerendered. |
| 79 bool TryCancelOnIOThread(int child_id, int route_id, | 79 bool TryCancelOnIOThread(int child_id, int route_id, |
| 80 FinalStatus final_status); | 80 FinalStatus final_status); |
| 81 | 81 |
| 82 // Potentially delay a resource request on the IO thread to prevent a double | |
| 83 // get. When this method returns true, the callback will be run later to | |
| 84 // indicate if the request should be allowed or canceled. | |
| 85 bool PotentiallyDelayRequestOnIOThread( | |
| 86 const GURL& gurl, | |
| 87 int child_id, | |
| 88 int route_id, | |
| 89 const CheckURLCallback& callback); | |
| 90 | |
| 91 void AddPrerenderURLOnUIThread(const GURL& url); | 82 void AddPrerenderURLOnUIThread(const GURL& url); |
| 92 void RemovePrerenderURLsOnUIThread(const std::vector<GURL>& urls); | 83 void RemovePrerenderURLsOnUIThread(const std::vector<GURL>& urls); |
| 93 | 84 |
| 94 // Gets the FinalStatus of the specified prerendered RenderView. Returns | 85 // Gets the FinalStatus of the specified prerendered RenderView. Returns |
| 95 // |true| and sets |final_status| to the status of the RenderView if it | 86 // |true| and sets |final_status| to the status of the RenderView if it |
| 96 // is found, returns false otherwise. | 87 // is found, returns false otherwise. |
| 97 bool GetFinalStatus(int child_id, int route_id, | 88 bool GetFinalStatus(int child_id, int route_id, |
| 98 FinalStatus* final_status) const; | 89 FinalStatus* final_status) const; |
| 99 | 90 |
| 100 // Returns whether or not a RenderView is prerendering. Can only be called on | 91 // Returns whether or not a RenderView is prerendering. Can only be called on |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 163 // date. | 154 // date. |
| 164 FinalStatusMap final_status_map_; | 155 FinalStatusMap final_status_map_; |
| 165 | 156 |
| 166 // Superset of child/route id pairs that are prerendering. Can only access on | 157 // Superset of child/route id pairs that are prerendering. Can only access on |
| 167 // the IO thread. May contain entries that have since been displayed. Only | 158 // the IO thread. May contain entries that have since been displayed. Only |
| 168 // used to prevent locking when not needed. | 159 // used to prevent locking when not needed. |
| 169 PossiblyPrerenderingChildRouteIdPairs possibly_prerendering_io_thread_set_; | 160 PossiblyPrerenderingChildRouteIdPairs possibly_prerendering_io_thread_set_; |
| 170 | 161 |
| 171 // |url_counter_| keeps track of the top-level URLs which are being | 162 // |url_counter_| keeps track of the top-level URLs which are being |
| 172 // prerendered. It must only be accessed on the IO thread. | 163 // prerendered. It must only be accessed on the IO thread. |
| 173 URLCounter url_counter_; | 164 URLCounter url_counter_; |
|
mmenke
2012/04/06 19:40:04
I don't believe we even need this (Including URLCo
| |
| 174 | 165 |
| 175 DISALLOW_COPY_AND_ASSIGN(PrerenderTracker); | 166 DISALLOW_COPY_AND_ASSIGN(PrerenderTracker); |
| 176 }; | 167 }; |
| 177 | 168 |
| 178 } // namespace prerender | 169 } // namespace prerender |
| 179 | 170 |
| 180 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_TRACKER_H_ | 171 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_TRACKER_H_ |
| OLD | NEW |