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_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 void SetTimeOverride(std::unique_ptr<TimeOverride> override); |
|
pasko
2016/10/05 12:35:24
The convention is to call it like: SetTimeOverride
| |
| 320 | 327 |
| 321 // Notification that a prerender has completed and its bytes should be | 328 // Notification that a prerender has completed and its bytes should be |
| 322 // recorded. | 329 // recorded. |
| 323 void RecordNetworkBytes(Origin origin, bool used, int64_t prerender_bytes); | 330 void RecordNetworkBytes(Origin origin, bool used, int64_t prerender_bytes); |
| 324 | 331 |
| 325 // Add to the running tally of bytes transferred over the network for this | 332 // Add to the running tally of bytes transferred over the network for this |
| 326 // profile if prerendering is currently enabled. | 333 // profile if prerendering is currently enabled. |
| 327 void AddProfileNetworkBytesIfEnabled(int64_t bytes); | 334 void AddProfileNetworkBytesIfEnabled(int64_t bytes); |
| 328 | 335 |
| 329 // Registers a new ProcessHost performing a prerender. Called by | 336 // 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. | 596 // PrerenderManager is attached to. |
| 590 int64_t profile_network_bytes_; | 597 int64_t profile_network_bytes_; |
| 591 | 598 |
| 592 // The value of profile_network_bytes_ that was last recorded. | 599 // The value of profile_network_bytes_ that was last recorded. |
| 593 int64_t last_recorded_profile_network_bytes_; | 600 int64_t last_recorded_profile_network_bytes_; |
| 594 | 601 |
| 595 // Set of process hosts being prerendered. | 602 // Set of process hosts being prerendered. |
| 596 using PrerenderProcessSet = std::set<content::RenderProcessHost*>; | 603 using PrerenderProcessSet = std::set<content::RenderProcessHost*>; |
| 597 PrerenderProcessSet prerender_process_hosts_; | 604 PrerenderProcessSet prerender_process_hosts_; |
| 598 | 605 |
| 606 std::unique_ptr<TimeOverride> time_override_; | |
| 607 | |
| 599 base::WeakPtrFactory<PrerenderManager> weak_factory_; | 608 base::WeakPtrFactory<PrerenderManager> weak_factory_; |
| 600 | 609 |
| 601 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); | 610 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); |
| 602 }; | 611 }; |
| 603 | 612 |
| 604 } // namespace prerender | 613 } // namespace prerender |
| 605 | 614 |
| 606 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ | 615 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ |
| OLD | NEW |