| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "base/memory/ref_counted.h" | 5 #include "base/memory/ref_counted.h" |
| 6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "chrome/browser/predictors/resource_prefetcher.h" | 8 #include "chrome/browser/predictors/resource_prefetcher.h" |
| 9 #include "chrome/browser/predictors/resource_prefetcher_manager.h" | 9 #include "chrome/browser/predictors/resource_prefetcher_manager.h" |
| 10 #include "chrome/test/base/testing_profile.h" | 10 #include "chrome/test/base/testing_profile.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 const NavigationID& navigation_id, | 29 const NavigationID& navigation_id, |
| 30 PrefetchKeyType key_type, | 30 PrefetchKeyType key_type, |
| 31 scoped_ptr<RequestVector> requests) | 31 scoped_ptr<RequestVector> requests) |
| 32 : ResourcePrefetcher(delegate, config, navigation_id, | 32 : ResourcePrefetcher(delegate, config, navigation_id, |
| 33 key_type, requests.Pass()) { } | 33 key_type, requests.Pass()) { } |
| 34 | 34 |
| 35 virtual ~TestResourcePrefetcher() { } | 35 virtual ~TestResourcePrefetcher() { } |
| 36 | 36 |
| 37 MOCK_METHOD1(StartURLRequest, void(net::URLRequest* request)); | 37 MOCK_METHOD1(StartURLRequest, void(net::URLRequest* request)); |
| 38 | 38 |
| 39 void ReadFullResponse(net::URLRequest* request) OVERRIDE { | 39 void ReadFullResponse(net::URLRequest* request) override { |
| 40 FinishRequest(request, Request::PREFETCH_STATUS_FROM_CACHE); | 40 FinishRequest(request, Request::PREFETCH_STATUS_FROM_CACHE); |
| 41 } | 41 } |
| 42 | 42 |
| 43 private: | 43 private: |
| 44 DISALLOW_COPY_AND_ASSIGN(TestResourcePrefetcher); | 44 DISALLOW_COPY_AND_ASSIGN(TestResourcePrefetcher); |
| 45 }; | 45 }; |
| 46 | 46 |
| 47 | 47 |
| 48 // Delegate for ResourcePrefetcher. | 48 // Delegate for ResourcePrefetcher. |
| 49 class TestResourcePrefetcherDelegate : public ResourcePrefetcher::Delegate { | 49 class TestResourcePrefetcherDelegate : public ResourcePrefetcher::Delegate { |
| 50 public: | 50 public: |
| 51 explicit TestResourcePrefetcherDelegate(base::MessageLoop* loop) | 51 explicit TestResourcePrefetcherDelegate(base::MessageLoop* loop) |
| 52 : request_context_getter_(new net::TestURLRequestContextGetter( | 52 : request_context_getter_(new net::TestURLRequestContextGetter( |
| 53 loop->message_loop_proxy())) { } | 53 loop->message_loop_proxy())) { } |
| 54 ~TestResourcePrefetcherDelegate() { } | 54 ~TestResourcePrefetcherDelegate() { } |
| 55 | 55 |
| 56 virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE { | 56 virtual net::URLRequestContext* GetURLRequestContext() override { |
| 57 return request_context_getter_->GetURLRequestContext(); | 57 return request_context_getter_->GetURLRequestContext(); |
| 58 } | 58 } |
| 59 | 59 |
| 60 MOCK_METHOD2(ResourcePrefetcherFinished, | 60 MOCK_METHOD2(ResourcePrefetcherFinished, |
| 61 void(ResourcePrefetcher* prefetcher, | 61 void(ResourcePrefetcher* prefetcher, |
| 62 ResourcePrefetcher::RequestVector* requests)); | 62 ResourcePrefetcher::RequestVector* requests)); |
| 63 | 63 |
| 64 private: | 64 private: |
| 65 scoped_refptr<net::TestURLRequestContextGetter> request_context_getter_; | 65 scoped_refptr<net::TestURLRequestContextGetter> request_context_getter_; |
| 66 | 66 |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 // We need to delete requests_ptr here, though it looks to be managed by the | 350 // We need to delete requests_ptr here, though it looks to be managed by the |
| 351 // scoped_ptr requests. The scoped_ptr requests releases itself and the raw | 351 // scoped_ptr requests. The scoped_ptr requests releases itself and the raw |
| 352 // pointer requests_ptr is passed to ResourcePrefetcherFinished(). In the | 352 // pointer requests_ptr is passed to ResourcePrefetcherFinished(). In the |
| 353 // test, ResourcePrefetcherFinished() is a mock function and does not handle | 353 // test, ResourcePrefetcherFinished() is a mock function and does not handle |
| 354 // the raw pointer properly. In the real code, requests_ptr will eventually be | 354 // the raw pointer properly. In the real code, requests_ptr will eventually be |
| 355 // passed to and managed by ResourcePrefetchPredictor::Result::Result. | 355 // passed to and managed by ResourcePrefetchPredictor::Result::Result. |
| 356 delete requests_ptr; | 356 delete requests_ptr; |
| 357 } | 357 } |
| 358 | 358 |
| 359 } // namespace predictors | 359 } // namespace predictors |
| OLD | NEW |