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_PREVIEWS_IO_DATA_H_ | 5 #ifndef COMPONENTS_PREVIEWS_PREVIEWS_IO_DATA_H_ |
6 #define COMPONENTS_PREVIEWS_PREVIEWS_IO_DATA_H_ | 6 #define COMPONENTS_PREVIEWS_PREVIEWS_IO_DATA_H_ |
7 | 7 |
| 8 #include <memory> |
8 #include <string> | 9 #include <string> |
9 | 10 |
10 #include "base/macros.h" | 11 #include "base/macros.h" |
11 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
12 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
13 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
14 #include "base/threading/thread_checker.h" | 15 #include "base/time/time.h" |
| 16 #include "components/previews/previews_opt_out_store.h" |
15 | 17 |
16 namespace previews { | 18 namespace previews { |
| 19 class PreviewsBlackList; |
17 class PreviewsUIService; | 20 class PreviewsUIService; |
| 21 enum class PreviewsType; |
18 | 22 |
19 // A class to manage the IO portion of inter-thread communication between | 23 // A class to manage the IO portion of inter-thread communication between |
20 // previews/ objects. Created on the UI thread, but used only on the IO thread | 24 // previews/ objects. Created on the UI thread, but used only on the IO thread |
21 // after initialization. | 25 // after initialization. |
22 class PreviewsIOData { | 26 class PreviewsIOData { |
23 public: | 27 public: |
24 PreviewsIOData( | 28 PreviewsIOData( |
25 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner, | 29 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner, |
26 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner); | 30 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner); |
27 virtual ~PreviewsIOData(); | 31 virtual ~PreviewsIOData(); |
28 | 32 |
29 // Stores |previews_ui_service| as |previews_ui_service_| and posts a task to | 33 // Stores |previews_ui_service| as |previews_ui_service_| and posts a task to |
30 // InitializeOnIOThread on the IO thread. | 34 // InitializeOnIOThread on the IO thread. |
31 void Initialize(base::WeakPtr<PreviewsUIService> previews_ui_service); | 35 void Initialize(base::WeakPtr<PreviewsUIService> previews_ui_service, |
| 36 std::unique_ptr<PreviewsOptOutStore> previews_opt_out_store); |
| 37 |
| 38 PreviewsBlackList* black_list() { return black_list_.get(); } |
32 | 39 |
33 protected: | 40 protected: |
34 // Posts a task to SetIOData for |previews_ui_service_| on the UI thread with | 41 // Posts a task to SetIOData for |previews_ui_service_| on the UI thread with |
35 // a weak pointer to |this|. Virtualized for testing. | 42 // a weak pointer to |this|. Virtualized for testing. |
36 virtual void InitializeOnIOThread(); | 43 virtual void InitializeOnIOThread( |
| 44 std::unique_ptr<PreviewsOptOutStore> previews_opt_out_store); |
37 | 45 |
38 private: | 46 private: |
39 // The UI thread portion of the inter-thread communication for previews. | 47 // The UI thread portion of the inter-thread communication for previews. |
40 base::WeakPtr<PreviewsUIService> previews_ui_service_; | 48 base::WeakPtr<PreviewsUIService> previews_ui_service_; |
41 | 49 |
| 50 std::unique_ptr<PreviewsBlackList> black_list_; |
| 51 |
42 // The UI and IO thread task runners. |ui_task_runner_| is used to post | 52 // The UI and IO thread task runners. |ui_task_runner_| is used to post |
43 // tasks to |previews_ui_service_|, and |io_task_runner_| is used to post from | 53 // tasks to |previews_ui_service_|, and |io_task_runner_| is used to post from |
44 // Initialize to InitializeOnIOThread as well as verify that execution is | 54 // Initialize to InitializeOnIOThread as well as verify that execution is |
45 // happening on the IO thread. | 55 // happening on the IO thread. |
46 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; | 56 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; |
47 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; | 57 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
48 | 58 |
49 base::WeakPtrFactory<PreviewsIOData> weak_factory_; | 59 base::WeakPtrFactory<PreviewsIOData> weak_factory_; |
50 | 60 |
51 DISALLOW_COPY_AND_ASSIGN(PreviewsIOData); | 61 DISALLOW_COPY_AND_ASSIGN(PreviewsIOData); |
52 }; | 62 }; |
53 | 63 |
54 } // namespace previews | 64 } // namespace previews |
55 | 65 |
56 #endif // COMPONENTS_PREVIEWS_PREVIEWS_IO_DATA_H_ | 66 #endif // COMPONENTS_PREVIEWS_PREVIEWS_IO_DATA_H_ |
OLD | NEW |