| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef COMPONENTS_PREVIEWS_PREVIEWS_IO_DATA_H_ | |
| 6 #define COMPONENTS_PREVIEWS_PREVIEWS_IO_DATA_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/macros.h" | |
| 11 #include "base/memory/ref_counted.h" | |
| 12 #include "base/memory/weak_ptr.h" | |
| 13 #include "base/single_thread_task_runner.h" | |
| 14 #include "base/threading/thread_checker.h" | |
| 15 | |
| 16 namespace previews { | |
| 17 class PreviewsUIService; | |
| 18 | |
| 19 // 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 | |
| 21 // after initialization. | |
| 22 class PreviewsIOData { | |
| 23 public: | |
| 24 PreviewsIOData( | |
| 25 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner, | |
| 26 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner); | |
| 27 virtual ~PreviewsIOData(); | |
| 28 | |
| 29 // Stores |previews_ui_service| as |previews_ui_service_| and posts a task to | |
| 30 // InitializeOnIOThread on the IO thread. | |
| 31 void Initialize(base::WeakPtr<PreviewsUIService> previews_ui_service); | |
| 32 | |
| 33 protected: | |
| 34 // Posts a task to SetIOData for |previews_ui_service_| on the UI thread with | |
| 35 // a weak pointer to |this|. Virtualized for testing. | |
| 36 virtual void InitializeOnIOThread(); | |
| 37 | |
| 38 private: | |
| 39 // The UI thread portion of the inter-thread communication for previews. | |
| 40 base::WeakPtr<PreviewsUIService> previews_ui_service_; | |
| 41 | |
| 42 // 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 | |
| 44 // Initialize to InitializeOnIOThread as well as verify that execution is | |
| 45 // happening on the IO thread. | |
| 46 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; | |
| 47 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; | |
| 48 | |
| 49 base::WeakPtrFactory<PreviewsIOData> weak_factory_; | |
| 50 | |
| 51 DISALLOW_COPY_AND_ASSIGN(PreviewsIOData); | |
| 52 }; | |
| 53 | |
| 54 } // namespace previews | |
| 55 | |
| 56 #endif // COMPONENTS_PREVIEWS_PREVIEWS_IO_DATA_H_ | |
| OLD | NEW |