OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/precache/content/precache_manager.h" | 5 #include "components/precache/content/precache_manager.h" |
6 | 6 |
7 #include <list> | 7 #include <list> |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/callback.h" | 14 #include "base/callback.h" |
15 #include "base/command_line.h" | 15 #include "base/command_line.h" |
16 #include "base/compiler_specific.h" | 16 #include "base/compiler_specific.h" |
17 #include "base/message_loop/message_loop.h" | 17 #include "base/location.h" |
18 #include "base/metrics/histogram.h" | 18 #include "base/metrics/histogram.h" |
19 #include "base/metrics/histogram_samples.h" | 19 #include "base/metrics/histogram_samples.h" |
20 #include "base/metrics/statistics_recorder.h" | 20 #include "base/metrics/statistics_recorder.h" |
| 21 #include "base/single_thread_task_runner.h" |
| 22 #include "base/thread_task_runner_handle.h" |
21 #include "components/precache/core/precache_switches.h" | 23 #include "components/precache/core/precache_switches.h" |
22 #include "components/precache/core/url_list_provider.h" | 24 #include "components/precache/core/url_list_provider.h" |
23 #include "content/public/test/test_browser_context.h" | 25 #include "content/public/test/test_browser_context.h" |
24 #include "content/public/test/test_browser_thread_bundle.h" | 26 #include "content/public/test/test_browser_thread_bundle.h" |
25 #include "net/http/http_status_code.h" | 27 #include "net/http/http_status_code.h" |
26 #include "net/url_request/test_url_fetcher_factory.h" | 28 #include "net/url_request/test_url_fetcher_factory.h" |
27 #include "net/url_request/url_request_status.h" | 29 #include "net/url_request/url_request_status.h" |
28 #include "net/url_request/url_request_test_util.h" | 30 #include "net/url_request/url_request_test_util.h" |
29 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
30 #include "url/gurl.h" | 32 #include "url/gurl.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 run_immediately_(run_immediately), | 91 run_immediately_(run_immediately), |
90 was_get_urls_called_(false) {} | 92 was_get_urls_called_(false) {} |
91 | 93 |
92 void GetURLs(const GetURLsCallback& callback) override { | 94 void GetURLs(const GetURLsCallback& callback) override { |
93 was_get_urls_called_ = true; | 95 was_get_urls_called_ = true; |
94 | 96 |
95 if (run_immediately_) { | 97 if (run_immediately_) { |
96 callback.Run(urls_); | 98 callback.Run(urls_); |
97 } else { | 99 } else { |
98 // Post the callback to be run later in the message loop. | 100 // Post the callback to be run later in the message loop. |
99 base::MessageLoop::current()->PostTask(FROM_HERE, | 101 base::ThreadTaskRunnerHandle::Get()->PostTask( |
100 base::Bind(callback, urls_)); | 102 FROM_HERE, base::Bind(callback, urls_)); |
101 } | 103 } |
102 } | 104 } |
103 | 105 |
104 bool was_get_urls_called() const { | 106 bool was_get_urls_called() const { |
105 return was_get_urls_called_; | 107 return was_get_urls_called_; |
106 } | 108 } |
107 | 109 |
108 private: | 110 private: |
109 const std::list<GURL> urls_; | 111 const std::list<GURL> urls_; |
110 const bool run_immediately_; | 112 const bool run_immediately_; |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 kCurrentTime, 1000, true); | 351 kCurrentTime, 1000, true); |
350 expected_histogram_count_map["Precache.Saved"] += 2; | 352 expected_histogram_count_map["Precache.Saved"] += 2; |
351 | 353 |
352 base::MessageLoop::current()->RunUntilIdle(); | 354 base::MessageLoop::current()->RunUntilIdle(); |
353 EXPECT_EQ(expected_histogram_count_map, GetHistogramCountMap()); | 355 EXPECT_EQ(expected_histogram_count_map, GetHistogramCountMap()); |
354 } | 356 } |
355 | 357 |
356 } // namespace | 358 } // namespace |
357 | 359 |
358 } // namespace precache | 360 } // namespace precache |
OLD | NEW |