summaryrefslogtreecommitdiffstats
path: root/components/bookmarks/browser/startup_task_runner_service.h
blob: 68d25c90098f9863a75777bf0ae4419dc5d875f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_BOOKMARKS_BROWSER_STARTUP_TASK_RUNNER_SERVICE_H_
#define COMPONENTS_BOOKMARKS_BROWSER_STARTUP_TASK_RUNNER_SERVICE_H_

#include "base/basictypes.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/threading/non_thread_safe.h"
#include "components/keyed_service/core/keyed_service.h"

namespace base {
class DeferredSequencedTaskRunner;
class SequencedTaskRunner;
}  // namespace base

namespace bookmarks {

// This service manages the startup task runners.
class StartupTaskRunnerService : public base::NonThreadSafe,
                                 public KeyedService {
 public:
  explicit StartupTaskRunnerService(
      const scoped_refptr<base::SequencedTaskRunner>& io_task_runner);
  ~StartupTaskRunnerService() override;

  // Returns sequenced task runner where all bookmarks I/O operations are
  // performed.
  // This method should only be called from the UI thread.
  // Note: Using a separate task runner per profile service gives a better
  // management of the sequence in which the task are started in order to avoid
  // congestion during start-up (e.g the caller may decide to start loading the
  // bookmarks only after the history finished).
  scoped_refptr<base::DeferredSequencedTaskRunner> GetBookmarkTaskRunner();

  // Starts the task runners that are deferred during start-up.
  void StartDeferredTaskRunners();

 private:
  scoped_refptr<base::SequencedTaskRunner> io_task_runner_;
  scoped_refptr<base::DeferredSequencedTaskRunner> bookmark_task_runner_;

  DISALLOW_COPY_AND_ASSIGN(StartupTaskRunnerService);
};

}  // namespace bookmarks

#endif  // COMPONENTS_BOOKMARKS_BROWSER_STARTUP_TASK_RUNNER_SERVICE_H_