| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 #ifndef COMPONENTS_BOOKMARKS_BROWSER_STARTUP_TASK_RUNNER_SERVICE_H_ | 5 #ifndef COMPONENTS_BOOKMARKS_BROWSER_STARTUP_TASK_RUNNER_SERVICE_H_ |
| 6 #define COMPONENTS_BOOKMARKS_BROWSER_STARTUP_TASK_RUNNER_SERVICE_H_ | 6 #define COMPONENTS_BOOKMARKS_BROWSER_STARTUP_TASK_RUNNER_SERVICE_H_ |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/threading/non_thread_safe.h" | 10 #include "base/sequence_checker.h" |
| 11 #include "components/keyed_service/core/keyed_service.h" | 11 #include "components/keyed_service/core/keyed_service.h" |
| 12 | 12 |
| 13 namespace base { | 13 namespace base { |
| 14 class DeferredSequencedTaskRunner; | 14 class DeferredSequencedTaskRunner; |
| 15 class SequencedTaskRunner; | 15 class SequencedTaskRunner; |
| 16 } // namespace base | 16 } // namespace base |
| 17 | 17 |
| 18 namespace bookmarks { | 18 namespace bookmarks { |
| 19 | 19 |
| 20 // This service manages the startup task runners. | 20 // This service manages the startup task runners. |
| 21 class StartupTaskRunnerService : public base::NonThreadSafe, | 21 class StartupTaskRunnerService : public KeyedService { |
| 22 public KeyedService { | |
| 23 public: | 22 public: |
| 24 explicit StartupTaskRunnerService( | 23 explicit StartupTaskRunnerService( |
| 25 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner); | 24 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner); |
| 26 ~StartupTaskRunnerService() override; | 25 ~StartupTaskRunnerService() override; |
| 27 | 26 |
| 28 // Returns sequenced task runner where all bookmarks I/O operations are | 27 // Returns sequenced task runner where all bookmarks I/O operations are |
| 29 // performed. | 28 // performed. |
| 30 // This method should only be called from the UI thread. | 29 // This method should only be called from the UI thread. |
| 31 // Note: Using a separate task runner per profile service gives a better | 30 // Note: Using a separate task runner per profile service gives a better |
| 32 // management of the sequence in which the task are started in order to avoid | 31 // management of the sequence in which the task are started in order to avoid |
| 33 // congestion during start-up (e.g the caller may decide to start loading the | 32 // congestion during start-up (e.g the caller may decide to start loading the |
| 34 // bookmarks only after the history finished). | 33 // bookmarks only after the history finished). |
| 35 scoped_refptr<base::DeferredSequencedTaskRunner> GetBookmarkTaskRunner(); | 34 scoped_refptr<base::DeferredSequencedTaskRunner> GetBookmarkTaskRunner(); |
| 36 | 35 |
| 37 // Starts the task runners that are deferred during start-up. | 36 // Starts the task runners that are deferred during start-up. |
| 38 void StartDeferredTaskRunners(); | 37 void StartDeferredTaskRunners(); |
| 39 | 38 |
| 40 private: | 39 private: |
| 41 scoped_refptr<base::SequencedTaskRunner> io_task_runner_; | 40 scoped_refptr<base::SequencedTaskRunner> io_task_runner_; |
| 42 scoped_refptr<base::DeferredSequencedTaskRunner> bookmark_task_runner_; | 41 scoped_refptr<base::DeferredSequencedTaskRunner> bookmark_task_runner_; |
| 43 | 42 |
| 43 SEQUENCE_CHECKER(sequence_checker_); |
| 44 |
| 44 DISALLOW_COPY_AND_ASSIGN(StartupTaskRunnerService); | 45 DISALLOW_COPY_AND_ASSIGN(StartupTaskRunnerService); |
| 45 }; | 46 }; |
| 46 | 47 |
| 47 } // namespace bookmarks | 48 } // namespace bookmarks |
| 48 | 49 |
| 49 #endif // COMPONENTS_BOOKMARKS_BROWSER_STARTUP_TASK_RUNNER_SERVICE_H_ | 50 #endif // COMPONENTS_BOOKMARKS_BROWSER_STARTUP_TASK_RUNNER_SERVICE_H_ |
| OLD | NEW |