OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 COMPONENTS_PREVIEWS_CORE_PREVIEWS_IO_DATA_H_ | 5 #ifndef COMPONENTS_PREVIEWS_CORE_PREVIEWS_IO_DATA_H_ |
6 #define COMPONENTS_PREVIEWS_CORE_PREVIEWS_IO_DATA_H_ | 6 #define COMPONENTS_PREVIEWS_CORE_PREVIEWS_IO_DATA_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
| 15 #include "base/time/time.h" |
15 #include "components/previews/core/previews_opt_out_store.h" | 16 #include "components/previews/core/previews_opt_out_store.h" |
16 | 17 |
| 18 class GURL; |
| 19 |
17 namespace previews { | 20 namespace previews { |
18 class PreviewsBlackList; | 21 class PreviewsBlackList; |
19 class PreviewsUIService; | 22 class PreviewsUIService; |
20 | 23 |
21 // A class to manage the IO portion of inter-thread communication between | 24 // A class to manage the IO portion of inter-thread communication between |
22 // previews/ objects. Created on the UI thread, but used only on the IO thread | 25 // previews/ objects. Created on the UI thread, but used only on the IO thread |
23 // after initialization. | 26 // after initialization. |
24 class PreviewsIOData { | 27 class PreviewsIOData { |
25 public: | 28 public: |
26 PreviewsIOData( | 29 PreviewsIOData( |
27 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner, | 30 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner, |
28 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner); | 31 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner); |
29 virtual ~PreviewsIOData(); | 32 virtual ~PreviewsIOData(); |
30 | 33 |
31 // Stores |previews_ui_service| as |previews_ui_service_| and posts a task to | 34 // Stores |previews_ui_service| as |previews_ui_service_| and posts a task to |
32 // InitializeOnIOThread on the IO thread. | 35 // InitializeOnIOThread on the IO thread. |
33 void Initialize(base::WeakPtr<PreviewsUIService> previews_ui_service, | 36 void Initialize(base::WeakPtr<PreviewsUIService> previews_ui_service, |
34 std::unique_ptr<PreviewsOptOutStore> previews_opt_out_store); | 37 std::unique_ptr<PreviewsOptOutStore> previews_opt_out_store); |
35 | 38 |
| 39 // Adds a navigation to |url| to the black list with result |opt_out|. |
| 40 void AddPreviewNavigation(const GURL& url, bool opt_out, PreviewsType type); |
| 41 |
| 42 // Clears the history of the black list between |begin_time| and |end_time|, |
| 43 // both inclusive. |
| 44 void ClearBlackList(base::Time begin_time, base::Time end_time); |
| 45 |
| 46 // The previews black list that decides whether a navigation can use previews. |
36 PreviewsBlackList* black_list() const { return previews_black_list_.get(); } | 47 PreviewsBlackList* black_list() const { return previews_black_list_.get(); } |
37 | 48 |
38 protected: | 49 protected: |
39 // Posts a task to SetIOData for |previews_ui_service_| on the UI thread with | 50 // Posts a task to SetIOData for |previews_ui_service_| on the UI thread with |
40 // a weak pointer to |this|. Virtualized for testing. | 51 // a weak pointer to |this|. Virtualized for testing. |
41 virtual void InitializeOnIOThread( | 52 virtual void InitializeOnIOThread( |
42 std::unique_ptr<PreviewsOptOutStore> previews_opt_out_store); | 53 std::unique_ptr<PreviewsOptOutStore> previews_opt_out_store); |
43 | 54 |
44 private: | 55 private: |
45 // The UI thread portion of the inter-thread communication for previews. | 56 // The UI thread portion of the inter-thread communication for previews. |
46 base::WeakPtr<PreviewsUIService> previews_ui_service_; | 57 base::WeakPtr<PreviewsUIService> previews_ui_service_; |
47 | 58 |
48 std::unique_ptr<PreviewsBlackList> previews_black_list_; | 59 std::unique_ptr<PreviewsBlackList> previews_black_list_; |
49 | 60 |
50 // The UI and IO thread task runners. |ui_task_runner_| is used to post | 61 // The UI and IO thread task runners. |ui_task_runner_| is used to post |
51 // tasks to |previews_ui_service_|, and |io_task_runner_| is used to post from | 62 // tasks to |previews_ui_service_|, and |io_task_runner_| is used to post from |
52 // Initialize to InitializeOnIOThread as well as verify that execution is | 63 // Initialize to InitializeOnIOThread as well as verify that execution is |
53 // happening on the IO thread. | 64 // happening on the IO thread. |
54 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; | 65 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; |
55 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; | 66 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
56 | 67 |
57 base::WeakPtrFactory<PreviewsIOData> weak_factory_; | 68 base::WeakPtrFactory<PreviewsIOData> weak_factory_; |
58 | 69 |
59 DISALLOW_COPY_AND_ASSIGN(PreviewsIOData); | 70 DISALLOW_COPY_AND_ASSIGN(PreviewsIOData); |
60 }; | 71 }; |
61 | 72 |
62 } // namespace previews | 73 } // namespace previews |
63 | 74 |
64 #endif // COMPONENTS_PREVIEWS_CORE_PREVIEWS_IO_DATA_H_ | 75 #endif // COMPONENTS_PREVIEWS_CORE_PREVIEWS_IO_DATA_H_ |
OLD | NEW |