| 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_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ |
| 6 #define CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ | 6 #define CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 }; | 92 }; |
| 93 | 93 |
| 94 // One or more of these flags must be passed to ClearData() to specify just | 94 // One or more of these flags must be passed to ClearData() to specify just |
| 95 // what data to clear. See function declaration for more information. | 95 // what data to clear. See function declaration for more information. |
| 96 enum ClearFlags { | 96 enum ClearFlags { |
| 97 CLEAR_PRERENDER_CONTENTS = 0x1 << 0, | 97 CLEAR_PRERENDER_CONTENTS = 0x1 << 0, |
| 98 CLEAR_PRERENDER_HISTORY = 0x1 << 1, | 98 CLEAR_PRERENDER_HISTORY = 0x1 << 1, |
| 99 CLEAR_MAX = 0x1 << 2 | 99 CLEAR_MAX = 0x1 << 2 |
| 100 }; | 100 }; |
| 101 | 101 |
| 102 // Used to manipulate time for testing. |
| 103 class TimeOverride { |
| 104 public: |
| 105 virtual base::Time GetCurrentTime() const = 0; |
| 106 virtual base::TimeTicks GetCurrentTimeTicks() const = 0; |
| 107 }; |
| 108 |
| 102 // Owned by a Profile object for the lifetime of the profile. | 109 // Owned by a Profile object for the lifetime of the profile. |
| 103 explicit PrerenderManager(Profile* profile); | 110 explicit PrerenderManager(Profile* profile); |
| 104 ~PrerenderManager() override; | 111 ~PrerenderManager() override; |
| 105 | 112 |
| 106 // From KeyedService: | 113 // From KeyedService: |
| 107 void Shutdown() override; | 114 void Shutdown() override; |
| 108 | 115 |
| 109 // Entry points for adding prerenders. | 116 // Entry points for adding prerenders. |
| 110 | 117 |
| 111 // Adds a prerender for |url| if valid. |process_id| and |route_id| identify | 118 // Adds a prerender for |url| if valid. |process_id| and |route_id| identify |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 | 312 |
| 306 const Config& config() const { return config_; } | 313 const Config& config() const { return config_; } |
| 307 Config& mutable_config() { return config_; } | 314 Config& mutable_config() { return config_; } |
| 308 | 315 |
| 309 // Records that some visible tab navigated (or was redirected) to the | 316 // Records that some visible tab navigated (or was redirected) to the |
| 310 // provided URL. | 317 // provided URL. |
| 311 void RecordNavigation(const GURL& url); | 318 void RecordNavigation(const GURL& url); |
| 312 | 319 |
| 313 Profile* profile() const { return profile_; } | 320 Profile* profile() const { return profile_; } |
| 314 | 321 |
| 315 // Classes which will be tested in prerender unit browser tests should use | 322 base::Time GetCurrentTime() const; |
| 316 // these methods to get times for comparison, so that the test framework can | 323 base::TimeTicks GetCurrentTimeTicks() const; |
| 317 // mock advancing/retarding time. | 324 |
| 318 virtual base::Time GetCurrentTime() const; | 325 // For testing. |
| 319 virtual base::TimeTicks GetCurrentTimeTicks() const; | 326 // TODO(mattcary): unify time testing by using base::SimpleTestClock and |
| 327 // SimpleTestTickClock. |
| 328 void SetTimeOverride(std::unique_ptr<TimeOverride> override); |
| 320 | 329 |
| 321 // Notification that a prerender has completed and its bytes should be | 330 // Notification that a prerender has completed and its bytes should be |
| 322 // recorded. | 331 // recorded. |
| 323 void RecordNetworkBytes(Origin origin, bool used, int64_t prerender_bytes); | 332 void RecordNetworkBytes(Origin origin, bool used, int64_t prerender_bytes); |
| 324 | 333 |
| 325 // Add to the running tally of bytes transferred over the network for this | 334 // Add to the running tally of bytes transferred over the network for this |
| 326 // profile if prerendering is currently enabled. | 335 // profile if prerendering is currently enabled. |
| 327 void AddProfileNetworkBytesIfEnabled(int64_t bytes); | 336 void AddProfileNetworkBytesIfEnabled(int64_t bytes); |
| 328 | 337 |
| 329 // Registers a new ProcessHost performing a prerender. Called by | 338 // Registers a new ProcessHost performing a prerender. Called by |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 589 // PrerenderManager is attached to. | 598 // PrerenderManager is attached to. |
| 590 int64_t profile_network_bytes_; | 599 int64_t profile_network_bytes_; |
| 591 | 600 |
| 592 // The value of profile_network_bytes_ that was last recorded. | 601 // The value of profile_network_bytes_ that was last recorded. |
| 593 int64_t last_recorded_profile_network_bytes_; | 602 int64_t last_recorded_profile_network_bytes_; |
| 594 | 603 |
| 595 // Set of process hosts being prerendered. | 604 // Set of process hosts being prerendered. |
| 596 using PrerenderProcessSet = std::set<content::RenderProcessHost*>; | 605 using PrerenderProcessSet = std::set<content::RenderProcessHost*>; |
| 597 PrerenderProcessSet prerender_process_hosts_; | 606 PrerenderProcessSet prerender_process_hosts_; |
| 598 | 607 |
| 608 std::unique_ptr<TimeOverride> time_override_; |
| 609 |
| 599 base::WeakPtrFactory<PrerenderManager> weak_factory_; | 610 base::WeakPtrFactory<PrerenderManager> weak_factory_; |
| 600 | 611 |
| 601 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); | 612 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); |
| 602 }; | 613 }; |
| 603 | 614 |
| 604 } // namespace prerender | 615 } // namespace prerender |
| 605 | 616 |
| 606 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ | 617 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ |
| OLD | NEW |